# NOT RUN {
## three different two dimensional ellipses
e1 <- list(c = c(0, 0.7), P = matrix(c(0.2, 0, 0, 3), ncol = 2), r = 0.5)
e2 <- list(c = c(0, 1), P = matrix(c(3, -1.5, -1.5, 1), ncol = 2), r = 1)
e3 <- list(c = c(1.5, 1), P = matrix(c(3, 1.2, 1.2, 1), ncol = 2), r = 1.2)
# Note: These ellipses have been chosen so all pairs intersect,
# but the intersection of all three is empty.
# test pairwise overlaps
pairwise_overlap(list(e1, e2, e3))
## regression example
# generate data
n <- 100
E <- rbinom(n, 2, 0.5)
X <- rnorm(n, 3 * E, 1)
Y <- rnorm(n, 2 + 1.5 * E, 1)
m0 <- lm(Y ~ X, data = data.frame(Y,X), subset = (E == 0))
m1 <- lm(Y ~ X, data = data.frame(Y,X), subset = (E == 1))
m2 <- lm(Y ~ X, data = data.frame(Y,X), subset = (E == 2))
# create 95% confidence ellipses and check pairwise intersection
q <- qchisq(0.95, 2) # df = 2, as there are two covariates (1, X)
E0 <- list(c = coefficients(m0), S = vcov(m0), r = q)
E1 <- list(c = coefficients(m1), S = vcov(m1), r = q)
E2 <- list(c = coefficients(m2), S = vcov(m2), r = q)
pairwise_overlap(list("model 0" = E0, "model 1" = E1, "model 2" = E2))
# }
Run the code above in your browser using DataLab