A Python package for causal inference methods including RCT analysis, propensity score methods, and meta-learners.
Project description
Causal Toolkit
A Python package for causal inference methods including RCT analysis, propensity score methods, and meta-learners.
Installation
git clone https://github.com/mokhan95/causal-toolkit-mkhan.git
cd causal-toolkit-mkhan
uv 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file causal_toolkit_mkhan-0.1.0.tar.gz.
File metadata
- Download URL: causal_toolkit_mkhan-0.1.0.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efa62f550c615a70b9f0ef2d16c377eff859c367d3b972402157c194e9ab1a3a
|
|
| MD5 |
912a5982d0512a3577b972cc3e2eb678
|
|
| BLAKE2b-256 |
5671abac785a51c270bd1300cc632fdc8f29eab27f8e6727017843cc61254e2d
|
File details
Details for the file causal_toolkit_mkhan-0.1.0-py3-none-any.whl.
File metadata
- Download URL: causal_toolkit_mkhan-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30801f73be1b564739bcd06d1661e38e42802bd757d4a41389d5b0e6f9acc8cf
|
|
| MD5 |
a85e016d8e94df3041aa9410b43349eb
|
|
| BLAKE2b-256 |
f7afc7aa1607ab92c4acdee462b4650aaf3f705e58e4a736a0126e2f17a983c2
|