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.1.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.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: causal_toolkit_yamashita-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for causal_toolkit_yamashita-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fa8bae9925f00ff9f6c4c84f92e44a4229544e0f6de39fd55d2fb46b5506db29
MD5 021d3b7e4ebd9206770d4a9510c3feb9
BLAKE2b-256 c49adf8b3af8ca89095af0bdf97ea6661e50f9bf98ae5e462c8a2659eeea13a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for causal_toolkit_yamashita-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e981d0d0763545d34e622fcc74277e1d7b744f758e364aca9caf12d724910b25
MD5 8c25210d6c5a7b2f0ff7d7306deff761
BLAKE2b-256 ab6f1b6ad098da5b9eac09b40b4969cc1daf424839dfe3112575b0e80db8e580

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