plot_cme: 'plot_slopes()' is an alias to 'plot_slopes()'

plot_cmeR Documentation

plot_slopes() is an alias to plot_slopes()


This alias is kept for backward compatibility.


  variables = NULL,
  condition = NULL,
  by = NULL,
  newdata = NULL,
  type = "response",
  vcov = NULL,
  conf_level = 0.95,
  wts = NULL,
  slope = "dydx",
  rug = FALSE,
  gray = FALSE,
  draw = TRUE,



Model object


Conditional predictions

  • Character vector (max length 3): Names of the predictors to display.

  • Named list (max length 3): List names correspond to predictors. List elements can be:

    • Numeric vector

    • Function which returns a numeric vector or a set of unique categorical values

    • Shortcut strings for common reference values: "minmax", "quartile", "threenum"

  • 1: x-axis. 2: color/shape. 3: facets.

  • Numeric variables in positions 2 and 3 are summarized by Tukey's five numbers ?stats::fivenum


Marginal predictions

  • Character vector (max length 3): Names of the categorical predictors to marginalize across.

  • 1: x-axis. 2: color. 3: facets.


When newdata is NULL, the grid is determined by the condition argument. When newdata is not NULL, the argument behaves in the same way as in the predictions() function.


string indicates the type (scale) of the predictions used to compute contrasts or slopes. This can differ based on the model type, but will typically be a string such as: "response", "link", "probs", or "zero". When an unsupported string is entered, the model-specific list of acceptable values is returned in an error message. When type is NULL, the first entry in the error message is used by default.


Type of uncertainty estimates to report (e.g., for robust standard errors). Acceptable values:

  • FALSE: Do not compute standard errors. This can speed up computation considerably.

  • TRUE: Unit-level standard errors using the default vcov(model) variance-covariance matrix.

  • String which indicates the kind of uncertainty estimates to return.

    • Heteroskedasticity-consistent: "HC", "HC0", "HC1", "HC2", "HC3", "HC4", "HC4m", "HC5". See ?sandwich::vcovHC

    • Heteroskedasticity and autocorrelation consistent: "HAC"

    • Mixed-Models degrees of freedom: "satterthwaite", "kenward-roger"

    • Other: "NeweyWest", "KernHAC", "OPG". See the sandwich package documentation.

  • One-sided formula which indicates the name of cluster variables (e.g., ~unit_id). This formula is passed to the cluster argument of the sandwich::vcovCL function.

  • Square covariance matrix

  • Function which returns a covariance matrix (e.g., stats::vcov(model))


numeric value between 0 and 1. Confidence level to use to build a confidence interval.


string or numeric: weights to use when computing average contrasts or slopes. These weights only affect the averaging in ⁠avg_*()⁠ or with the by argument, and not the unit-level estimates themselves. Internally, estimates and weights are passed to the weighted.mean() function.

  • string: column name of the weights variable in newdata. When supplying a column name to wts, it is recommended to supply the original data (including the weights variable) explicitly to newdata.

  • numeric: vector of length equal to the number of rows in the original data or in newdata (if supplied).


TRUE displays tick marks on the axes to mark the distribution of raw data.


FALSE grayscale or color plot


TRUE returns a ggplot2 plot. FALSE returns a data.frame of the underlying data.


Additional arguments are passed to the predict() method supplied by the modeling package.These arguments are particularly useful for mixed-effects or bayesian models (see the online vignettes on the marginaleffects website). Available arguments can vary from model to model, depending on the range of supported arguments by each modeling package. See the "Model-Specific Arguments" section of the ?marginaleffects documentation for a non-exhaustive list of available arguments.


A ggplot2 object or data frame (if draw=FALSE)

Model-Specific Arguments

Some model types allow model-specific arguments to modify the nature of marginal effects, predictions, marginal means, and contrasts. Please report other package-specific predict() arguments on Github so we can add them to the table below.

Package Class Argument Documentation
brms brmsfit ndraws brms::posterior_predict
re_formula brms::posterior_predict
lme4 merMod re.form lme4::predict.merMod lme4::predict.merMod
glmmTMB glmmTMB re.form glmmTMB::predict.glmmTMB glmmTMB::predict.glmmTMB
zitype glmmTMB::predict.glmmTMB
mgcv bam exclude mgcv::predict.bam
robustlmm rlmerMod re.form robustlmm::predict.rlmerMod robustlmm::predict.rlmerMod
MCMCglmm MCMCglmm ndraws


mod <- lm(mpg ~ hp + wt, data = mtcars)
plot_predictions(mod, condition = "wt")

mod <- lm(mpg ~ hp * wt * am, data = mtcars)
plot_predictions(mod, condition = c("hp", "wt"))

plot_predictions(mod, condition = list("hp", wt = "threenum"))

plot_predictions(mod, condition = list("hp", wt = range))

marginaleffects documentation built on Oct. 20, 2023, 1:07 a.m.