plot.margins: Plot Marginal Effects Estimates

View source: R/plot.R

plot.marginsR Documentation

Plot Marginal Effects Estimates

Description

An implementation of Stata's ‘⁠marginsplot⁠’ as an S3 generic function

Usage

## S3 method for class 'margins'
plot(
  x,
  pos = seq_along(marginal_effects(x, with_at = FALSE)),
  which = colnames(marginal_effects(x, with_at = FALSE)),
  labels = gsub("^dydx_", "", which),
  horizontal = FALSE,
  xlab = "",
  ylab = "Average Marginal Effect",
  level = 0.95,
  pch = 21,
  points.col = "black",
  points.bg = "black",
  las = 1,
  cex = 1,
  lwd = 2,
  zeroline = TRUE,
  zero.col = "gray",
  ...
)

Arguments

x

An object of class “margins”, as returned by margins.

pos

A numeric vector specifying the x-positions of the estimates (or y-positions, if horizontal = TRUE).

which

A character vector specifying which marginal effect estimate to plot. Default is all.

labels

A character vector specifying the axis labels to use for the marginal effect estimates. Default is the variable names from x.

horizontal

A logical indicating whether to plot the estimates along the x-axis with vertical confidence intervals (the default), or along the y-axis with horizontal confidence intervals.

xlab

A character string specifying the x-axis (or y-axis, if horizontal = TRUE) label.

ylab

A character string specifying the y-axis (or x-axis, if horizontal = TRUE) label.

level

A numeric value between 0 and 1 indicating the confidence level to use when drawing error bars.

pch

The point symbol to use for plotting marginal effect point estimates. See points for details.

points.col

The point color to use for plotting marginal effect point estimates. See points for details.

points.bg

The point color to use for plotting marginal effect point estimates. See points for details.

las

An integer value specifying the orientation of the axis labels. See par for details.

cex

A numerical value giving the amount by which plotting text and symbols should be magnified relative to the default. See par for details.

lwd

A numerical value giving the width of error bars in points.

zeroline

A logical indicating whether to draw a line indicating zero. Default is TRUE.

zero.col

A character string indicating a color to use for the zero line if zeroline = TRUE.

...

Additional arguments passed to plot.default, such as title, etc.

Details

This function is invoked for its side effect: a basic dot plot with error bars displaying marginal effects as generated by margins, in the style of Stata's ‘⁠marginsplot⁠’ command.

Value

The original “margins” object x, invisibly.

See Also

margins, persp.lm

Examples

## Not run: 
  require("datasets")
  x <- lm(mpg ~ cyl * hp + wt, data = mtcars)
  mar <- margins(x)
  plot(mar)

## End(Not run)


margins documentation built on Sept. 11, 2024, 5:21 p.m.