sim_slopes.Rd
sim_slopes
conducts a simple slopes analysis for the purposes of
understanding two and threeway 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("jtoolsdigits", default = 2), pvals = TRUE, confint = FALSE, ci.width = 0.95, cluster = NULL, modx.labels = NULL, mod2.labels = NULL, v.cov = NULL, v.cov.args = NULL, ...)
model  A regression model. The function is tested with 

pred  The name of the predictor variable involved
in the interaction. This can be a bare name or string. Note that it
is evaluated using 
modx  The name of the moderator variable involved
in the interaction. This can be a bare name or string. The same

mod2  Optional. The name of the second moderator
variable involved in the interaction. This can be a bare name or string.
The same 
modx.values  For which values of the moderator should lines be plotted? There are two basic options:
Default is If the moderator is a factor variable and 
mod2.values  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 
centered  A vector of quoted variable names that are to be
meancentered. If 
data  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., 
cond.int  Should conditional intercepts be printed in addition to the
slopes? Default is 
johnson_neyman  Should the JohnsonNeyman interval be calculated?
Default is 
jnplot  Should the JohnsonNeyman interval be plotted as well? Default
is 
jnalpha  What should the alpha level be for the JohnsonNeyman interval? Default is .05, which corresponds to a 95% confidence interval. 
robust  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.,

digits  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

pvals  Show p values? If 
confint  Show confidence intervals instead of standard errors? Default
is 
ci.width  A number between 0 and 1 that signifies the width of the
desired confidence interval. Default is 
cluster  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. 
modx.labels  A character vector of labels for each level of the
moderator values, provided in the same order as the 
mod2.labels  A character vector of labels for each level of the 2nd
moderator values, provided in the same order as the 
v.cov  A function to calculate variances for the model. Examples
could be 
v.cov.args  A list of arguments for the 
...  Arguments passed to 
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 2way interaction, the list will be of length
Otherwise, there will be 1 johnson_neyman
object for each value of
the
2nd moderator for 3way interactions.
This allows the user to perform a simple slopes analysis for the purpose of probing interaction effects in a linear regression. Two and threeway interactions are supported, though one should be warned that threeway interactions are not easy to interpret in this way.
For more about JohnsonNeyman 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), 373400. 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 JohnsonNeyman intervals.
simpleSlope
performs a similar analysis.
Other interaction tools: johnson_neyman
,
probe_interaction
,
sim_margins
# 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)#> JOHNSONNEYMAN INTERVAL #> #> When Illiteracy is OUTSIDE the interval [0.68, 2.20], the slope of #> Murder is p < .05. #> #> Note: The range of observed values of Illiteracy is [0.50, 2.80] #> #> SIMPLE SLOPES ANALYSIS #> #> Slope of Murder when Illiteracy = 0.56 ( 1 SD): #> #> Est. S.E. t val. p #>     #> 78.99 34.81 2.27 0.03 #> #> Slope of Murder when Illiteracy = 1.17 (Mean): #> #> Est. S.E. t val. p #>     #> 8.36 29.24 0.29 0.78 #> #> Slope of Murder when Illiteracy = 1.78 (+ 1 SD): #> #> Est. S.E. t val. p #>     #> 62.28 41.49 1.50 0.14 #># 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) # 3way with survey and factor input regmodel < svyglm(api00 ~ ell * meals * sch.wide, design = dstrat) sim_slopes(regmodel, pred = ell, modx = meals, mod2 = sch.wide) }#> ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ While sch.wide (2nd moderator) = No ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ #> #> JOHNSONNEYMAN INTERVAL #> #> The JohnsonNeyman interval could not be found. Is the p value for your #> interaction term below the specified alpha? #> #> SIMPLE SLOPES ANALYSIS #> #> Slope of ell when meals = 18.72 ( 1 SD): #> #> Est. S.E. t val. p #>     #> 3.51 1.99 1.76 0.08 #> #> Slope of ell when meals = 48.22 (Mean): #> #> Est. S.E. t val. p #>     #> 1.98 1.25 1.58 0.11 #> #> Slope of ell when meals = 77.73 (+ 1 SD): #> #> Est. S.E. t val. p #>     #> 0.45 1.23 0.37 0.71 #> #> ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ While sch.wide (2nd moderator) = Yes ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ #> #> JOHNSONNEYMAN INTERVAL #> #> The JohnsonNeyman interval could not be found. Is the p value for your #> interaction term below the specified alpha? #> #> SIMPLE SLOPES ANALYSIS #> #> Slope of ell when meals = 18.72 ( 1 SD): #> #> Est. S.E. t val. p #>     #> 0.93 0.83 1.12 0.26 #> #> Slope of ell when meals = 48.22 (Mean): #> #> Est. S.E. t val. p #>     #> 0.62 0.56 1.12 0.26 #> #> Slope of ell when meals = 77.73 (+ 1 SD): #> #> Est. S.E. t val. p #>     #> 0.32 0.38 0.84 0.40 #>