jn_interval: Compute Johnson-Neyman Interval for Interaction Effects

View source: R/johnson_neyman.R

jn_intervalR Documentation

Compute Johnson-Neyman Interval for Interaction Effects

Description

Identifies the values of the moderating variable at which the conditional effect of the other variable transitions between statistical significance and non-significance.

Usage

jn_interval(m, var1, var2, ci = 0.95)

Arguments

m

A model object (lm, glm, lmerMod, or glmerMod).

var1

The name (as a string) of the variable whose conditional effect is of interest.

var2

The name (as a string) of the moderating variable.

ci

A numeric value defining the confidence level. The default is 0.95.

Details

The Johnson-Neyman (JN) technique finds the values of the moderating variable (var2) at which the conditional effect of var1 is exactly at the boundary of statistical significance. This is computed analytically from the regression coefficients and their variance-covariance matrix.

For linear mixed-effects models (lmerMod, glmerMod), a normal approximation (z-distribution) is used instead of the t-distribution due to the controversy over appropriate degrees of freedom.

The function does not support factor variables or quadratic terms (var1 == var2).

Value

An object of class jn_interval containing:

bounds

All Johnson-Neyman bounds (may be 0, 1, or 2 values).

bounds_in_range

Bounds that fall within the observed data range of var2.

var2_range

The range of the moderating variable in the data.

sig_pattern

One of "always", "never", "between", "outside", "below", or "above", indicating where the effect is statistically significant.

ns_regions

List of (xmin, xmax) pairs marking non-significant regions.

Examples

m <- lm(mpg ~ wt * cyl, data = mtcars)
jn <- jn_interval(m, "cyl", "wt")
print(jn)

# Add JN bounds to an interplot
interplot(m, "cyl", "wt") + jn_layer(jn)


interplot documentation built on June 24, 2026, 5:08 p.m.