Calculating Marginal Effects and Levels with Errors

Calculate predicted levels and marginal effects, using the delta method to calculate standard errors. This is an R-based version of the 'margins' command from Stata.

CRAN Version Build Status codecov

Calculate predicted levels and marginal effects using the delta method to calculate standard errors. This is an R-based version of Stata's 'margins' command.


  • Calculate predictive levels and margins for glm and ivreg objects (more models to be added - PRs welcome) using closed-form derivatives

  • Add custom variance-covariance matrices to all calculations to add, e.g., clustered or robust standard errors (for more information on replicating Stata analyses, see here)

  • Frequency weights are incorporated into margins and effects


To install this package from CRAN, please run


To install the development version of this package, please run

devtools::install_github('anniejw6/modmarg', build_vignettes = TRUE)

Here is an example of estimating predicted levels and effects using the iris dataset:


mod <- glm(Sepal.Length ~ Sepal.Width + Species, 
           data = iris, family = 'gaussian')
# Predicted Levels
modmarg::marg(mod, var_interest = 'Species', type = 'levels')

# Predicted Effects
modmarg::marg(mod, var_interest = 'Species', type = 'effects')

There are two vignettes included:

vignette('usage', package = 'modmarg')
vignette('delta-method', package = 'modmarg')

More Reading on the Delta Method


Version 0.9.2

  • Change variance covariance function for compatibility with R-devel

Version 0.9.0

  • Add generic functions for glm
  • Add functionality for ivreg

Version 0.7.0

  • Refactors to use generic functions

Version 0.6.0

  • Incorporates frequency weights into predictive margins and levels

Version 0.5.0

  • This is the initial CRAN release of modmarg

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.9.6 by Annie Wang, a year ago

Report a bug at

Browse source code at

Authors: Alex Gold [aut] , Nat Olin [aut] , Annie Wang [aut, cre]

Documentation:   PDF Manual  

GPL-3 license

Suggests knitr, rmarkdown, testthat, sandwich, AER

See at CRAN