pycausalgps
Causal Inference with Generalized Propensity Score
pycausalgps is a Python library for implementing matching on generalized propensity scores with continuous exposures. We have developed an innovative approach for estimating causal effects using observational data in settings with continuous exposures and introduced a new framework for GPS caliper matching that jointly matches on both the estimated GPS and exposure levels to fully adjust for confounding bias.
Setting Up Environment
Please refer to the documentation for setting up the enviorment.
Installation
To install the latest release from PyPI, run:
pip install pycausalgps
To install the latest development version from GitHub, run:
git clone https://github.com/NSAPH-Software/pycausalgps
cd pycausalgps
pip install .
Usage
Geneting synthetic data
from pycausalgps.base.utils import generate_syn_pop
data = generate_syn_pop(sample_size=1000,
seed_val=456,
outcome_sd=0.25,
gps_spec=1,
cova_spec=2)
Estimating GPS
from pycausalgps.base.utils import generate_syn_pop
from pycausalgps.base import GeneralizedPropensityScore
params = {"gps_density": "normal",
"exposure_column": "treat",
"covariate_column_num": ["cf1",
"cf2",
"cf3",
"cf4",
"cf6"],
"covariate_column_cat": ["cf5"],
"libs":{
"xgboost":{
"n_estimators": 100,
"max_depth": 3,
"learning_rate": 0.1,
"test_rate": 0.2,
"random_state": 42
}
}
}
data = generate_syn_pop(sample_size=1000,
seed_val=456,
outcome_sd=0.25,
gps_spec=1,
cova_spec=2)
gps = GeneralizedPropensityScore(data, params)
Generating Pseudo Population
- Weighting approach
from pycausalgps.pseudo_population import PseudoPopulation
gps_params = {"gps_density": "normal",
"exposure_column": "treat",
"covariate_column_num": ["cf1",
"cf2",
"cf3",
"cf4",
"cf6"],
"covariate_column_cat": ["cf5"],
"libs":{
"xgboost":{
"n_estimators": 100,
"max_depth": 3,
"learning_rate": 0.1,
"test_rate": 0.2,
"random_state": 42
}
}
}
data = generate_syn_pop(sample_size=1000,
seed_val=456,
outcome_sd=0.25,
gps_spec=1,
cova_spec=2)
gps = GeneralizedPropensityScore(data, gps_params)
results = gps.get_results()
gps_data = {
'data' : results.get("data"),
'gps_density' : results.get("gps_density")
}
pspop_params = {"approach" : "weighting",
"exposure_column": "treat",
"covariate_column_num": ["cf1",
"cf2",
"cf3",
"cf4",
"cf6"],
"covariate_column_cat": ["cf5"],}
pspop = PseudoPopulation(data=data,
gps_data=gps_data,
params=pspop_params)
- Matching approach
from pycausalgps.base.utils import generate_syn_pop
from pycausalgps.gps import GeneralizedPropensityScore
from pycausalgps.pseudo_population import PseudoPopulation
gps_params = {"gps_density": "normal",
"exposure_column": "treat",
"covariate_column_num": ["cf1",
"cf2",
"cf3",
"cf4",
"cf6"],
"covariate_column_cat": ["cf5"],
"libs":{
"xgboost":{
"n_estimators": 100,
"max_depth": 3,
"learning_rate": 0.1,
"test_rate": 0.2,
"random_state": 42
}
}
}
data = generate_syn_pop(sample_size=500,
seed_val=456,
outcome_sd=0.25,
gps_spec=1,
cova_spec=2)
gps = GeneralizedPropensityScore(data, gps_params)
results = gps.get_results()
gps_data = {
'data' : results.get("data"),
'gps_density' : results.get("gps_density"),
'gps_minmax': results.get("gps_minmax")
}
pspop_params = {"approach" : "matching",
"exposure_column": "treat",
"covariate_column_num": ["cf1",
"cf2",
"cf3",
"cf4",
"cf6"],
"covariate_column_cat": ["cf5"],
"control_params": {"caliper": 1.0,
"scale": 0.5,
"dist_measure": "l1",
"bin_seq": None},
"run_params": {"n_thread": 12,
"chunk_size": 500},
}
pspop = PseudoPopulation(data=data,
gps_data=gps_data,
params=pspop_params)
Documentation
Documentation is hosted at https://nsaph-software.github.io/pycausalgps/
Metadata
Release files for pycausalgps 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pycausalgps-0.0.3.tar.gz | 29.9 kB | Without provenance | Details |
Release files / pycausalgps-0.0.3.tar.gz
| Download URL | pycausalgps-0.0.3.tar.gz |
|---|---|
| Size | 29.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a00be21dfa2b53f78c236b318d600c013caf61f56bfb6916dba33d94476f5f2b
|
|
BLAKE2b-256 checksum How to use checksums |
805e6110fd600154dd883e53d94a7962610c020f83e28f1a9d3243444cf3bd79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.6
|
Security for pycausalgps 0.0.3
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.