Section 7 Box 5: Fit propensity score SuperLearner & make predictions

library(SuperLearner)
library(tmle)
set.seed(124)
ObsData.noYA <- dplyr::select(ObsData, !c(Y,Y.bounded,
                                          A,Pred.initialQ0,
                                          Pred.initialQ0.Y1,
                                          Pred.initialQ0.Y0,
                                          Pred.TE))

PS.fit.SL <- SuperLearner(Y=ObsData$A, 
                       X=ObsData.noYA, 
                       cvControl = list(V = 3),
                       SL.library=c("SL.glm", "SL.gam", "tmle.SL.dbarts.k.5"),
                       method="method.CC_nloglik",
                       family="binomial")  
FALSE Error in s(age, 2) : 
FALSE   unordered factors cannot be used as smoothing variables
FALSE Error in s(age, 2) : 
FALSE   unordered factors cannot be used as smoothing variables
FALSE Error in s(age, 2) : 
FALSE   unordered factors cannot be used as smoothing variables
FALSE Error in s(age, 2) : 
FALSE   unordered factors cannot be used as smoothing variables
ObsData$PS.SL <- PS.fit.SL$SL.predict
summary(ObsData$PS.SL)
FALSE        V1          
FALSE  Min.   :0.001492  
FALSE  1st Qu.:0.157856  
FALSE  Median :0.349607  
FALSE  Mean   :0.379279  
FALSE  3rd Qu.:0.580233  
FALSE  Max.   :0.988144
hist(ObsData$PS.SL)

require(cobalt)
bal.plot(ObsData, var.name = "PS.SL", 
         treat = "A", 
         which = "both", 
         data = ObsData)