A library for estimates of causal effects.
Project description
CausalEstimate
CausalEstimate is a Python library designed for causal inference, providing a suite of methods to estimate treatment effects from observational data. It includes doubly robust techniques such as Targeted Maximum Likelihood Estimation (TMLE) alongside propensity score-based methods like inverse probability weighting (IPW) and matching. The library is built for flexibility and ease of use, integrating seamlessly with pandas and supporting bootstrap-based standard error estimation.
Features
- Causal inference methods including doubly robust estimators (TMLE, AIPW)
- Tools for estimating average treatment effects (ATE, ATT, RR...)
- Bootstrap standard error estimation
Installation
To install the required dependencies, run:
pip install CausalEstimate
For local installation, clone the repository and run:
pip install -e .
Usage
Example: Using the Estimator
Here's an example of how to use the Estimator class to compute effects:
import pandas as pd
import numpy as np
from CausalEstimate.interface.estimator import Estimator
# Simulate data
np.random.seed(42)
n = 1000
ps = np.random.uniform(0, 1, n)
treatment = np.random.binomial(1, ps)
outcome = 2 + 0.5*treatment + np.random.normal(0, 1, n)
df = pd.DataFrame({
'treatment': treatment,
'outcome': outcome,
'ps': ps
})
# Create an Estimator object
estimator = Estimator(methods=['AIPW'], effect_type='ATE')
# Compute effects
results = estimator.compute_effect(
df,
treatment_col='treatment',
outcome_col='outcome',
ps_col='ps',
bootstrap=True,
n_bootstraps=100,
method_args={},
apply_common_support=False,
common_support_threshold=0.1
)
print(results)
Example: Matching
Here is an example of how to use the matching functionality in a Jupyter notebook:
import numpy as np
import pandas as pd
from CausalEstimate.matching import match_optimal
# Simulate data
ps = np.array([0.3, 0.90, 0.5, 0.34, 0.351, 0.32, 0.35, 0.81, 0.79, 0.77, 0.90, 0.6, 0.52, 0.55])
treated = np.array([1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
ids = np.array([101, 102, 103, 103, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211])
df = pd.DataFrame({
'PID': ids,
'treatment': treated,
'ps': ps
})
# Perform matching
result = match_optimal(df, n_controls=3, caliper=0.1)
print(result)
This example demonstrates how to:
- Create an
Estimatorobject with a specified method (AIPW in this case) - Use the
compute_effectmethod to estimate the Average Treatment Effect (ATE) - Apply bootstrap for standard error estimation
Development
Please refer to the CONTRIBUTING.md file for development guidelines.
Attributions
If you use CausalEstimate in your research, please cite it using the following BibTeX entry:
@software{causalestimate,
author = {Kiril Klein, ...},
title = {CausalEstimate: A Python Library for Causal Inference},
year = {2024},
url = {https://github.com/kirilklein/CausalEstimate},
version = {X.Y.Z},
note = {GitHub repository}
}
Contact
License
This project is licensed under the MIT License.
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 causalestimate-0.6.1.tar.gz.
File metadata
- Download URL: causalestimate-0.6.1.tar.gz
- Upload date:
- Size: 32.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
442564dccd268a0ecc468d71596776a4aaa03b2ebd15ef4459e54f6d9a87ff4b
|
|
| MD5 |
27fa64968ee0e3876edfadb5cec3d70e
|
|
| BLAKE2b-256 |
5a8136dd938054fa08dc003ae0fe33a0021fa25e681a7e98a6a84cd74215bb2b
|
Provenance
The following attestation bundles were made for causalestimate-0.6.1.tar.gz:
Publisher:
publish.yml on kirilklein/CausalEstimate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
causalestimate-0.6.1.tar.gz -
Subject digest:
442564dccd268a0ecc468d71596776a4aaa03b2ebd15ef4459e54f6d9a87ff4b - Sigstore transparency entry: 172962372
- Sigstore integration time:
-
Permalink:
kirilklein/CausalEstimate@9979033fb4f2a3c258061e07e028e104335fa09a -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/kirilklein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9979033fb4f2a3c258061e07e028e104335fa09a -
Trigger Event:
push
-
Statement type:
File details
Details for the file CausalEstimate-0.6.1-py3-none-any.whl.
File metadata
- Download URL: CausalEstimate-0.6.1-py3-none-any.whl
- Upload date:
- Size: 28.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f2f194d6d5226ea084620145c38bc978aa519b918874188581c43eb78f04796
|
|
| MD5 |
7611912f66c94ca8121abe5ba2e94d84
|
|
| BLAKE2b-256 |
4aa94e7b1a13127e20ca0a4bbf055a885eab5effd3c290ab796700d3135a5a23
|
Provenance
The following attestation bundles were made for CausalEstimate-0.6.1-py3-none-any.whl:
Publisher:
publish.yml on kirilklein/CausalEstimate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
causalestimate-0.6.1-py3-none-any.whl -
Subject digest:
7f2f194d6d5226ea084620145c38bc978aa519b918874188581c43eb78f04796 - Sigstore transparency entry: 172962374
- Sigstore integration time:
-
Permalink:
kirilklein/CausalEstimate@9979033fb4f2a3c258061e07e028e104335fa09a -
Branch / Tag:
refs/tags/v0.6.1 - Owner: https://github.com/kirilklein
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9979033fb4f2a3c258061e07e028e104335fa09a -
Trigger Event:
push
-
Statement type: