Sample R Code for generalizing trial results to target populations in Li et al. (under review)
You will need to change the directory to use the example code in script example_analysis.R This folder includes the following functions:
- IPSW_truePS.R : implement the IPSW1_tilde and IPSW2_tilde estimators for PATE and the associated sandwich variance estimators, the true treatment propensity score (e_i=1/2) is used;
- OR_truePS.R : implement the OR_tilde estimator for PATE and the associated sandwich variance estimator, the true treatment propensity score (e_i=1/2) is used;
- DR_truePS.R : implement the DR1_tilde and DR2_tilde estimators for PATE and the associated sandwich variance estimators, the true treatment propensity score (e_i=1/2) is used;
- IPSW_estPS.R : implement the IPSW1_hat and IPSW2_hat estimators for PATE and the associated sandwich variance estimators, the estimated treatment propensity score (e_i_hat) is used;
- OR_estPS.R : implement the OR_hat estimator for PATE and the associated sandwich variance estimator, the estimated treatment propensity score (e_i_hat) is used;
- DR_estPS.R : implement the DR1_tilde and DR2_tilde estimators for PATE and the associated sandwich variance estimators, the estimated treatment propensity score (e_i_hat) is used;
- simdata.R : sample R code to generate a simulated data set for illustrative analysis;
- example_analysis.R : illustrative R code to perform the generalizability analysis using the above functions that implement point and variance estimators developed in Li et al. (under review).