mlm_jn: Johnson-Neyman interval for multilevel two-way interactions

View source: R/mlm_jn.R

mlm_jnR Documentation

Johnson—Neyman interval for multilevel two-way interactions

Description

Computes the Johnson—Neyman (JN) interval: the region(s) of the moderator (modx) where the simple slope of pred transitions between statistical significance and non-significance. Useful for identifying exactly at which moderator values an effect becomes significant.

Usage

mlm_jn(model, pred, modx, alpha = 0.05, modx.range = NULL, grid = 200L)

Arguments

model

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

pred

Character scalar. Focal predictor name.

modx

Character scalar. Moderator name.

alpha

Significance level. Default 0.05.

modx.range

Numeric vector of length 2 giving the range over which to evaluate the slope. Defaults to the observed range of modx.

grid

Integer. Number of points at which to evaluate the slope across the moderator range. Default 200.

Value

An object of class mlm_jn with components:

  • jn_bounds: numeric vector of moderator values where the slope crosses the significance threshold. NA if no finite region exists.

  • slopes_df: data frame of slope estimates and significance across the grid.

  • pred, modx, alpha, modx.range.

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"))
jn <- mlm_jn(mod, pred = "x", modx = "m")
print(jn)


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