| mlm_plot | R Documentation |
Creates a ggplot2-based interaction plot showing predicted values of the
outcome across levels of pred, with separate lines for each selected value
of modx. Confidence bands and raw data overlay are optional.
mlm_plot(
model,
pred,
modx,
modx.values = c("mean-sd", "quartiles", "tertiles", "custom"),
at = NULL,
interval = TRUE,
conf.level = 0.95,
points = FALSE,
point_alpha = 0.3,
colors = NULL,
line_size = 1,
x_label = NULL,
y_label = NULL,
legend_title = NULL
)
model |
An |
pred |
Character scalar. Focal predictor (x-axis). |
modx |
Character scalar. Moderator (separate lines). |
modx.values |
Strategy for moderator values. Same options as
|
at |
Numeric vector of custom moderator values (used when
|
interval |
Logical. Draw confidence bands? Default |
conf.level |
Confidence level for bands. Default |
points |
Logical. Overlay raw data points? Default |
point_alpha |
Transparency for raw data points. Default |
colors |
Character vector of colours for moderator lines. If |
line_size |
Line width for predicted lines. Default |
x_label |
Label for x-axis. Defaults to |
y_label |
Label for y-axis. Defaults to response variable name. |
legend_title |
Label for the legend. Defaults to |
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_plot(mod, pred = "x", modx = "m")
mlm_plot(mod, pred = "x", modx = "m", modx.values = "quartiles")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.