Package: pycausalgps
pycausalgpsCausal Inference with Generalized Propensity Scorepycausalgps 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 EnvironmentPlease refer to the documentation for setting up the enviorment.InstallationTo install the latest release from PyPI, run:pipinstallpycausalgpsTo install the latest development version from GitHub, run:gitclonehttps://github.com/NSAPH-Software/pycausalgpscdpycausalgps
pipinstall.UsageGeneting synthetic datafrompycausalgps.base.utilsimportgenerate_syn_popdata=generate_syn_pop(sample_size=1000,seed_val=456,outcome_sd=0.25,gps_spec=1,cova_spec=2)Estimating GPSfrompycausalgps.base.utilsimportgenerate_syn_popfrompycausalgps.baseimportGeneralizedPropensityScoreparams={"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 PopulationWeighting approachfrompycausalgps.pseudo_populationimportPseudoPopulationgps_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 approachfrompycausalgps.base.utilsimportgenerate_syn_popfrompycausalgps.gpsimportGeneralizedPropensityScorefrompycausalgps.pseudo_populationimportPseudoPopulationgps_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)DocumentationDocumentation is hosted athttps://nsaph-software.github.io/pycausalgps/