sim_slopes
conducts a simple slopes analysis for the purposes of
understanding two- and three-way interaction effects in linear regression.
sim_slopes(model, pred, modx, mod2 = NULL, modxvals = NULL,
mod2vals = NULL, centered = NULL, scale = FALSE, cond.int = FALSE,
johnson_neyman = TRUE, jnplot = FALSE, jnalpha = 0.05, robust = FALSE,
robust.type = "HC3", digits = getOption("jtools-digits", default = 2),
n.sd = 1, standardize = NULL, ...)
A regression model of type lm
or
svyglm
.
It should contain the interaction of interest.
The predictor variable involved in the interaction.
The moderator variable involved in the interaction.
Optional. The name of the second moderator variable involved in the interaction.
For which values of the moderator should simple slopes
analysis be performed? Default is NULL
. If NULL
, then the
values will be the customary +/- 1 standard deviation from the mean as
well as the mean itself. There is no specific limit on the number of
variables provided. If
"plus-minus"
, uses just +/- 1 standard
deviation without the mean. You may also choose "terciles"
to split
the data into equally-sized groups and choose the point at the mean of
each of those groups.
Factor variables
are not particularly suited to simple slopes analysis, but you could have
a numeric moderator with values of 0 and 1 and give c(0,1)
to
compare the slopes at the different conditions. Two-level factor
variables are coerced to numeric 0/1 variables, but are not
standardized/centered like they could be if your input data had a numeric
0/1 variable.
For which values of the second moderator should the plot be
facetted by? That is, there will be a separate plot for each level of this
moderator. Defaults are the same as modxvals
.
A vector of quoted variable names that are to be
mean-centered. If NULL
, all non-focal predictors are centered. If
not NULL
, only the user-specified predictors are centered. User
can also use "none" or "all" arguments. The response variable is not
centered unless specified directly.
Logical. Would you like to standardize the variables
that are centered? Default is FALSE
, but if TRUE
it will
scale variables specified by the centered
argument. Note that
non-focal predictors are centered when centered = NULL
, its
default.
Should conditional intercepts be printed in addition to the
slopes? Default is FALSE
.
Should the Johnson-Neyman interval be calculated?
Default is TRUE
. This can be performed separately with
johnson_neyman
.
Should the Johnson-Neyman interval be plotted as well? Default
is FALSE
.
What should the alpha level be for the Johnson-Neyman interval? Default is .05, which corresponds to a 95% confidence interval.
Logical. If TRUE
, computes heteroskedasticity-robust
standard errors.
Type of heteroskedasticity-robust standard errors to use
if robust=TRUE
. See details of j_summ
for more on
options.
An integer specifying the number of digits past the decimal to
report in the output. Default is 2. You can change the default number of
digits for all jtools functions with
options("jtools-digits" = digits)
where digits is the desired
number.
How many standard deviations should be used if scale
= TRUE
? Default is 1, but some prefer 2.
Deprecated. Equivalent to scale
. Please change your
scripts to use scale
instead as this argument will be removed in the
future.
Arguments passed to johnson_neyman
.
A table of coefficients for the focal predictor at each value of the moderator
A table of coefficients for the intercept at each value of the moderator
The values of the moderator used in the analysis
A list containing each regression model created to estimate the conditional coefficients.
If johnson_neyman = TRUE
, a list of johnson_neyman
objects from johnson_neyman
. These contain the values of the
interval and the plots. If a 2-way interaction, the list will be of length
Otherwise, there will be 1 johnson_neyman
object for each value of the
2nd moderator for 3-way interactions.
This allows the user to perform a simple slopes analysis for the purpose of probing interaction effects in a linear regression. Two- and three-way interactions are supported, though one should be warned that three-way interactions are not easy to interpret in this way.
For more about Johnson-Neyman intervals, see johnson_neyman
.
The function accepts a lm
object and uses it to recompute models
with the moderating variable set to the levels requested.
svyglm
objects are also accepted, though users
should be cautioned against using simple slopes analysis with non-linear
models (svyglm
also estimates linear models).
Factor moderators are coerced to a 0/1 numeric variable and are not centered, even when requested in arguments. To avoid this, modify your data to change the factor to a binary numeric variable. Factors with more than 2 levels trigger an error.
Bauer, D. J., & Curran, P. J. (2005). Probing interactions in fixed and multilevel regression: Inferential and graphical techniques. Multivariate Behavioral Research, 40(3), 373-400. http://dx.doi.org/10.1207/s15327906mbr4003_5
Cohen, J., Cohen, P., West, S. G., & Aiken, L. S. (2003). Applied multiple regression/correlation analyses for the behavioral sciences (3rd ed.). Mahwah, NJ: Lawrence Erlbaum Associates, Inc.
interact_plot
accepts similar syntax and will plot the
results with ggplot
.
testSlopes
performs a hypothesis test of
differences and provides Johnson-Neyman intervals.
simpleSlope
performs a similar analysis and can
also analyze a second moderator.
Other interaction tools: cat_plot
,
interact_plot
,
johnson_neyman
,
probe_interaction
# NOT RUN {
# Using a fitted model as formula input
fiti <- lm(Income ~ Frost + Murder * Illiteracy,
data=as.data.frame(state.x77))
sim_slopes(model = fiti, pred = Murder, modx = Illiteracy)
# With svyglm
library(survey)
data(api)
dstrat <- svydesign(id = ~1, strata = ~stype, weights = ~pw,
data = apistrat, fpc = ~fpc)
regmodel <- svyglm(api00 ~ ell * meals, design = dstrat)
sim_slopes(regmodel, pred = ell, modx = meals)
# 3-way with survey and factor input
regmodel <- svyglm(api00 ~ ell * meals * sch.wide, design = dstrat)
sim_slopes(regmodel, pred = ell, modx = meals, mod2 = sch.wide)
# }
Run the code above in your browser using DataLab