Skip to main content

Entropy Balancing for Causal Inference - Binary and Continuous Treatment

Project description

Entropy Balancing for Binary and Continuous Treatment

Python implementation of Entropy Balancing for binary and continuous treatment

Author: Eddie Yang

ebal for binary treatment is based on Hainmueller (2012) and ebal for continuous treatment is based on Tübbicke (2020) and Vegetabile et al. (2021).

Installation

# From PyPI
pip install ebal

# From GitHub
pip install git+https://github.com/EddieYang211/ebal-py.git

# For development
git clone https://github.com/EddieYang211/ebal-py.git
cd ebal
pip install -e .

Examples

# Binary
import pandas as pd
from ebal import ebal_bin

df = pd.read_csv('~/data.csv')

treatment="treat"
tmp_df = df[df[treatment].isin([0, 1])]
tmp_df = tmp_df.sort_values(by=[treatment])
tmp_df = tmp_df.reset_index(drop=True)

Y = tmp_df.Y.values
X = tmp_df.loc[:,0:10]                         #features
T = tmp_df[treatment].values                   #treatment
e = ebal_bin()
out = e.ebalance(T, X, Y)

# print ebal-weighted regression result
out['wls'].summary()

# check post-weighting balance between treatment and control groups
e.check_balance(X, T, out['w'])
# Continuous
import pandas as pd
from ebal import ebal_con

df = pd.read_csv('~/data_cont.csv')

Y = df.Y.values
X = df.iloc[:,4:]                         #features
T = df.T.values                           #treatment

e = ebal_con()
out = e.ebalance(T, X)

# check post-weighting Pearson correlation
e.check_balance(X, T, out['w'])

Documentation

For detailed documentation in Chinese:

Reference

  • Hainmueller, J. (2012). Entropy balancing for causal effects: A multivariate reweighting method to produce balanced samples in observational studies. Political analysis, 20(1), 25-46.
  • Vegetabile, B. G., Griffin, B. A., Coffman, D. L., Cefalu, M., Robbins, M. W., & McCaffrey, D. F. (2021). Nonparametric estimation of population average dose-response curves using entropy balancing weights for continuous exposures. Health Services and Outcomes Research Methodology, 21(1), 69-110.
  • Tübbicke, S. (2020). Entropy balancing for continuous treatments. arXiv preprint arXiv:2001.06281.
  • R Package 'ebal': https://github.com/cran/ebal

License

MIT License - see LICENSE for details.

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

ebal-1.0.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ebal-1.0.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file ebal-1.0.0.tar.gz.

File metadata

  • Download URL: ebal-1.0.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for ebal-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b35d770ad977552c1c1fb3348f3bc2a8927cc167fbd98f42f04b204c97e394de
MD5 58fca809c5c5647946b8f9805d866611
BLAKE2b-256 fe9f8fcd536755b545bcfb5bc255f311cca35df7ce8bc5c28e22e0916b166531

See more details on using hashes here.

File details

Details for the file ebal-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ebal-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for ebal-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8909239be98b556b8fc6f8b31ac50fea8a56b2ecf58454d573f7aa37f15d7796
MD5 c53007ccaa5e6f3ebc8d799a7d405361
BLAKE2b-256 bb8307ed5d7ad7e176656cfde94d605508390bb63ac932ce7ae48c8f2d34eccc

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