Skip to main content

causal_toolkit_pmathew

Tests Publish to PyPI PyPI version

causal_toolkit_pmathew packages the causal implementations into an installable causal inference toolkit.

Package contents

  • causal_toolkit_pmathew/rct.py: randomized controlled trial estimators from Week 02
  • causal_toolkit_pmathew/propensity.py: inverse propensity weighting and doubly robust estimators from Week 03
  • causal_toolkit_pmathew/meta_learners.py: S-, T-, X-learner, and double machine learning CATE estimators from Weeks 04 and 05
  • tests/: pytest coverage for the required modules

Installation

# Install from PyPI
pip install causal_toolkit_pmathew

# Or install from source
git clone https://github.com/prinupmathew/causal_toolkit_pmathew.git
cd causal_toolkit_pmathew
uv pip install -e .
python -m uv pip install -e .

Run tests

uv run pytest
python -m uv run pytest

Run pytest module with coverage

python -m pytest tests/ -v --cov=causal_toolkit_pmathew --cov-report=term-missing

Publish to PyPI

  • Create accounts:
  • Generate API tokens:
    • Go to Account Settings → API tokens → Add token
    • Scope: "Entire account"
    • Save token securely (starts with pypi-)
  • Publish to PyPI:
python -m pip install --upgrade twine build

# Set pypi credential locally in terminal (cmd)
set TWINE_USERNAME=__token__
set TWINE_PASSWORD=pypi-your-token-here

# Set pypi credential locally in terminal (bash)
export TWINE_USERNAME="__token__"
export TWINE_PASSWORD="pypi-your-token-here"

# Set pypi credential locally in terminal (powershell)
$env:TWINE_USERNAME="__token__"
$env:TWINE_PASSWORD="pypi-your-token-here"

# Verify tests pass
pytest tests/ -v

# Clean and rebuild
python -m build
python -m twine check dist/*
python -m twine upload dist/*

Automated publishing (GitHub Release -> PyPI)

  1. Add repository secret PYPI_API_TOKEN in GitHub Actions settings.
  2. Create and publish a GitHub Release (for example tag v0.1.1).
  3. GitHub Actions workflow publish.yml builds and uploads to PyPI automatically.

Usage

import pandas as pd

from causal_toolkit_pmathew import (
	calculate_ate_ci,
	doubly_robust,
	ipw,
	s_learner_discrete,
	t_learner_discrete,
)

trial_data = pd.DataFrame({
	"T": [1, 1, 0, 0],
	"Y": [11.2, 10.8, 8.9, 9.1],
})

ate, ci_lower, ci_upper = calculate_ate_ci(trial_data)

observational_data = pd.DataFrame({
	"x": [0.2, 0.7, -0.1, 1.3],
	"t": [1, 1, 0, 0],
	"y": [3.4, 2.8, 1.1, 1.6],
})

ipw_estimate = ipw(observational_data, "x", "t", "y")
dr_estimate = doubly_robust(observational_data, "x", "t", "y")

train = observational_data.rename(columns={"x": "x1"}).assign(x2=[1.0, 0.5, 0.1, -0.2])
test = train.copy()

s_cate = s_learner_discrete(train, test, ["x1", "x2"], "t", "y")
t_cate = t_learner_discrete(train, test, ["x1", "x2"], "t", "y")

API

  • calculate_ate_ci(data, alpha=0.05): estimate the average treatment effect and a two-sided confidence interval from an RCT dataset with T and Y columns
  • calculate_ate_pvalue(data): estimate the ATE, test statistic, and two-sided p-value for an RCT dataset with T and Y columns
  • ipw(df, ps_formula, T, Y): compute an inverse propensity weighted ATE
  • doubly_robust(df, formula, T, Y): compute a doubly robust ATE using propensity and outcome models
  • s_learner_discrete(train, test, X, T, y): estimate CATE with a single outcome model
  • t_learner_discrete(train, test, X, T, y): estimate CATE with separate treated and control models
  • x_learner_discrete(train, test, X, T, y): estimate CATE with the X-learner procedure
  • double_ml_cate(train, test, X, T, y): estimate CATE using residualized treatment and outcome models

Metadata

Release files for causal-toolkit-pmathew 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for causal-toolkit-pmathew 0.1.2
File Size Uploaded Provenance Actions
causal_toolkit_pmathew-0.1.2.tar.gz 13.2 kB Without provenance Details for causal_toolkit_pmathew-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for causal-toolkit-pmathew 0.1.2
File Interpreter ABI Platform Actions
causal_toolkit_pmathew-0.1.2-py3-none-any.whl Python 3 none any Details for causal_toolkit_pmathew-0.1.2-py3-none-any.whl

Total release size: 24.9 kB

Release files / causal_toolkit_pmathew-0.1.2.tar.gz

Download URL causal_toolkit_pmathew-0.1.2.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d529fe08b08c5bbb581a437b4b0cc9b00ae876cf922a126c7882c2c2ea8ba9bc
BLAKE2b-256 checksum
How to use checksums
0f207c73f0bc83840b88c38fb05ec4c8cd78cefecdaa9b7622d42e69323c89da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / causal_toolkit_pmathew-0.1.2-py3-none-any.whl

Download URL causal_toolkit_pmathew-0.1.2-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6e2d23fd6e40fe0c740ba0e9dbb151cd27fa4250c2aae1851f2fec8f77200ec8
BLAKE2b-256 checksum
How to use checksums
253d09ad3f6aaf82f49bd630ea94c0fa1732da5a6175afb5e200d3aacf7eb771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for causal-toolkit-pmathew 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page