Skip to content
marginaleffects needs insight, which CRAN will archive unless its check problems are fixed by Nov 14.

marginaleffects

1.0.0Package record

Predictions, Comparisons, Slopes, Marginal Means, and Hypothesis Tests

16packages dependsuggested by 34
418.7Kdownloads / year
–test coverage
13/13flavors OK

Overview

About

Compute and plot predictions, slopes, marginal means, and comparisons (contrasts, risk ratios, odds, etc.) for over 100 classes of statistical and machine learning models in R. Conduct linear and non-linear hypothesis tests, or equivalence tests. Calculate uncertainty estimates using the delta method, bootstrapping, or simulation-based inference. Details can be found in Arel-Bundock, Greifer, and Heiss (2024) doi:10.18637/jss.v111.i09.

Changes in 1.0.0

Breaking changes:

  • The byfun argument is no longer supported. Use hypothesis for custom aggregations.
  • Removed autodiff(), JAX differentiation, and the reticulate dependency. Remove calls to autodiff(). The new analytic Jacobians are faster and have broader coverage (see Performance below).

New features:

  • New vcov = "unconditional" standard errors for average predictions, comparisons, and slopes account for sampling variation in the covariate distribution. vcovUnconditional() supports HC0 (default), HC1, one-way clustering, built-in contrasts, weighted targets, lm, glm, survey::svyglm(), and validated fixest::feols() cases. Unsupported multiple-imputation, hypotheses(), fixed-effect fixest, censored, and survival cases produce informative errors and recommend bootstrap inference where appropriate. vcov = vcovUnconditional is equivalent to vcov = vcovUnconditional(). Thanks to @pedrohcgs for the code contribution in #1737; @snhansen for theoretical guidance and independent testing; and @ngreifer and @grantmcdermott for discussion in #1240 and #1737.
  • New set_modeldata() attaches training data to model objects. get_modeldata() uses it first and warns once per session about retrieval problems from insight::get_data().
  • New components(x, "jacobian_method") reports the differentiation path.

