Skip to main content

A Python package for causal inference methods including ATE estimation, propensity score methods, and meta-learners

Project description

causal-toolkit-yamashita

Tests PyPI version

A Python package for causal inference methods, including:

  • Randomized experiment analysis — average treatment effect (ATE) with confidence intervals and p-values
  • Propensity score methods — inverse probability weighting (IPW) and doubly robust estimation
  • Meta-learners — S-learner, T-learner, X-learner, and double machine learning for conditional average treatment effects (CATE)

Installation

Install the released package from PyPI:

pip install causal-toolkit-yamashita

Or install from source in editable mode for development:

git clone https://github.com/yamashann/causal-toolkit-yamashita.git
cd causal-toolkit-yamashita
uv pip install -e .

Usage

from causal_toolkit_yamashita import (
    calculate_ate_ci,
    calculate_ate_pvalue,
    ipw,
    doubly_robust,
    s_learner_discrete,
    t_learner_discrete,
    x_learner_discrete,
    double_ml_cate,
)

# Randomized experiment ATE with 95% CI
ate, ci_lower, ci_upper = calculate_ate_ci(data)

# IPW estimate of ATE
ate = ipw(df, ps_formula="x1 + x2", T="treatment", Y="outcome")

# Heterogeneous treatment effects with an X-learner
cate_df = x_learner_discrete(train, test, X=["x1", "x2"], T="t", y="y")

API

rct — Randomized experiments

Function Description
calculate_ate_ci(data, alpha=0.05) Returns (ate, ci_lower, ci_upper)
calculate_ate_pvalue(data) Returns (ate, t_stat, p_value)

propensity — Propensity score methods

Function Description
ipw(df, ps_formula, T, Y) Inverse probability weighted ATE
doubly_robust(df, formula, T, Y) Doubly robust ATE estimate

meta_learners — CATE estimation

Function Description
s_learner_discrete(train, test, X, T, y) Single-model learner; returns DataFrame with cate column
t_learner_discrete(train, test, X, T, y) Two-model learner
x_learner_discrete(train, test, X, T, y) Cross-fitted X-learner
double_ml_cate(train, test, X, T, y) Double machine learning CATE

Running tests

uv run pytest

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

causal_toolkit_yamashita-0.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

causal_toolkit_yamashita-0.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file causal_toolkit_yamashita-0.1.0.tar.gz.

File metadata

File hashes

Hashes for causal_toolkit_yamashita-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e14f8533ddbcc16472f839bc778e8baa8406afd1fcb2278ad946b5319c1127e7
MD5 bcfa053b699fafa6c0132598ad5c21d7
BLAKE2b-256 8a40ec9b05d70e0b20959572f263dac9d2458da45fdde1e6cba1d3ede56292bb

See more details on using hashes here.

File details

Details for the file causal_toolkit_yamashita-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for causal_toolkit_yamashita-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0f3d8548031f9d9283699416bf0c4434d9d0e2f42b22f2b691338d1ad255b31
MD5 0e93665dfc319a81062d814d811170b1
BLAKE2b-256 c60d175f1d11fe6017b6771a7a9ad792599a09822b263d2ce1d6128720f88601

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page