R/sjPlotInteractions.R
sjp.int.Rd
Plot regression (predicted values) or probability lines (predicted probabilities) of significant interaction terms to better understand effects of moderations in regression models. This function accepts following fitted model classes:
linear models (lm
)
generalized linear models (glm
)
linear mixed effects models (lmer
)
generalized linear mixed effects models (glmer
)
nonlinear mixed effects models (nlmer
)
linear mixed effects models (lme
, but only for type = "eff"
)
generalized least squares models (gls
, but only for type = "eff"
)
panel data estimators (plm
)
Note that beside interaction terms, also the single predictors of each interaction (main effects)
must be included in the fitted model as well. Thus, lm(dep ~ pred1 * pred2)
will work,
but lm(dep ~ pred1:pred2)
won't!
sjp.int(fit, type = c("eff", "cond"), int.term = NULL, int.plot.index = NULL, mdrt.values = c("minmax", "meansd", "zeromax", "quart", "all"), swap.pred = FALSE, plevel = 0.1, diff = FALSE, title = NULL, axis.title = NULL, legend.title = NULL, legend.labels = NULL, wrap.title = 50, wrap.legend.labels = 20, wrap.legend.title = 20, geom.colors = "Set1", geom.size = NULL, fill.color = "grey", fill.alpha = 0.3, show.values = FALSE, show.ci = FALSE, jitter.ci = FALSE, p.kr = TRUE, grid.breaks = NULL, xlim = NULL, ylim = NULL, y.offset = 0.07, digits = 2, facet.grid = FALSE, prnt.plot = TRUE, ...)
fit  A fitted (generalized) linear (mixed) model object, including interaction terms. Accepted model classes are


type  Interaction plot type. Use one of following values:

int.term  Name of interaction term of 
int.plot.index  Numeric vector with index numbers that indicate which
interaction terms should be plotted in case the 
mdrt.values  Indicates which values of the moderator variable should be used when plotting the interaction effects.

swap.pred  Logical, if 
plevel  Numeric, indicates at which pvalue an interaction term is considered as significant,
i.e. at which plevel an interaction term will be considered for plotting. Default is
0.1 (10 percent), hence, nonsignificant interactions are excluded by default. This
argument does not apply to 
diff  Logical, if 
title  Default title used for the plots. Should be a character vector
of same length as interaction plots to be plotted. Default value is 
axis.title  Default title used for the xaxis. Should be a character vector
of same length as interaction plots to be plotted. Default value is 
legend.title  Title of the plot's legend. A character vector of same length as amount of interaction plots to be plotted (i.e. one vector element for each plot's legend title). 
legend.labels  Labels for the guide/legend. Either a character vector of same length as
amount of legend labels of the plot, or a 
wrap.title  numeric, determines how many chars of the plot title are displayed in one line and when a line break is inserted. 
wrap.legend.labels  numeric, determines how many chars of the legend labels are displayed in one line and when a line break is inserted. 
wrap.legend.title  numeric, determines how many chars of the legend's title are displayed in one line and when a line break is inserted. 
geom.colors  Vector of color values or name of a valid color brewer palette.
If not a color brewer palette name, 
geom.size  size resp. width of the geoms (bar width, line thickness or point size, depending on plot type and function). Note that bar and bin widths mostly need smaller values than dot sizes. 
fill.color  Fill color of the shaded area between the minimum and maximum lines. Default is 
fill.alpha  Alpha value (transparancy) of the shaded area between the minimum and maximum lines. Default is 0.4.
Use either 0 or set 
show.values  Logical, whether values should be plotted or not. 
show.ci  Logical, if 
jitter.ci  Logical, if 
p.kr  logical, if 
grid.breaks  numeric; sets the distance between breaks for the axis,
i.e. at every 
xlim  Numeric vector of length two, defining lower and upper axis limits
of the x scale. By default, this argument is set to 
ylim  numeric vector of length two, defining lower and upper axis limits
of the y scale. By default, this argument is set to 
y.offset  numeric, offset for text labels when their alignment is adjusted
to the top/bottom of the geom (see 
digits  Numeric, amount of digits after decimal point when rounding estimates and values. 
facet.grid 

prnt.plot  logical, if 
...  Other arguments passed down to further functions. Currently, following arguments are supported:

(Insisibily) returns the ggplotobjects with the complete plotlist (plot.list
)
as well as the data frames that were used for setting up the ggplotobjects (data.list
).
type = "eff"
plots the overall effects (marginal effects) of the interaction, with all remaining
covariates set to the mean. Effects are calculated using the effect

function from the effectspackage.
You can pass further arguments down to allEffects
for flexible
function call via the ...
argument.
type = "cond"
plots the effective change or impact
(conditional effect) on a dependent variable of a moderation effect, as
described by GraceMartin, i.e. the difference of the moderation effect on the
dependent variable in presence and absence of the moderating effect
(simple slope plot or conditional effect, see Hayes 2012). All
remaining predictors are set to zero (i.e. ignored and not adjusted for).
Hence, this plot type may be used especially for binary or dummy coded
moderator values (see also Esarey and Summer 2015).
This type does not show the overall effect (marginal mean, i.e. adjusted
for all other predictors and covariates) of interactions on the result of Y. Use
type = "eff"
for effect displays similar to the effect
function
from the effectspackage.
The argument int.term
only applies to type = "eff"
and can be used
to select a specific interaction term of the model that should be plotted. The function
then calls effect(int.term, fit)
to compute effects for this specific interaction
term only. This approach is recommended, when the fitted model contains many observations
and/or variables, which may slow down the effectcomputation dramatically. In such cases,
consider computing effects for selected interaction terms only with int.terms
.
See 'Examples'.
Note that beside interaction terms, also the single predictors of each interaction (main effects)
must be included in the fitted model as well. Thus, lm(dep ~ pred1 * pred2)
will work,
but lm(dep ~ pred1:pred2)
won't!
For type = "eff"
, predictors of interactions that are introduced first into the model
are used as grouping variable, while the latter predictor is printed along the xaxis
(i.e. lm(y~a+b+a:b) means that "a" is used as grouping variable and "b" is plotted along the xaxis).
Aiken and West (1991). Multiple Regression: Testing and Interpreting Interactions.
Brambor T, Clark WR and Golder M (2006) Understanding Interaction Models: Improving Empirical Analyses. Political Analysis 14: 6382. download
Esarey J, Sumner JL (2015) Marginal Effects in Interaction Models: Determining and Controlling the False Positive Rate. download
Fox J (2003) Effect displays in R for generalised linear models. Journal of Statistical Software 8:15, 1–27, <http://www.jstatsoft.org/v08/i15/>
Hayes AF (2012) PROCESS: A versatile computational tool for observed variable mediation, moderation, and conditional process modeling [White paper] download
GraceMartin K: Clarifications on Interpreting Interactions in Regression