Description Usage Arguments Details Value See Also Examples
View source: R/marginal_overlap.R
Determin if the projections of ellipses onto each margin overlap.
1 | marginal_overlap(ell, margins = "all")
|
ell |
a list of at least two (non degenerate) ellipses; see
|
margins |
either "all" or a vector indicating the margins to project the ellipses onto and take intersections. |
The ellipses are projected onto the specified margins
. For each margin
the intersection of the projected ellipses is found. The Lower
and
Upper
endpoints of the intersection interval is reported. If the
intersection along a margin is empty then Lower
and Upper
is reported as NA
.
Note that if the ellipses overlap when projected onto each margin this does not imply that the ellipses themselves intersect non-emptily. The example below is constructed to illustrate this.
marginal_overlap
returns an object of class
"marginal_overlap" which contains a data.frame where the coloumns descibe the
following
Margin |
Intputted |
Overlap |
Whether the ellipses overlap when projected onto corresponding margin. |
Lower |
Lower endpoint of intersection interval. |
Upper |
Upper endpoint of intersection interval. |
wrangle_ellipse
for detailed on ellipse
parameterization.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ## two dimensional ellipses
e1 <- list(c = c(0.1, 0), P = matrix(c(3, 0, 0, 1), ncol = 2), r = 1)
e2 <- list(c = c(1, 1), P = matrix(c(3, 1.2, 1.2, 1), ncol = 2), r = 0.8)
e3 <- list(c = c(2, 1.5), P = matrix(c(1, 0.6, 0.6, 1), ncol = 2), r = 0.4)
# Note: These three ellipses have been chosen so (some of) the marginal
# projections intersect, but the actual ellipses do not intersect.
# Ellipses e1 and e2 overlap when projected onto margin 1 and 2 respectivly.
marginal_overlap(list(e1, e2))
# Adding ellipse e3:
# Then there is no overlap when projecting onto margin 1
marginal_overlap(list(e1, e2, e3), margins = c(1))
## regression example
n <- 100
E <- rbinom(n, 1, 0.5)
X <- rnorm(n, E * 3, 1)
Y <- rnorm(n, 2 + X, 1)
lm_E0 <- lm(Y ~ X, data = data.frame(Y, X), subset = (E == 0))
lm_E1 <- lm(Y ~ X, data = data.frame(Y, X), subset = (E == 1))
# create 95% confidence ellipses and check marginal overlap
q <- qchisq(0.95, 2) # df = 2, as there are two covariates (1, X)
ell0 <- list(c = coefficients(lm_E0), S = vcov(lm_E0), r = q)
ell1 <- list(c = coefficients(lm_E1), S = vcov(lm_E1), r = q)
marginal_overlap(list(ell0, ell1))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.