simple_slopes: Simple Slopes Analysis

Description Usage Arguments Value Author(s) References Examples

View source: R/simple_slopes.R

Description

Computes simple slopes for objects fit with the class "lm"

Usage

1
2
3
4
5
6
7
8
simple_slopes(
  fit,
  variable1name,
  variable1values = NULL,
  variable2name,
  variable2values = NULL,
  plot_slopes = TRUE
)

Arguments

fit

"lm" object. Object from a model fit using a regression model

variable1name

Character. Name of the first variable in interaction from fit

variable1values

Numeric. Values to be used when first variable is the moderator. If variable1type = "dichotomous", then defaults to values 0 and 1. If variable1type = "continuous", then defaults to values -1 SD, M, and +1 SD

variable2name

Character. Name of the second variable in interaction from fit

variable2values

Numeric. Values to be used when second variable is the moderator. If variable2type = "dichotomous", then defaults to values 0 and 1. If variable2type = "continuous", then defaults to values -1 SD, M, and +1 SD

plot_slopes

Boolean. Should simple slopes be plotted? Defaults to TRUE

Value

Returns a list containing:

fit

Returns fit object back

results

Data frame with variable, moderator, values of moderator betas of simple slopes, t values, p-values, and significance level

parameters

A list containing degrees of freedom (df), betas (from fit), interaction name, variance-covariance matrix of the variables involved, and data from fit

plot_args

Internal use only. Arguments for plots

Author(s)

Alexander Christensen <alexpaulchristensen@gmail.com>

References

Preacher, K. J., Curran, P. J., & Bauer, D. J. (2006). Computational tools for probing interactions in multiple linear regression, multilevel modeling, and latent curve analysis. Journal of Educational and Behavioral Statistics, 31(4), 437-448.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Generate data
df <- data.frame(
  y = rnorm(100),
  x1 = rnorm(100),
  x2 = rnorm(100)
)

# Estimate linear model
fit <- lm(y ~ x1 * x2, data = df)

# Estimate simple slopes
simple_slopes(
  fit = fit,
  variable1name = "x1", # must be name as it appears in 'fit' object
  variable2name = "x2", # must be name as it appears in 'fit' object
  plot = TRUE
)

AlexChristensen/simpleRslopes documentation built on Feb. 6, 2022, 12:32 a.m.