Learn R Programming

⚠️There's a newer version (0.25.1) of this package.Take me there.

The marginaleffects package for R and Python offers a single point of entry to easily interpret the results of over 100 classes of models, using a simple and consistent user interface.

This package comes with a free full-length online book, with extensive tutorials: https://marginaleffects.com

The package’s benefits include:

  • Powerful: It can compute and plot predictions; comparisons (contrasts, risk ratios, etc.); slopes; and conduct hypothesis and equivalence tests for over 100 different classes of models in R.
  • Simple: All functions share a simple and unified interface.
  • Documented: Each function is thoroughly documented with abundant examples. The Marginal Effects Zoo website includes 20,000+ words of vignettes and case studies.
  • Efficient: Some operations can be up to 1000 times faster and use 30 times less memory than with the margins package.
  • Valid: When possible, numerical results are checked against alternative software like Stata or other R packages.
  • Thin: The R package requires relatively few dependencies.
  • Standards-compliant: marginaleffects follows “tidy” principles and returns simple data frames that work with all standard R functions. The outputs are easy to program with and feed to other packages like ggplot2 or modelsummary.
  • Extensible: Adding support for new models is very easy, often requiring less than 10 lines of new code. Please submit feature requests on Github.
  • Active development: Bugs are fixed promptly.

To cite marginaleffects in publications use:

Arel-Bundock V, Greifer N, Heiss A (2024). “How to Interpret Statistical Models Using marginaleffects for R and Python.” Journal of Statistical Software, 111(9), 1-32.

A BibTeX entry for LaTeX users is

@Article{, title = {How to Interpret Statistical Models Using {marginaleffects} for {R} and {Python}}, author = {Vincent Arel-Bundock and Noah Greifer and Andrew Heiss}, journal = {Journal of Statistical Software}, year = {2024}, volume = {111}, number = {9}, pages = {1–32}, doi = {10.18637/jss.v111.i09}, }

Copy Link

Version

Install

install.packages('marginaleffects')

Monthly Downloads

21,335

Version

0.24.0

License

GPL (>= 3)

Maintainer

Vincent Arel-Bundock

Last Published

November 25th, 2024

Functions in marginaleffects (0.24.0)

marginaleffects

Deprecated function
plot_comparisons

Plot Conditional or Marginal Comparisons
reexports

Objects exported from other packages
plot_predictions

Plot Conditional or Marginal Predictions
print.marginaleffects

Print marginaleffects objects
plot_slopes

Plot Conditional or Marginal Slopes
predictions

Predictions
marginalmeans

Deprecated function
posterior_draws

alias to get_draws() for backward compatibility with JJSS
sanitize_model_specific.glimML

Method to raise model-specific warnings and errors
meffects

Deprecated function
set_coef

Internal function to set coefficients
slopes

Slopes (aka Partial derivatives, Marginal Effects, or Trends)
deltamethod

Deprecated function
comparisons

Comparisons Between Predictions Made With Different Regressor Values
get_draws

Extract Posterior Draws or Bootstrap Resamples from marginaleffects Objects
get_coef

Get a named vector of coefficients from a model object
complete_levels

Create a data.frame with all factor or character levels
datagrid

Data grids
datagridcf

Deprecated function
expect_predictions

tinytest helper
get_group_names

Get levels of the outcome variable in grouped or multivariate models
expect_margins

tinytest helper
expect_slopes

tinytest helper
marginal_means

Deprecated function
get_vcov

Get a named variance-covariance matrix from a model object
get_model_matrix

Get a named model matrix
get_predict

Get predicted values from a model object (internal function)
get_varcov_args

Take a summary() style vcov argument and convert it to insight::get_varcov()
hypotheses

(Non-)Linear Tests for Null Hypotheses, Joint Hypotheses, Equivalence, Non Superiority, and Non Inferiority
inferences

(EXPERIMENTAL) Bootstrap, Conformal, and Simulation-Based Inference
knit_print.marginaleffects

Print a marginaleffects object in knitr