pymargins¶
Expert-mode marginal effects for Python. Session-level analytical pre-commitment, JAX-native autodiff, and a κ-driven simulation fallback when the delta method is unsafe.
pymargins wraps a fitted statistical model in a Margins
session, then computes adjusted predictions, slopes, contrasts, and
arbitrary differentiable estimands — with uncertainty from the delta
method, Krinsky–Robb simulation, or bootstrap — across statsmodels,
linearmodels, lifelines, and scikit-learn model classes.
Source code: https://github.com/huntermills707/pymargins
Issue tracker: https://github.com/huntermills707/pymargins/issues
Changelog: https://github.com/huntermills707/pymargins/blob/main/CHANGELOG.md
Getting started
Tutorials — learning by doing
- Getting started
- GLM — Binomial logit
- GLM — Poisson count
- OLS — linear regression
- Multinomial logit
- Cox proportional hazards
- Accelerated failure time models
- Instrumental variables (2SLS / LIML / GMM)
- Panel data — fixed effects
- Generalised Estimating Equations (GEE)
- Linear Mixed Effects
- Contrasts and difference-in-differences
- Inference — delta, simulation, bootstrap
- Inference scales and the κ diagnostic
- scikit-learn models
- Survey designs — weights, strata, and clusters
- Multiple imputation via
reimpute - Pooling precomputed imputations (
pool_imputations)
How-to guides — task-focused recipes
- Robust and clustered standard errors
- Bootstrap inference
- Cluster and block bootstrap
- Simultaneous confidence intervals and multiple-testing correction
- Scenario helpers
- Grid predictions
- Effects by subgroup with
over= - Difference-in-differences on the response scale
- Elasticities and semi-elasticities
- Discrete changes for binary / categorical regressors
- Per-observation influence
- Reading and controlling the κ fallback
- Writing a custom adapter
- Matching support
- Exporting and persisting results
- Plotting predictions and effects
- Nonlinear estimands with
evaluate - Linear contrasts with
contrasts - Contrasts vs
evaluate— choosing the right tool - Formula interface for array-fit models
Demos — end-to-end analyses
- Mroz (1987) — Female labor force participation
- Fair (1978) — Extramarital affairs, two ways
- Spector & Mazzeo (1980) — Did PSI work?
- Rossi recidivism — Cox proportional hazards end-to-end
- Wage panel — union premium with entity fixed effects
- Union premium heterogeneity — effects by subgroup
- ANES96 — Multinomial logit on party identification
- Travel mode choice — the value of travel time (WTP)
- California API — stratified survey design
- Bayesian marginal effects — posterior draws via
from_posterior - Transform pipelines — honest CIs for data-dependent preprocessing
Reference
Explanations — theory and design