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, modx.values = NULL,
mod2.values = NULL, centered = "all", data = NULL,
cond.int = FALSE, johnson_neyman = TRUE, jnplot = FALSE,
jnalpha = 0.05, robust = FALSE, digits = getOption("jtools-digits",
default = 2), pvals = TRUE, confint = FALSE, ci.width = 0.95,
cluster = NULL, modx.labels = NULL, mod2.labels = NULL, ...)
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.
Same as modx.values
, but for the second moderator
(mod2
).
A vector of quoted variable names that are to be
mean-centered. If "all"
, all non-focal predictors as well as
the pred
variable are centered. You
may instead pass a character vector of variables to center. User can
also use "none" to base all predictions on variables set at 0.
The response variable, modx
, and mod2
variables are never
centered.
Optional, default is NULL. You may provide the data used to
fit the model. This can be a better way to get mean values for centering
and can be crucial for models with variable transformations in the formula
(e.g., log(x)
) or polynomial terms (e.g., poly(x, 2)
). You will
see a warning if the function detects problems that would likely be
solved by providing the data with this argument and the function will
attempt to retrieve the original data from the global environment.
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.
Should robust standard errors be used to find confidence
intervals for supported models? Default is FALSE, but you should specify
the type of sandwich standard errors if you'd like to use them (i.e.,
"HC0"
, "HC1"
, and so on). If TRUE
, defaults to "HC3"
standard
errors.
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.
Show p values and significance stars? If FALSE
, these
are not printed. Default is TRUE
.
Show confidence intervals instead of standard errors? Default
is FALSE
.
A number between 0 and 1 that signifies the width of the
desired confidence interval. Default is .95
, which corresponds
to a 95% confidence interval. Ignored if confint = FALSE
.
For clustered standard errors, provide the column name of the cluster variable in the input data frame (as a string). Alternately, provide a vector of clusters.
A character vector of labels for each level of the
moderator values, provided in the same order as the modx.values
argument. If NULL
, the values themselves are used as labels unless
modx,values
is also NULL
. In that case, "+1 SD" and "-1 SD"
are used.
A character vector of labels for each level of the 2nd
moderator values, provided in the same order as the mod2.values
argument. If NULL
, the values themselves are used as labels unless
mod2.values
is also NULL
. In that case, "+1 SD" and "-1 SD"
are used.
Arguments passed to johnson_neyman
and
summ
.
A list object with the following components:
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 is tested with lm
, glm
, svyglm
, and merMod
inputs.
Others may work as well, but are not tested. In all but the linear model
case, be aware that not all the assumptions applied to simple slopes
analysis apply.
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.
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
if (requireNamespace("survey")) {
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