if (FALSE) { # all(sapply(c("SuperLearner", "MASS"), requireNamespace, quietly = TRUE))
library("cobalt")
data("lalonde", package = "cobalt")
#Note: for time, all exmaples use a small set of
# learners. Many more should be added if
# possible, including a variety of model
# types (e.g., parametric, flexible, tree-
#. based, regularized, etc.)
#Balancing covariates between treatment groups (binary)
(W1 <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "super", estimand = "ATT",
SL.library = c("SL.glm", "SL.stepAIC",
"SL.glm.interaction")))
summary(W1)
bal.tab(W1)
#Balancing covariates with respect to race (multi-category)
(W2 <- weightit(race ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "super", estimand = "ATE",
SL.library = c("SL.glm", "SL.stepAIC",
"SL.glm.interaction")))
summary(W2)
bal.tab(W2)
#Balancing covariates with respect to re75 (continuous)
#assuming t(8) conditional density for treatment
(W3 <- weightit(re75 ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "super", density = "dt_8",
SL.library = c("SL.glm", "SL.ridge",
"SL.glm.interaction")))
summary(W3)
bal.tab(W3)
#Balancing covariates between treatment groups (binary)
# using balance SuperLearner to minimize the maximum
# KS statistic
(W4 <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "super", estimand = "ATT",
SL.library = c("SL.glm", "SL.stepAIC",
"SL.lda"),
SL.method = "method.balance",
criterion = "ks.max"))
summary(W4)
bal.tab(W4, stats = c("m", "ks"))
}
Run the code above in your browser using DataLab