Section 4 Box 2: Fit SuperLearner & make predictions

library(SuperLearner)
library(tmle)
set.seed(123)
ObsData.noY <- dplyr::select(ObsData, !c(Y,Y.bounded))
Y.fit.sl <- SuperLearner(Y=ObsData$Y.bounded, 
                       X=ObsData.noY, 
                       cvControl = list(V = 3),
                       SL.library=c("SL.glm", "tmle.SL.dbarts2", "SL.glmnet"),
                       method="method.CC_nloglik", 
                       family="gaussian")

ObsData$Pred.initialQ0 <- Y.fit.sl$SL.predict

# check the range of our newly predicted outcomes
summary(ObsData$Pred.initialQ0)
##        V1         
##  Min.   :0.00100  
##  1st Qu.:0.03837  
##  Median :0.05035  
##  Mean   :0.04960  
##  3rd Qu.:0.06155  
##  Max.   :0.13982
hist(ObsData$Pred.initialQ0)

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