# NOT RUN {
library("cobalt")
data("lalonde", package = "cobalt")
#Balancing covariates between treatment groups (binary)
(W1 <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "gbm", estimand = "ATE",
stop.method = "es.max"))
summary(W1)
bal.tab(W1)
# }
# NOT RUN {
#Balancing covariates with respect to race (multinomial)
(W2 <- weightit(race ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "gbm", estimand = "ATT",
focal = "hispan", stop.method = "ks.mean"))
summary(W2)
bal.tab(W2)
#Balancing covariates with respect to re75 (continuous)
(W3 <- weightit(re75 ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "gbm", use.kernel = TRUE,
stop.method = "p.rms", trim.at = .97))
summary(W3)
bal.tab(W3)
#Using a t(3) density and illustrating the search for
#more trees.
W4a <- weightit(re75 ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "gbm", density = "dt_3",
stop.method = "p.max",
n.trees = 10000)
W4a$info$best.tree #10000; optimum hasn't been found
plot(W4a$info$tree.val) #decreasing at right edge
W4b <- weightit(re75 ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "gbm", density = "dt_3",
stop.method = "p.max",
start.tree = 10000,
n.trees = 20000)
W4b$info$best.tree #13417; optimum has been found
plot(W4b$info$tree.val) #increasing at right edge
bal.tab(W4b)
#Tuning hyperparameters
(W5 <- weightit(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
method = "gbm", estimand = "ATT",
stop.method = "ks.max",
interaction.depth = 2:4,
distribution = c("bernoulli", "adaboost")))
W5$info$tune
W5$info$best.tune #Best values of tuned parameters
bal.tab(W5, stats = "k")
# }
Run the code above in your browser using DataLab