mlm_probe: Probe simple slopes from a multilevel interaction

View source: R/mlm_probe.R

mlm_probeR Documentation

Probe simple slopes from a multilevel interaction

Description

Computes simple slopes of a focal predictor (pred) at selected values of a moderator (modx) from a two-level mixed-effects model fitted with lme4::lmer(). Returns estimates, standard errors, t-values, p-values, and confidence intervals in a tidy data frame.

Usage

mlm_probe(
  model,
  pred,
  modx,
  modx.values = c("mean-sd", "quartiles", "tertiles", "custom"),
  at = NULL,
  conf.level = 0.95
)

Arguments

model

An lmerMod object containing a two-way interaction between pred and modx in the fixed-effects structure.

pred

Character scalar. Name of the focal predictor variable.

modx

Character scalar. Name of the moderator variable.

modx.values

Strategy for selecting moderator values. One of:

  • "mean-sd" (default): mean — 1 SD, mean, mean + 1 SD.

  • "quartiles": 25th, 50th, 75th percentiles.

  • "tertiles": 33rd and 67th percentiles.

  • "custom": use values supplied via at.

at

Numeric vector of custom moderator values. Used when modx.values = "custom", or to override any strategy.

conf.level

Confidence level for intervals. Default 0.95.

Value

An object of class mlm_probe (a list) with components:

  • slopes: a data frame with columns modx_value, slope, se, t, df, p, ci_lower, ci_upper.

  • pred, modx: names of the predictor and moderator.

  • modx.values: the strategy used.

  • conf.level: the confidence level.

  • model: the original model (stored for downstream use).

Examples

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_probe(mod, pred = "x", modx = "m")
mlm_probe(mod, pred = "x", modx = "m", modx.values = "quartiles")
mlm_probe(mod, pred = "x", modx = "m", modx.values = "custom", at = c(-1, 0, 1))


mlmoderator documentation built on April 4, 2026, 1:07 a.m.