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 estimates causal effects from observational data using TMLE, AIPW, inverse probability weighting, and matching. Provide the propensity scores and outcome predictions from your own models as columns in a pandas DataFrame.


Why CausalEstimate?

Many causal-inference libraries combine model fitting and effect estimation. CausalEstimate keeps the two separate:

  • Bring your own predictions. Fit propensity and outcome models with scikit-learn, XGBoost, a deep model, or an external system. CausalEstimate uses the resulting columns to estimate effects.
  • Pandas-native. Pass a DataFrame with named columns and get back a plain dictionary.
  • Focused. Estimate ATE, ATT, and risk ratios. TMLE, AIPW and IPW include influence-curve standard errors, and every estimator supports bootstrap confidence intervals. Built-in diagnostics help assess overlap, covariate balance, and weights.

Choose DoWhy or EconML instead if you need an end-to-end modeling pipeline, causal-graph construction, or heterogeneous treatment effects.


Installation

pip install CausalEstimate

Quickstart

Single estimator

Each estimator is configured with its column names and effect type, then called with compute_effect(df).

from CausalEstimate.datasets import load_binary_with_probas
from CausalEstimate.estimators import IPW

# Synthetic data with known ground truth. Columns "ps", "probas",
# "probas_t0", "probas_t1" stand in for your own model's predictions.
df, params = load_binary_with_probas(
    n_samples=5000,
    random_state=42,
    return_params=True,
)

ipw = IPW(
    effect_type="ATE",
    treatment_col="treatment",
    outcome_col="Y",
    ps_col="ps",
)
results = ipw.compute_effect(df)

print(f"IPW estimated effect: {results['effect']:.4f}")
print(f"True ATE: {params['true_ate']:.4f}")
IPW estimated effect: 0.1599
True ATE: 0.1644

results["effect"] is the estimated effect. effect_1 and effect_0 are the mean potential outcomes under treatment and control.

To compare several estimators or add bootstrap confidence intervals, see Multiple Estimators & Bootstrap.


What's included

Estimator ATE ATT RR RRT ARR
IPW ✓ ✓ ✓ ✓ ✓
AIPW ✓ ✓ – – ✓
TMLE ✓ ✓ ✓ – ✓
Matching ✓* – – – ✓*

ATE is the average treatment effect, and ATT is the average treatment effect among treated units. RR is the risk ratio, RRT is the risk ratio among treated units, and ARR is the absolute risk reduction. * With a caliper, the matched population is neither the full nor the treated population; interpret accordingly.

  • Diagnostics (CausalEstimate.diagnostics): covariate balance, positivity and overlap metrics, effective sample size, and weight summaries.
  • Common-support filtering (CausalEstimate.filter_common_support): trim to the propensity-score overlap region.
  • Matching (CausalEstimate.estimators.Matching): greedy and optimal propensity-score matching with an optional caliper.
  • Synthetic datasets (CausalEstimate.datasets): load_binary and load_binary_with_probas can return known effects for benchmarking.
  • Plotting (CausalEstimate.vis): propensity-score and outcome-probability distributions by treatment group.

Run all diagnostics in one call before reporting IPW or TMLE estimates:

from CausalEstimate import run_diagnostics

report = run_diagnostics(
    df,
    ps_col="ps",
    treatment_col="treatment",
    covariate_cols=["X1", "X2"],
)
print(report["flags"])  # {"extreme_ps": bool, "unbalanced": bool}
print(report["positivity"], report["weights"], report["balance_summary"])

Documentation

Balance before/after weighting at a glance (notebook):

Love Plot

Propensity-score overlap before and after IPW weighting:

Propensity Score Boxplot

Bootstrap confidence-interval coverage on the built-in synthetic data, where the true effect is known:

Zipper Plot


Contributing

See CONTRIBUTING.md for the dev setup and test workflow. Bug reports and feature requests are welcome as issues; questions can also go to kikl@di.ku.dk.

License

MIT — see LICENSE.

Citation

Use the "Cite this repository" button on GitHub (backed by CITATION.cff), or:

@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.14.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.14.0
File Size Uploaded
causalestimate-0.14.0.tar.gz 715.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for CausalEstimate 0.14.0
File Interpreter ABI Platform
causalestimate-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 781.3 kB

Release files / causalestimate-0.14.0.tar.gz

Download URL causalestimate-0.14.0.tar.gz
Size 715.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f98e2dd30fc6c3e5c2e4eaa05cc5fe0f51f41500946c435bc459087194eb5449
BLAKE2b-256 checksum
How to use checksums
ea7f1df33029e3df6dae4ae1572d209aaedb2856510718577025ca5dfa4acce3
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 Sep 23, 2026.

Transparency log

Release files / causalestimate-0.14.0-py3-none-any.whl

Download URL causalestimate-0.14.0-py3-none-any.whl
Size 66.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ea3bcff1d0f82d3e5c0c5d42ebceb6b81d4d795fb16628cc43057d67297a1bf
BLAKE2b-256 checksum
How to use checksums
92ba61f6f053a1272b1d4015014871a0a6e7168baf2d94ebd8a1ea9bc52e6979
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 Sep 23, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files

0.11.0

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