Learn R Programming

eulerr (version 1.0.0)

eulerr: Area-Proportional Euler Diagrams

Description

Compute Euler diagrams (a generalization of Venn diagrams) using numerical optimization to find exact or approximate solutions to a specification of set relationships.

Usage

eulerr(sets, ...)
"eulerr"(sets, cost = c("eulerAPE", "venneuler"), ...)
"eulerr"(sets, by = NULL, cost = c("eulerape", "venneuler"), ...)
"eulerr"(sets, by = NULL, cost = c("eulerape", "venneuler"), ...)

Arguments

sets
Set relationships as a named numeric vector, matrix, or data.frame. (See the methods (by class) section for details.)
cost
Cost function to use in optimizing the fit. See details.
by
A factor or character vector used in by to split the data.frame or matrix and compute euler diagrams for each split.
...
Currently ignored.

Value

A list object of class 'eulerr' with the following parameters.

Methods (by class)

  • default: A named numeric vector, with interactions seperated by an ampersand, for instance `A&B` = 10. Missing interactions are treated as being 0.
  • matrix: A matrix of logical vectors with columns representing sets and rows representing each observation's set relationships (see examples).
  • data.frame: A data.frame that can be converted to a matrix of logicals (as in the description above) via as.matrix.

Details

If by is specified, eulerr returns a list of euler diagrams that can be plotted in facets via a special plot method.

The fit is optimized using either the cost function used in the eulerAPE software package or the stress statistic of the R package venneuler. The eulerAPE cost function is defined as

$$% \frac{1}{n} \sum_{i=1}^{n} \frac{(y_i - \hat{y}_i) ^ 2}{\hat{y}_i} $$

where $fit$ are the estimates of $y$ that are currently explored during optimization. For venneuler, the stress function is defined as

$$% \frac{\sum_{i=1}^{n} (y_i - \hat{y}_i) ^ 2}{\sum_{i=1}^{n} y_i ^ 2} $$

where $fit$ are OLS estimates from the regression of the fitted areas on the original areas that are currently being explored during optimization.

References

Wilkinson L. Exact and Approximate Area-Proportional Circular Venn and Euler Diagrams. IEEE Transactions on Visualization and Computer Graphics [Internet]. 2012 Feb [cited 2016 Apr 9];18(2):321–31. Available from: http://doi.org/10.1109/TVCG.2011.56

Micallef L, Rodgers P. eulerAPE: Drawing Area-Proportional 3-Venn Diagrams Using Ellipses. PLOS ONE [Internet]. 2014 Jul [cited 2016 Dec 10];9(7):e101717. Available from: http://dx.doi.org/10.1371/journal.pone.0101717

See Also

plot.eulerr, print.eulerr

Examples

Run this code

fit1 <- eulerr(c("A" = 1, "B" = 0.4, "C" = 3, "A&B" = 0.2))

# Same result as above
fit2 <- eulerr(c("A" = 1, "B" = 0.4, "C" = 3,
                 "A&B" = 0.2, "A&C" = 0, "B&C" = 0,
                 "A&B&C" = 0) )

# Using the matrix method
mat <- cbind(A = sample(c(TRUE, TRUE, FALSE), size = 50, replace = TRUE),
             B = sample(c(TRUE, FALSE), size = 50, replace = TRUE))
fit3 <- eulerr(mat)

# Using grouping via the 'by' argument
dat <- data.frame(
  A      = sample(c(TRUE, FALSE), size = 100, replace = TRUE),
  B      = sample(c(TRUE, TRUE, FALSE), size = 100, replace = TRUE),
  gender = sample(c("Men", "Women"), size = 100, replace = TRUE),
  nation = sample(c("Sweden", "Denmark"), size = 100, replace = TRUE)
)

fit4 <- eulerr(dat[, 1:2], by = dat[, 3:4])

# A set with no perfect solution
rel <- c("a" = 3491, "b" = 3409, "c" = 3503,
         "a&b" = 120, "a&c" = 114, "b&c" = 132, "a&b&c" = 126)

# Use the cost function from eulerAPE (the default)
fit5 <- eulerr(rel, cost = "eulerAPE")

# Use the stress function from venneuler
fit6 <- eulerr(rel, cost = "venneuler")

par(mfrow = c(1, 2))
plot(fit5); plot(fit6)

Run the code above in your browser using DataLab