Extracts the effective pairwise network implied by a moderated MGM
(mgm_fit() with moderators) at a given value of the moderator, mirroring
mgm::condition(): it applies the AND-rule pre-filter, absorbs the moderator
value into the main-effect coefficients, and re-aggregates the pairwise edges.
Examples
set.seed(1)
x1 <- stats::rnorm(400); x2 <- stats::rnorm(400)
mod <- rep(0:1, each = 200)
y <- x1 * (mod == 1) + stats::rnorm(400) # x1-y edge only when mod == 1
d <- data.frame(x1 = x1, x2 = x2, y = y, mod = mod)
fit <- mgm_fit(d, types = c("g", "g", "g", "c"), moderators = 4)
condition(fit, value = 0) # no x1-y edge
#> <psychnet> mgm_moderated network
#> nodes: 4 edges: 0 (undirected)
condition(fit, value = 1) # the x1-y edge appears
#> <psychnet> mgm_moderated network
#> nodes: 4 edges: 1 (undirected)