johnson_neyman: Generate Johnson-Neyman plot

View source: R/johnson_neyman_wrapper.R

johnson_neymanR Documentation

Generate Johnson-Neyman plot

Description

Generates a Johnson-Neyman plot for the effect of X on the dependent variable, moderated by M. Performs two-sided t-Test on coefficient.

Usage

johnson_neyman(
  object,
  X,
  M,
  modrange = NULL,
  resolution = 10000,
  sig.thresh = 0.05
)

Arguments

object

model object, either "lm","lmer","nlme"

X

name of independent variable

M

name of moderator variable

modrange

moderator range to consider. Defaults to observed range.

resolution

plotting resolution, i.e. count of moderator values to consider

sig.thresh

significance threshold alpha. Defaults to 0.05.

Value

Johnson-neyman plot as gpplot2 object. Also prints the exact significance regions within the supplied moderator range.

Examples

#Generate base plot for linear model
x <- rnorm(50)
m <- rnorm(50)
y <- rnorm(50,x*m,2)
model <- lm(y~x*m)
plot <- johnson_neyman(model,"x","m")

# Add custom ggplot2 elements
plot + labs(x="Changed x label",y="Changed y label")

#mixed models
x <- rnorm(50)
m <- rnorm(50)
y <- rnorm(50,x*m,2)
g <- sample(1:10,50,TRUE)
model <- lme4::lmer(y~m*x + (1|g))
johnson_neyman(model,"x","m")


AlexHartmann00/lmmadd documentation built on Aug. 16, 2022, 8:19 a.m.