if (FALSE) { # all(sapply(c("WeightIt", "twang"), requireNamespace, quietly = TRUE))
library(WeightIt)
data("lalonde", package = "cobalt")
## Basic propensity score weighting
w.out1 <- weightit(treat ~ age + educ + race +
married + nodegree + re74 + re75,
data = lalonde, method = "ps")
bal.tab(w.out1, un = TRUE, m.threshold = .1,
v.threshold = 2)
## Weighting with a multi-category treatment
w.out2 <- weightit(race ~ age + educ + married +
nodegree + re74 + re75,
data = lalonde, method = "ps",
estimand = "ATE", use.mlogit = FALSE)
bal.tab(w.out2, un = TRUE)
bal.tab(w.out2, un = TRUE, pairwise = FALSE)
## IPW for longitudinal treatments
data("iptwExWide", package = "twang")
wmsm.out <- weightitMSM(list(tx1 ~ use0 + gender,
tx2 ~ use0 + gender + use1 + tx1,
tx3 ~ use0 + gender + use1 + tx1 + use2 + tx2),
data = iptwExWide,
stabilize = TRUE)
bal.tab(wmsm.out)
}
Run the code above in your browser using DataLab