New models:

  • Added support for svyVGAM::svy_vglm() (#1730, @kkranker), glmtoolbox::glmgee() and glmtoolbox::gnm() (#1148, @luifrancgom), nestedLogit::nestedLogit() (#1675, @strengejacke), mmrm::mmrm() (#1000, @kkmann, @lang-benjamin, and @danielinteractive), and ordinal::clmm2() (#1003).
  • Improved the type error for aft models.

Performance:

  • Eligible estimands now use exact analytic Jacobians for lm, glm, MASS::glm.nb(), MASS::rlm(), brglm2::brglmFit(), quantreg::rq(), ivreg, geepack::geeglm(), survey::svyglm(), rms::ols(), and binary rms::lrm() models. Newly exact standard errors may differ from previous builds by about 1e-7.
Show all changes in 1.0.0Hide the rest of the changes in 1.0.0
  • Many comparisons() and slopes() calls are at least three times faster on large datasets.
  • Built-in ratios, lifts, slopes, and elasticities now use exact derivatives.
  • Linear hypothesis= expressions and supported formula shortcuts compile to contrast matrices, and post-hoc hypotheses() uses the same exact path for linear expressions, including constants. Nonlinear hypotheses compose with upstream Jacobians instead of re-differentiating the full pipeline. Issue #1735. Thanks to @nremenyi for #1750.
  • Bayesian posterior draws processing is much more efficient.
  • Set options(marginaleffects_analytic_jacobian = FALSE) to disable analytic Jacobians and force the numerical fallback, which is useful for validation and debugging.

Covariance and inference:

  • User-supplied covariance matrices must cover all coefficients. Named matrices are reordered and validated; unnamed matrices warn about positional matching. Errors from vcov functions are now propagated.
  • vcov = "stata" now maps to HC1, matching Stata, estimatr, and modelsummary; use vcov = "HC2" for the previous behavior.
  • multcomp= and simulated Wald inference now respect the hypothesis null and direction. Bonferroni confidence intervals now match Bonferroni p values.
  • Exact zero standard errors are reported as NA, along with their associated inferential quantities. This distinguishes structural or constant estimands from effects estimated with very small uncertainty.
  • Per-observation df vectors are rejected with aggregation or hypotheses; df = NULL remains valid. Equivalence tests support vector-valued degrees of freedom and reject reversed bounds.
  • Weighted average comparisons no longer return NaN when a group's first weight is zero; groups with zero total weight remain undefined.

Hypotheses and contrasts:

  • Numeric variables= functions and data frames honor lo/hi and low/high regardless of order and may return data frames, data tables, or tibbles. Logical comparisons honor their requested direction.
  • hypothesis formulas group by datagrid() variables when by is omitted and can resolve external variables such as ~ I(drop(t(www) %*% x)) | am. Thanks to Matt Thomas for #1705 and @mattansb for #1707.
  • Hypothesis functions may declare newdata and by; empty results now error. Joint tests prefer exact name matches, reject ambiguous or missing matches, and report null values correctly. Matrix hypotheses preserve posterior and bootstrap draws.
  • ~meandev and ~meanotherdev now use O(np) time and memory instead of dense n x n matrices, reducing memory use from 573 MB for 10,000 estimates.
  • numderiv = list("richardson", side = ...) is now accepted; the validator previously rejected side and accepted the nonexistent size argument.

Data, grids, and grouping:

  • Grouped comparisons and slopes support by = "rowid", avoid collisions with data columns named predicted, term, or contrast, preserve posterior and bootstrap draws when groups are incomplete, and retain comparison = "lift" rows with duplicate labels. Thanks to @coughlanja for #1669.
  • Formula terms are parsed to recognize factor(x, levels = ...), as.numeric(x), and as.logical(x), preventing invalid datagrid() values and NA predictions.
  • datagrid() now preserves counterfactual row identifiers across groups, supports grouped data.table inputs, honors response, validates grouping columns, and treats numeric fixest fixed effects as categorical. Thanks to @arcruz0 for #1685.
  • newdata shortcuts now handle logical, integer, binary, and missing values as documented. Existing rowid columns are no longer modified by reference.
  • avg_predictions() with factor variables uses all factor levels when the original model data is unavailable. Thanks to @trose64 for report #1703.

Model compatibility:

  • Corrected standard errors for survival::survreg() models with estimated scale, named systemfit() equations, mhurdle scale parameters, and zero coefficients in nnet::multinom().
  • Repeated standard-error calculations for nls() models are now reproducible.
  • betareg models without a precision formula now align the precision parameter names used by get_coef() and get_vcov(), allowing user-supplied covariance matrices.
  • lm and glm estimates work when qr$qr was removed from the fitted object; linear predictions fall back to the model matrix when stats::predict() fails. Thanks to @trose64 for report #1748.
  • vcov = "HC0" no longer changes response-scale point estimates for glmmTMB models with random effects; robust covariance extraction now restores the internal TMB state. Thanks to @nremenyi for the report.
  • Fixed mira models fitted with formula transformations and subset=, and enabled predictions(<mira>, newdata = datagrid(...)) for mice objects. Thanks to @dmongin for #1682.
  • flexsurv prediction standard errors now synchronize transformed coefficients and delegate to flexsurv::predict() when vcov = TRUE. Thanks to @colinorourke for report #1670.
  • hypotheses() no longer errors on survey::svyglm() objects when no averaging is required. Thanks to @bdwilliamson for Issue #1723.

Bootstrap and conformal inference:

  • Bootstrap and refit() reject models fitted with external weight vectors. Bootstrap refits no longer resolve unrelated global data, and fractional weighted bootstrap uses model-stored data. Thanks to @U8NWXD for #1713.
  • Bootstrap inference with a user-supplied estimator uses the conf_level from the estimator result.
  • Conformal intervals now use the correct finite-sample quantile, warn and return infinite bounds when calibration data are insufficient, respect transformed outcomes, and preserve absolute residuals for squared-residual CV+ scores.

Predictions and comparisons:

  • Comparison rows are now dropped when either prediction is missing.
  • transform= handles NaN confidence bounds and reports wrong-length function results clearly.

Plots, printing, and diagnostics:

  • Plot functions avoid duplicate lines, handle missing response labels and duplicated rounded condition values, and support points= and rug= with cbind() responses.
  • Printing handles NA values in df. print(style = "tinytable") preserves Term: and Comparison: notes when their columns are dropped and bases that decision on the full object rather than the displayed rows.
  • Fixed diagnostics and validation in expect_margins() and expect_slopes().
  • Models with NA coefficients now trigger a once-per-session rank-deficiency warning. Thanks to @andymilne for #1744.

From NEWS.md in the release

Install

Health

CRAN checks
13OK
Slowest check: 2.9 min · r-oldrel-windows-x86_64
Status changes
  • OK13 OK2026-08-05
  • NOTE12 OK, 1 NOTE2026-08-01
  • OK12 OK2026-04-25
  • NOTE13 OK, 1 NOTE2026-03-10
Advisories

none known

Documentation

In release 1.0.0
READMEYes · 309 wordsVignettesYes · 1 · dynamicNEWSYes · 100% structured · mentions 1.0.0Citation fileYes · cites a publicationWebsiteYes
Cites a JSS article
Help pages
36 (19 internal)
Examples that run
82%9 run in a plain check (6 of them under a condition) · 2 never run
Exported functions with examples
37%
Documented parameters
73%
Return-value docs
67%
Help pages citing references
8%
Vignettes (1)

Downloads

418.7K
CRAN downloads in the past year
Rank #600 · ~1.1K/day · ~34.9K/mo
Daily download trend is not available in this view yet.
35.8K30 days
101.5K90 days
418.7K1 year
Compare downloads with other packages →
Also on5.7K r2u6 autocran17K conda_forge130 c2d4u

Repository

651Stars
70Forks
7Open issues
2Open PRs
23Releases
5,199Commits
43Commit identities
5,199 commits · Last activity 2026-10-23 · +0.8% stars, 30d · Discussions: 53 posts
Responsiveness
How these are sampled
PRs merged (all time)
84%
Median days to close, 50 most recently updated closed issues
5
Median days to close, 50 most recently updated closed PRs
1

Stars over time

2025-10-22 · 5612026-10-24 · 651
PracticesBeta

6 development-tooling and community-health practices detected across 5 families in the upstream repository

Checks run against github.com/vincentarelbundock/marginaleffects on 2026-10-22.

Continuous integration (2)
GitHub ActionsR CMD check workflow

The R CMD check workflow runs on Linux, macOS and Windows

Governance and community (1)
Issue templates
Docs source (1)

GitHub Pages site last deployed 2025-05-19

Reproducibility and dev environment (1)
Makefile
Show all practicesHide 1 practice
Lint, format, editor (1)
Lint workflow
How this is detected·Detection ruleset v4 (2026-10-20)
AI coding toolsBeta

This repository shows signs of AI coding tools.

  • Claude Codefirst seen 2026-03-10
    Pull request it wrote: opened by a project member
    Commits: at least 9 crediting it in the message
Models named in its commits
  • Claude Opus 56 commits · Aug to Sep 2026
  • Claude Fable 51 commit · Aug 2026
  • Claude Fable 5.11 commit · Oct 2026
  • Claude Opus 4.61 commit · Mar 2026
Counts are commits, not lines of code. Commits by a tool's accounts count once across all of its accounts. Commits crediting it are the largest count among its credit lines, a minimum.How this is detected·Detection ruleset v4 (updated 2026-09-27)

Dependencies

Declared dependencies
157 external dependencies (excludes base and recommended)

Installing marginaleffects adds 7 packages (4 with compiled code, 8.0 MB of source tarballs). Heaviest: data.table 5.7 MB, insight 1.2 MB, rlang 766 KB.

Depends (1)
R >= 3.6.0
LinkingTo (0)
none
Enhances (0)
none
Dependencies facing archival

CRAN will archive these unless their check problems are fixed by the date shown. This package needs each one to install.

People & History

People (5)
Author, Maintainer since 0.1.0 (2021), Copyright holder
Contributor · added in 0.10.0
Contributor · added in 0.8.0
Contributor · added in 0.24.0
Contributor · added in 0.24.0
Listed in earlier versions (1)
Marcio Augusto Diniz
no longer listed · 0.7.1 to 0.18.0
Releases (45)

Pick two releases to compare their code metrics.

  • 1.0.0Latest
    record
    2026-09-03 · current release · diff ↗ ·
    removed 1 export
    autodiff
    added 3 exports
    get_modeldata, set_modeldata, vcovUnconditional
  • R
    R 4.6.0 released · 2026-04-24
  • 0.32.0
    record
    2026-02-14 · diff ↗
  • 0.31.0
    record
    2025-11-15 · diff ↗ ·
    added 1 export
    refit
  • 0.30.0
    record
    2025-09-13 · diff ↗ ·
    added 1 export
    autodiff
  • 0.29.0
    record
    2025-08-28 · diff ↗ ·
    added 4 exports
    components, expect_comparisons, expect_hypotheses, prune
  • 0.28.0
    record
    2025-06-25 · diff ↗
  • 0.27.0
    record
    2025-06-04 · diff ↗
  • 0.26.0
    record
    2025-05-19 · diff ↗
  • R
    R 4.5.0 released · 2025-04-11
  • 0.25.1
    record
    2025-03-29 · diff ↗
  • 0.25.0
    record
    2025-02-01 · diff ↗ ·
    removed 6 exports
    datagridcf, deltamethod, marginal_means, marginaleffects, marginalmeans, meffects
    added 1 export
    get_dataset
  • 0.24.0
    record
    2024-11-25 · diff ↗ ·
    removed 2 exports
    posteriordraws, specify_hypothesis
    added 1 export
    get_draws
  • 0.23.0
    record
    2024-10-05 · diff ↗
  • 0.22.0
    record
    2024-08-31 · diff ↗
  • 0.21.0
    record
    2024-06-14 · diff ↗
Show 37 earlier eventsHide 37 earlier events
  • 0.20.1
    record
    2024-05-08 · diff ↗
  • 0.20.0
    record
    2024-05-06 · diff ↗ ·
    added 1 export
    specify_hypothesis
  • R
    R 4.4.0 released · 2024-04-24
  • 0.19.0
    record
    2024-04-14 · diff ↗
  • 0.18.0
    record
    2024-02-05 · diff ↗ ·
    removed 4 exports
    expect_marginal_means, plot_cap, plot_cco, plot_cme
  • 0.17.0
    record
    2023-12-09 · diff ↗
  • 0.16.0
    record
    2023-10-20 · diff ↗
  • 0.15.1
    record
    2023-09-17 · diff ↗
  • 0.15.0
    record
    2023-09-11 · diff ↗
  • 0.14.0
    record
    2023-08-15 · diff ↗
  • 0.13.0
    record
    2023-06-19 · diff ↗
  • 0.12.0
    record
    2023-05-20 · diff ↗
  • 0.11.2
    record
    2023-05-13 · diff ↗
  • R
    R 4.3.0 released · 2023-04-21
  • 0.11.1
    record
    2023-03-31 · diff ↗
  • 0.11.0
    record
    2023-03-10 · diff ↗ ·
    added 1 export
    get_model_matrix
  • 0.10.0
    record
    2023-02-22 · diff ↗
  • 0.9.0
    record
    2023-02-01 · diff ↗ ·
    removed 3 exports
    counterfactual, mean_or_mode, typical
    added 15 exports
    avg_comparisons, avg_predictions, avg_slopes, expect_marginal_means, expect_margins, expect_predictions, expect_slopes, hypotheses, inferences, marginal_means, plot_comparisons, plot_predictions, plot_slopes, posterior_draws, slopes
  • 0.8.1
    record
    2022-11-23 · diff ↗
  • 0.8.0
    record
    2022-11-02 · diff ↗
  • 0.7.1
    record
    2022-09-25 · diff ↗
  • 0.7.0
    record
    2022-08-06 · diff ↗ ·
    added 1 export
    datagridcf
  • 0.6.0
    record
    2022-06-20 · diff ↗ ·
    added 2 exports
    deltamethod, plot_cco
  • unarchivedReturned to CRAN
    2022-05-17
  • 0.5.0
    record
    2022-05-17 · diff ↗
  • archivedRemoved from CRAN
    2022-05-15
    check issues were not corrected in time
  • R
    R 4.2.0 released · 2022-04-22
  • 0.4.1
    record
    2022-03-28 · diff ↗
  • 0.4.0
    record
    2022-03-13 · diff ↗ ·
    added 1 export
    comparisons
  • 0.3.4
    record
    2022-03-03 · diff ↗
  • 0.3.3
    record
    2022-01-26 · diff ↗
  • 0.3.2
    record
    2022-01-18 · diff ↗
  • 0.3.1
    record
    2022-01-09 · diff ↗
  • 0.3.0
    record
    2022-01-08 · diff ↗ ·
    removed 1 export
    sanity_model_specific
    added 2 exports
    datagrid, posteriordraws
  • 0.2.0
    record
    2021-10-18 · diff ↗ ·
    removed 1 export
    get_dydx_and_se
  • 0.1.0
    record
    2021-09-29
  • R
    R 4.1.0 released · 2021-05-18

Package metadata

First published
2021-09-29
Total releases
45 / 5 yrs
License
GPL (>= 3) OSI
Copyright
inst/COPYRIGHTS
Minimum R
≥ 3.6.0
Download size
1.6 MB

Cite

Cite this package

Run in R for the authors' entry:

citation("marginaleffects")

The package provides a citation file, so citation() returns the authors' own entry.

It points to 10.18637/jss.v111.i09.

Cite the R Observatory

For a number measured here: a download total, a coverage figure, an archival date.

APA

Balamuta, J. J. (2026). R Observatory: Metrics for marginaleffects version 1.0.0 [Data set]. HJJB, LLC. Data release v2026-10-25. https://doi.org/10.5281/zenodo.21843040

From data release v2026-10-25, which the citation names so these numbers can be found later. More on citing and the projects behind them.

Report a problem with this page →

Privacy choices

These apply to this browser and are stored on this device only. Nothing about your choice is sent to us.

Read the privacy policy