Pygformula
The pygformula implements the parametric g-formula in Python. The parametric g-formula (Robins, 1986) uses longitudinal data with time-varying treatments and confounders to estimate the risk or mean of an outcome under hypothetical treatment strategies specified by the user.
Install / Use
/learn @CausalInference/PygformulaREADME
pygformula: a python implementation of the parametric g-formula
Authors: Jing Li, Sophia Rein, Sean McGrath, Roger Logan, Ryan O’Dea, Miguel Hernán
Overview
The pygformula package implements the non-iterative conditional expectation (NICE) estimator of the g-formula algorithm (Robins, 1986). The g-formula can estimate an outcome’s counterfactual mean or risk under hypothetical treatment strategies (interventions) when there is sufficient information on time-varying treatments and confounders.
Features
- Treatments: discrete or continuous time-varying treatments.
- Outcomes: failure time outcomes or continuous/binary end of follow-up outcomes.
- Interventions: interventions on a single treatment or joint interventions on multiple treatments.
- Random measurement/visit process.
- Incorporation of a priori knowledge of the data structure.
- Censoring events.
- Competing events.
Requirements
The package requires python 3.8+ and these necessary dependencies:
- cmprsk
- joblib
- lifelines
- matplotlib
- numpy
- pandas
- prettytable
- pytruncreg
- scipy
- seaborn
- statsmodels
- tqdm
Documentation
The online documentation is available at pygformula documentation.
Issues
If you have any issues, please open an issue on github, we will regularly check the questions. For any additional questions or comments, please email jing_li@hsph.harvard.edu.
Related Skills
next
A beautifully designed, floating Pomodoro timer that respects your workspace.
product-manager-skills
50PM skill for Claude Code, Codex, Cursor, and Windsurf: diagnose SaaS metrics, critique PRDs, plan roadmaps, run discovery, and coach PM career transitions.
pm
PM Agent Rule This rule is triggered when the user types `@pm` and activates the Product Manager agent persona.
