| mlm_surface | R Documentation |
Plots iso-outcome contour lines of \hat{Y}(x, w) over the full joint
space of pred (x-axis) and modx (y-axis). This is the most direct
geometric representation of a two-way interaction:
mlm_surface(
model,
pred,
modx,
grid = 80L,
n_contours = 10L,
fill = TRUE,
probe_lines = TRUE,
x_label = NULL,
y_label = NULL,
legend_title = NULL
)
model |
An |
pred |
Character scalar. Focal predictor (x-axis). |
modx |
Character scalar. Moderator (y-axis). |
grid |
Integer. Grid resolution (points per axis). Default |
n_contours |
Integer. Number of contour levels to draw. Default |
fill |
Logical. Fill contour bands with colour? Default |
probe_lines |
Logical. Overlay horizontal lines at mean – 1 SD of
|
x_label |
x-axis label. Defaults to |
y_label |
y-axis label. Defaults to |
legend_title |
Legend title. Defaults to the outcome variable name. |
No interaction: contour lines are perfectly straight and parallel —
the effect of pred does not depend on modx.
Positive interaction: contour lines fan outward (rotate clockwise) —
higher modx steepens the pred slope.
Negative interaction: contour lines fan inward (rotate counter-clockwise).
The degree of non-parallelism among contours is a direct visual index of
interaction strength: the larger \beta_3, the more the lines rotate.
An optional overlay draws the three standard simple-slope evaluation lines
(mean – 1 SD of modx) as horizontal reference lines, connecting the plot
to mlm_probe() output.
Predicted values are computed from fixed effects only
(re.form = NA), with all covariates held at their means or reference
levels. The surface therefore represents the population-average predicted
outcome, not any specific cluster.
Reading the plot:
Pick any contour line. Its slope in the pred direction tells you how fast
the outcome changes with pred at that modx value. If the contour slopes
steeply up-right, pred has a strong positive effect there. If contours
become more horizontal as modx increases, the pred effect is weakening.
If they rotate from positive to flat to negative, you have a sign-changing
interaction — and the modx value where they are perfectly horizontal is
the Johnson-Neyman boundary.
A ggplot object.
set.seed(1)
dat <- data.frame(
y = rnorm(200), x = rnorm(200),
m = rep(rnorm(20), each = 10),
grp = factor(rep(1:20, each = 10))
)
dat$y <- dat$y + dat$x * dat$m
mod <- lme4::lmer(y ~ x * m + (1 | grp), data = dat,
control = lme4::lmerControl(optimizer = "bobyqa"))
mlm_surface(mod, pred = "x", modx = "m")
mlm_surface(mod, pred = "x", modx = "m", fill = FALSE, n_contours = 15)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.