# install the package, then load it library(nn4pse) ?dat # see Keller, Kim, & Steiner (2015) for more details head(dat) hist(dat$ps) # true propensity scores hist(dat$ps[dat$sel == 0]) # PSs for untreated hist(dat$ps[dat$sel == 1]) # PSs for treated # Define ps formula: psform <- as.formula(paste0("sel.fact ~ ", paste0("X", 1:12, collapse = " + "))) psform # Set number of cores to number available on your machine doMC::registerDoMC(cores = 4) # Fit the nn model out1 <- cv_train(ps_formula = psform, data = dat, folds = 5, decay = 10^seq(-4, 0, 1), size = c(2, 4, 8, 16), ncores = 4) out1$Performance out1$BestTune # Histogram of estimated PSs (compare with actual PSs above) hist(out1$PropensityScore) hist(out1$PropensityScore[dat$sel == 0]) hist(out1$PropensityScore[dat$sel == 1]) cor(dat$ps, out1$PropensityScore)