Metadata-Version: 2.4
Name: causal-toolkit-yamashita
Version: 0.1.1
Summary: A Python package for causal inference methods including ATE estimation, propensity score methods, and meta-learners
Author-email: Hannah Yamashita <yamashitah@uchicago.edu>
License: MIT
Project-URL: Homepage, https://github.com/yamashann/causal-toolkit-yamashita
Project-URL: Documentation, https://github.com/yamashann/causal-toolkit-yamashita#readme
Project-URL: Repository, https://github.com/yamashann/causal-toolkit-yamashita
Project-URL: Bug Tracker, https://github.com/yamashann/causal-toolkit-yamashita/issues
Keywords: causal inference,statistics,machine learning,treatment effects
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: packaging
Requires-Dist: pandas>=1.3.0
Requires-Dist: numpy>=1.21.0
Requires-Dist: scipy>=1.7.0
Requires-Dist: scikit-learn>=1.0.0
Requires-Dist: lightgbm>=3.3.0
Requires-Dist: patsy>=0.5.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: pylint>=2.12.0; extra == "dev"
Requires-Dist: mypy>=0.950; extra == "dev"
Dynamic: license-file

# causal-toolkit-yamashita

[![Tests](https://github.com/yamashann/causal-toolkit-yamashita/workflows/Tests/badge.svg)](https://github.com/yamashann/causal-toolkit-yamashita/actions)
[![PyPI version](https://badge.fury.io/py/causal-toolkit-yamashita.svg)](https://pypi.org/project/causal-toolkit-yamashita/)

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:

```bash
pip install causal-toolkit-yamashita
```

Or install from source in editable mode for development:

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

## Usage

```python
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

```bash
uv run pytest
```

## License

MIT
