CausalEstimate
📖 Documentation: kirilklein.github.io/CausalEstimate
CausalEstimate is a Python library designed for causal inference, providing a suite of methods to estimate treatment effects from observational data. It includes doubly robust techniques such as Targeted Maximum Likelihood Estimation (TMLE), alongside propensity score-based methods like inverse probability weighting (IPW) and matching. The library is built for flexibility and ease of use, integrating seamlessly with pandas and supporting bootstrap-based standard error estimation and multiple estimators in one pass.
Why CausalEstimate?
Libraries like DoWhy, EconML, and causallib are powerful, but they couple effect estimation to their own model-fitting pipelines. CausalEstimate takes the opposite approach:
- Bring your own predictions. You fit propensity scores and outcome models however you like — scikit-learn, XGBoost, a deep model, or scores from an external system. CausalEstimate takes the resulting columns and estimates effects.
- Pandas-native. Input is a plain DataFrame with named columns; output is a plain dictionary. No wrappers, no custom data containers.
- Lightweight. A small dependency footprint (numpy, pandas, scipy, scikit-learn, statsmodels) and a focused scope: average effects (ATE/ATT/RR) with doubly robust estimators, matching, and bootstrap inference.
Reach for DoWhy/EconML instead when you want end-to-end pipelines, causal graphs, or heterogeneous (CATE) estimation.
Features
-
Causal inference methods and the effect types each supports:
Estimator ATE ATT RR RRT ARR IPW ✓ ✓ ✓ ✓ ✓ AIPW ✓ ✓ – – ✓ TMLE ✓ ✓ ✓ – ✓ Matching ✓* – – – ✓* ATE: average treatment effect · ATT: ATE on the treated · RR: risk ratio · RRT: risk ratio on the treated · ARR: absolute risk reduction. * With a caliper, the matched population is strictly neither the full nor the treated population; interpret accordingly.
-
Bootstrap standard error estimation and confidence intervals
-
Common-support filtering and matching (greedy, optimal)
-
Plotting utilities for distribution checks (e.g., propensity score overlap)
-
Diagnostics: positivity/overlap metrics for propensity scores
Installation
pip install CausalEstimate
Or for local development:
git clone https://github.com/kirilklein/CausalEstimate.git
cd CausalEstimate
pip install -e .
Usage
1) Single Estimator Usage
You can import any estimator class (e.g., IPW, AIPW, TMLE) and call compute_effect(df) directly. Columns (treatment, outcome, propensity score) are passed to the estimator in its constructor.
import numpy as np
import pandas as pd
from CausalEstimate.estimators import IPW
# Simulate data
np.random.seed(42)
n = 1000
ps = np.random.uniform(0, 1, n) # true propensity for treatment
treatment = np.random.binomial(1, ps) # actual treatment assignment
outcome = 2 + 0.5 * treatment + np.random.normal(0, 1, n)
df = pd.DataFrame({
"ps": ps,
"treatment": treatment,
"outcome": outcome
})
# Create an IPW Estimator for ATE
ipw_estimator = IPW(
effect_type="ATE",
treatment_col="treatment",
outcome_col="outcome",
ps_col="ps",
# optionally stabilized=True if you want stabilized IP weights
)
results = ipw_estimator.compute_effect(df)
print("IPW estimated effect:", results)
Output:
{'effect': 0.5518, 'effect_1': 2.5260, 'effect_0': 1.9742}
results is a plain dictionary: effect is the estimated treatment effect, and effect_1/effect_0 are the mean potential outcomes under treatment and control. When bootstrapping is applied (see Multiple Estimators & Bootstrap), standard errors and confidence intervals are added.
Documentation
Full documentation lives at kirilklein.github.io/CausalEstimate:
- Getting Started — installation and the input-data contract
- Estimators — IPW, AIPW, TMLE, Matching
- Multiple Estimators & Bootstrap — several estimators in one pass, with confidence intervals
- Matching — optimal and greedy propensity-score matching
- Diagnostics — positivity/overlap metrics, effective sample size, weight summaries
- Plotting — propensity-score overlap checks
- API Reference — full signatures and docstrings
Covariate balance — the standard pre/post-weighting SMD table. The denominator is the pooled unweighted SD, held fixed pre/post so both share a scale (Stuart 2010; cobalt's default):
from CausalEstimate.diagnostics import compute_balance_table, check_balance
table = compute_balance_table(df, covariate_cols=["age", "bmi"], ps_col="ps", treatment_col="treatment")
print(table) # means, smd_unweighted, smd_weighted, balanced per covariate
print(check_balance(table)) # max_smd_weighted, n_unbalanced, n_undefined, prop_unbalanced, balanced
Development
See CONTRIBUTING.md for details on setting up a dev environment, running tests, and contributing to this project.
License
CausalEstimate is licensed under the MIT License. See LICENSE for more details.
Contact
- GitHub: kirilklein
- Email: kikl@di.ku.dk
Please open issues or pull requests if you find any bugs or want to propose enhancements.
Citation
If you use CausalEstimate in your research, please cite it via the "Cite this repository" button on GitHub (backed by CITATION.cff), or use the following BibTeX entry:
@software{causalestimate,
author = {Klein, Kiril},
title = {CausalEstimate: A Python Library for Causal Inference},
year = {2024},
url = {https://github.com/kirilklein/CausalEstimate},
note = {GitHub repository}
}
Metadata
Release files for CausalEstimate 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| causalestimate-0.11.0.tar.gz | 133.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| causalestimate-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 188.6 kB
Release files / causalestimate-0.11.0.tar.gz
| Download URL | causalestimate-0.11.0.tar.gz |
|---|---|
| Size | 133.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
adacbd19c89b275df53c64c30079d74419f227b80c30b49608d0a6096175b7d2
|
|
BLAKE2b-256 checksum How to use checksums |
94f8a51ee0c5a9ffaee800474d3a3115ae6c1496677a610e8511337e0777490e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency logRelease files / causalestimate-0.11.0-py3-none-any.whl
| Download URL | causalestimate-0.11.0-py3-none-any.whl |
|---|---|
| Size | 55.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dcfeec10462f5aa13b230d6db1680fb1cd8b160c578c50d679dcda2124c849f9
|
|
BLAKE2b-256 checksum How to use checksums |
7b1f17f7bcd452d935f12b4c65b25c3a64bfd9e10dade85cc2276e97d48f45ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 30, 2026.
Transparency log