Skip to main content

CausalEstimate

Unittests Lint using flake8 Formatting using black PyPI version Python versions License: MIT Docs Ask DeepWiki

📖 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:

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

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)

Source distribution for CausalEstimate 0.11.0
File Size Uploaded
causalestimate-0.11.0.tar.gz 133.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CausalEstimate 0.11.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

0.14.0

2 release files

This release

0.11.0 This release

2 release files

0.10.3

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page