plot_model() creates plots from regression models, either
estimates (as so-called forest or dot whisker plots) or marginal effects.
plot_model( model, type = c("est", "re", "eff", "emm", "pred", "int", "std", "std2", "slope", "resid", "diag"), transform, terms = NULL, sort.est = NULL, rm.terms = NULL, group.terms = NULL, order.terms = NULL, pred.type = c("fe", "re"), mdrt.values = c("minmax", "meansd", "zeromax", "quart", "all"), ri.nr = NULL, title = NULL, axis.title = NULL, axis.labels = NULL, legend.title = NULL, wrap.title = 50, wrap.labels = 25, axis.lim = NULL, grid.breaks = NULL, ci.lvl = NULL, se = NULL, robust = FALSE, vcov.fun = NULL, vcov.type = c("HC3", "const", "HC", "HC0", "HC1", "HC2", "HC4", "HC4m", "HC5"), vcov.args = NULL, colors = "Set1", show.intercept = FALSE, show.values = FALSE, show.p = TRUE, show.data = FALSE, show.legend = TRUE, show.zeroinf = TRUE, value.offset = NULL, value.size, jitter = NULL, digits = 2, dot.size = NULL, line.size = NULL, vline.color = NULL, p.threshold = c(0.05, 0.01, 0.001), p.adjust = NULL, grid, case, auto.label = TRUE, prefix.labels = c("none", "varname", "label"), bpe = "median", bpe.style = "line", bpe.color = "white", ci.style = c("whisker", "bar"), ... ) get_model_data( model, type = c("est", "re", "eff", "pred", "int", "std", "std2", "slope", "resid", "diag"), transform, terms = NULL, sort.est = NULL, rm.terms = NULL, group.terms = NULL, order.terms = NULL, pred.type = c("fe", "re"), ri.nr = NULL, ci.lvl = NULL, colors = "Set1", grid, case = "parsed", digits = 2, ... )
A regression model object. Depending on the
Type of plot. There are three groups of plot-types:
Marginal Effects (related vignette)
Note: For mixed models, the diagnostic plots like linear relationship or check for Homoscedasticity, do not take the uncertainty of random effects into account, but is only based on the fixed effects part of the model.
A character vector, naming a function that will be applied
on estimates and confidence intervals. By default,
Character vector with the names of those terms from
Determines in which way estimates are sorted in the plot:
Character vector with names that indicate which terms should
be removed from the plot. Counterpart to
Numeric vector with group indices, to group coefficients. Each group of coefficients gets its own color (see 'Examples').
Numeric vector, indicating in which order the coefficients should be plotted. See examples in this package-vignette.
Character, only applies for Marginal Effects plots
with mixed effects models. Indicates whether predicted values should be
conditioned on random effects (
Indicates which values of the moderator variable should be
used when plotting interaction terms (i.e.
Numeric vector. If
Character vector, used as plot title. By default,
Character vector of length one or two (depending on the
plot function and type), used as title(s) for the x and y axis. If not
specified, a default labelling is chosen. Note: Some plot types
may not support this argument sufficiently. In such cases, use the returned
ggplot-object and add axis titles manually with
Character vector with labels for the model terms, used as
axis labels. By default,
Character vector, used as legend title for plots that have a legend.
Numeric, determines how many chars of the plot title are displayed in one line and when a line break is inserted.
Numeric, determines how many chars of the value, variable or axis labels are displayed in one line and when a line break is inserted.
Numeric vector of length 2, defining the range of the plot
axis. Depending on plot-type, may effect either x- or y-axis. For
Marginal Effects plots,
Numeric value or vector; if
Numeric, the level of the confidence intervals (error bars).
Logical, shortcut for arguments
Character vector, indicating the name of the
List of named vectors, used as additional arguments that
are passed down to
May be a character vector of color values in hex-format, valid
color value names (see
Logical, whether values should be plotted or not.
Logical, adds asterisks that indicate the significance level of estimates to the value labels.
Logical, for Marginal Effects plots, also plots the raw data points.
For Marginal Effects plots, shows or hides the legend.
Numeric, offset for text labels to adjust their position relative to the dots or lines.
Numeric, indicates the size of value labels. Can be used
for all plot types where the argument
Numeric, between 0 and 1. If
Numeric, amount of digits after decimal point when rounding estimates or values.
Numeric, size of the dots that indicate the point estimates.
Numeric, size of the lines that indicate the error bars.
Color of the vertical "zero effect" line. Default color is inherited from the current theme.
Numeric vector of length 3, indicating the treshold for
annotating p-values with asterisks. Only applies if
Character vector, if not
Desired target case. Labels will automatically converted into the
specified character case. See
Indicates whether the value labels of categorical variables
should be prefixed, e.g. with the variable name or variable label. See
For Stan-models (fitted with the rstanarm- or
brms-package), the Bayesian point estimate is, by default, the median
of the posterior distribution. Use
For Stan-models (fitted with the rstanarm- or
brms-package), the Bayesian point estimate is indicated as a small,
vertical line by default. Use
Character vector, indicating the color of the Bayesian
point estimate. Setting
Character vector, defining whether inner and outer intervals
for Bayesion models are shown in boxplot-style (
Other arguments, passed down to various functions. Here is a list of supported arguments and their description in detail.
Depending on the plot-type,
plot_model() returns a
ggplot-object or a list of such objects.
returns the associated data with the plot-object as tidy data frame, or
(depending on the plot-type) a list of such data frames.
type = "std"
Plots standardized estimates. See details below.
type = "std2"
Plots standardized estimates, however, standardization follows Gelman's (2008) suggestion, rescaling the estimates by dividing them by two standard deviations instead of just one. Resulting coefficients are then directly comparable for untransformed binary predictors.
type = "pred"
type = "eff"
type = "int"
A shortcut for marginal effects plots, where
interaction terms are automatically detected and used as
terms-argument. Furthermore, if the moderator variable (the second
- and third - term in an interaction) is continuous,
type = "int"
automatically chooses useful values based on the
which are passed to
type = "int" plots the interaction term that appears
first in the formula along the x-axis, while the second (and possibly
third) variable in an interaction is used as grouping factor(s)
(moderating variable). Use
type = "pred" or
type = "eff"
and specify a certain order in the
terms-argument to indicate
which variable(s) should be used as moderator. See also
type = "slope"and
type = "resid"
Simple diagnostic-plots, where a linear model for each single predictor is plotted against the response variable, or the model's residuals. Additionally, a loess-smoothed line is added to the plot. The main purpose of these plots is to check whether the relationship between outcome (or residuals) and a predictor is roughly linear or not. Since the plots are based on a simple linear regression with only one model predictor at the moment, the slopes (i.e. coefficients) may differ from the coefficients of the complete model.
type = "diag"
For Stan-models, plots the prior versus posterior samples. For linear (mixed) models, plots for multicollinearity-check (Variance Inflation Factors), QQ-plots, checks for normal distribution of residuals and homoscedasticity (constant variance of residuals) are shown. For generalized linear mixed models, returns the QQ-plot for random effects.
Default standardization is done by completely refitting the model on the
standardized data. Hence, this approach is equal to standardizing the
variables before fitting the model, which is particularly recommended for
complex models that include interactions or transformations (e.g., polynomial
or spline terms). When
type = "std2", standardization of estimates
follows Gelman's (2008)
suggestion, rescaling the estimates by dividing them by two standard deviations
instead of just one. Resulting coefficients are then directly comparable for
untransformed binary predictors.
Gelman A (2008) "Scaling regression inputs by dividing by two
standard deviations." Statistics in Medicine 27: 2865-2873.
Aiken and West (1991). Multiple Regression: Testing and Interpreting Interactions.