if (FALSE) { # rlang::is_installed("cobalt")
library("cobalt")
data("lalonde", package = "cobalt")
tols <- process_tols(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = .1)
#Balancing covariates between treatment groups (binary)
ow1 <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = tols,
estimand = "ATT")
# Note the L2 divergence and effective sample
# size (ESS)
summary(ow1, weight.range = FALSE)
# age has a low value, married is high
plot(ow1)
tols["age"] <- 0
ow2 <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = tols,
estimand = "ATT")
# Notice that tightening the constraint on age has
# a negligible effect on the variability of the
# weights and ESS
summary(ow2, weight.range = FALSE)
tols["age"] <- .1
tols["married"] <- 0
ow3 <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
tols = tols,
estimand = "ATT")
# In contrast, tightening the constraint on married
# has a large effect on the variability of the
# weights, shrinking the ESS
summary(ow3, weight.range = FALSE)
# More duals are displayed when targeting other
# estimands:
ow4 <- optweight(treat ~ age + educ + married +
nodegree + re74, data = lalonde,
estimand = "ATE")
plot(ow4)
# Display duals by constraint type
plot(ow4, type = "constraints")
}
Run the code above in your browser using DataLab