simple.slopes: Simple Slopes

Description Usage Arguments Details Value Author(s) Examples

Description

simple.slopes() generates simple slopes and tests for the effect of a predictor on an outcome given a linear regression fit. plot.simple.slopes() generates a plot of the simple regression lines.

Usage

1
2
3
4
5
6
7
simple.slopes(fit, predictor = NULL, moderator = NULL, at.mod.level = NULL, mod.level.names = NULL, alpha = .05, sig.region = NULL, ...)

## S3 method for class 'simple.slopes'
print(s, ...)

## S3 method for class 'simple.slopes'
plot(s, pred.range = NULL, colors = NULL, ...)

Arguments

fit

the output of a call to lm() containing a linear interaction between a continuous predictor and a one or two moderators. If other variables are included in the model, all output will be taken with those variables set to 0.

predictor

optional; a string containing the name of the predictor. By default, it is assumed that the first variable to appear in fit is the predictor; if not, it must be specified here.

moderator

optional; a string containing the name of the moderator. By default, it is assumed that the second variable to appear in fit is the sole moderator; if not, it must be specified here. If more than one moderator is present, all of them must be named because the default is to only use the second variable in the fit.

at.mod.level

optional; a list of values of each moderator for which simple slopes are to be computed. If NULL, will compute simple slopes at the mean, mean - SD, and mean + SD of the moderator if the moderator is continuous or at the unique values of the moderator if it is categorical. Ideally, each item in the list will be named in accordance with each moderator, but otherwise each item will be used in the order it appears.

mod.level.names

optional; a vector of the same length as at.mod.level containing the names of the levels of the moderator for which simple slopes are to be calculated, in the same order as at.mod.level. If NULL, will use the values of the moderator as the names, unless at.mod.level is also NULL and the moderator is continuous, in which case "Mean", "Mean - SD", and "Mean + SD" will be used.

pred.range

optional; a vector of length 2 containing the range of the predictor for which the simple regression lines are to be plotted in a call to plot.simple.slopes(). If NULL, will use the range of the predictor given in fit.

alpha

the alpha value (significance criterion) of the t-tests for simple slopes.

sig.region

optional; a sig.region object. If specified, will compute and test the simple slopes at the significance bounds. This is generally not of use. If at.mod.level is specified, sig.region will be ignored.

s

a simple.slopes object; the output of a call to simple.slopes().

colors

a vector of colors to be used to specify the colors of the lines in the simple slopes plot. See 'Color Specification' at par.

...

other arguments passed to or from other functions.

Details

simple.slopes() replicates the simple slopes tool at [quantpsy.org] by allowing users to enter a regression object and specify options for display and computation. Currently it can support up to two moderators. Categorical moderators are supported, but only if exactly one moderator is present. A categorical variable should be entered as a factor variable in the original fit.

It has its own print method, which produces the values and tests of the simple slopes and intercepts for the given values of the moderator(s). plot() generates a plot of the simple slopes. Note that this plot is a ggplot object, meaning users can edit it with ggplot2 syntax.

Value

simple.slopes: An object of class "simple.slopes" with the following entries: simple.lines The slopes (w0) and intercepts (w1) and their t- and p-values and confidence intervals for each simple line. var.names The names of the outcome, predictor, and moderator(s). pred.range The range of the predictor in the original data set. cz The values and names of the conditional values of the moderator(s) at which the simple slopes are evaluated.

Author(s)

Noah Greifer

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#One Moderator
data("mpg")
fit <- lm(cty ~ displ * drv, data = mpg)
summary(fit)

s <- simple.slopes(fit)
s
plot(s)

#Two Moderators
fit2 <- lm()

ngreifer/modprobe documentation built on May 30, 2019, 7:20 a.m.