Skip to main content

A Python package for causal inference methods including RCT analysis, propensity score methods, and meta-learners.

Project description

Causal Toolkit

Tests PyPI version

A Python package for causal inference methods including RCT analysis, propensity score methods, and meta-learners.

Installation

pip install causal-toolkit-mkhan

Development Installation

git clone https://github.com/mokhan95/causal-toolkit-mkhan.git
cd causal-toolkit-mkhan
pip install -e .

Usage

RCT Analysis

from causal_toolkit_mkhan import calculate_ate_ci, calculate_ate_pvalue

ate, ci_lower, ci_upper = calculate_ate_ci(data)
ate, t_stat, p_value = calculate_ate_pvalue(data)

Propensity Score Methods

from causal_toolkit_mkhan import ipw, doubly_robust

ate_ipw = ipw(df, ps_formula="X1 + X2", T="treatment", Y="outcome")
ate_dr = doubly_robust(df, formula="X1 + X2", T="treatment", Y="outcome")

Meta-Learners

from causal_toolkit_mkhan import s_learner_discrete, t_learner_discrete, x_learner_discrete

result = s_learner_discrete(train, test, X=['x1', 'x2'], T='treatment', y='outcome')
result = t_learner_discrete(train, test, X=['x1', 'x2'], T='treatment', y='outcome')
result = x_learner_discrete(train, test, X=['x1', 'x2'], T='treatment', y='outcome')

Double ML

from causal_toolkit_mkhan import double_ml_cate

result = double_ml_cate(train, test, X=['x1', 'x2'], T='treatment', y='outcome')

API Reference

calculate_ate_ci(data, alpha=0.05)

Returns (ate, ci_lower, ci_upper) using z-test.

calculate_ate_pvalue(data)

Returns (ate, t_statistic, p_value).

ipw(df, ps_formula, T, Y)

Inverse Propensity Weighting estimation.

doubly_robust(df, formula, T, Y)

Doubly Robust estimation.

s_learner_discrete(train, test, X, T, y)

S-learner for discrete treatment CATE estimation.

t_learner_discrete(train, test, X, T, y)

T-learner for discrete treatment CATE estimation.

x_learner_discrete(train, test, X, T, y)

X-learner for discrete treatment CATE estimation.

double_ml_cate(train, test, X, T, y)

Double ML for continuous treatment CATE estimation.

Testing

uv run pytest tests/ -v

Dependencies

  • pandas >= 1.3.0
  • numpy >= 1.21.0
  • scipy >= 1.7.0
  • scikit-learn >= 1.0.0
  • lightgbm >= 3.3.0
  • patsy >= 0.5.0

License

MIT License

Author

mkhan (mohammadokhan95@gmail.com)

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_mkhan-0.1.1.tar.gz (7.0 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_mkhan-0.1.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for causal_toolkit_mkhan-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bf8711648c3592a30235a3c449f21a1cb01a763a21e6d972b3ba56ad6e1c6ffa
MD5 5b24e79269b2bfbe21ba8340be96786d
BLAKE2b-256 b513bd46cd63c1c313ab476c962b686695ef3f1e5e5633d561e025c478ff47c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for causal_toolkit_mkhan-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 13a61b2c4b08c9f8f4c546deb29762781bd329dbe905789319acad66c0c7e42a
MD5 4f89e68e1ba943f751e870917095fc22
BLAKE2b-256 fc88470512c1243d9920300af7ad6228c609832faf413c50c4305260f2af5480

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