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
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
- 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
Reference
Explanations — theory and design