Learn R Programming

marginaleffects (version 0.3.4)

plot_cme: Plot Conditional Marginal Effects

Description

This function plots marginal effects (y-axis) against values of predictor(s) variable(s) (x-axis and colors). This is especially useful in models with interactions, where the values of marginal effects depend on the values of "condition" variables.

Usage

plot_cme(
  model,
  effect,
  condition,
  type = "response",
  conf.int = TRUE,
  conf.level = 0.95,
  draw = TRUE
)

Arguments

model

Model object

effect

Name of the variable whose marginal effect we want to plot on the y-axis

condition

String or vector of two strings. The first is a variable name to be displayed on the x-axis. The second is a variable whose values will be displayed in different colors.

type

Type(s) of prediction as string or character vector. This can differ based on the model type, but will typically be a string such as: "response", "link", "probs", or "zero".

conf.int

Logical indicating whether or not to include a confidence interval.

conf.level

The confidence level to use for the confidence interval if conf.int=TRUE. Must be strictly greater than 0 and less than 1. Defaults to 0.95, which corresponds to a 95 percent confidence interval.

draw

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

Value

A ggplot2 object

Examples

Run this code
# NOT RUN {
mod <- lm(mpg ~ hp * wt, data = mtcars)
plot_cme(mod, effect = "hp", condition = "wt")

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

# }

Run the code above in your browser using DataLab