if (FALSE) {
# --- Create Mixture of two Gaussians ---
set.seed(1)
n <- 500
library(MASS)
# Component A
Sigma_a <- diag(2)
Sigma_a[1, 2] <- Sigma_a[2, 1] <- .5
Xa <- mvrnorm(n = n, mu = rep(0, 2), Sigma = Sigma_a)
# Component B
Sigma_b <- diag(2)
Sigma_b[1, 2] <- Sigma_b[2, 1] <- 0
Xb <- mvrnorm(n = n, mu = rep(0, 2), Sigma = Sigma_b)
data <- as.data.frame(cbind(rbind(Xa, Xb), c(rep(0, n), rep(1, n))))
colnames(data) <- c("x1", "x2", "x3")
# --- Fit MGM ---
# with mgm
mgm_obj <- mgm(data = data,
type = c("g","g","c"),
level = c(1, 1, 2),
moderator = c(3),
lambdaSel = "EBIC")
# --- Condition on / fix values of variable 3 ---
# Fix x3=0
mgm_obj_x3.0 <- condition(object = mgm_obj,
values = list("3"=0))
mgm_obj_x3.0$pairwise$wadj
# Fix x3=1
mgm_obj_x3.1 <- condition(object = mgm_obj,
values = list("3"=1))
mgm_obj_x3.1$pairwise$wadj
}
Run the code above in your browser using DataLab