# NOT RUN {
## 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))
# }
Run the code above in your browser using DataLab