if (FALSE) { # rlang::is_installed("WeightIt")
data("lalonde", package = "cobalt")
# A censoring indicator: 1 = lost to follow-up
set.seed(1234)
lalonde$C <- rbinom(nrow(lalonde), 1,
prob = plogis(-1.5 + 0.05 * lalonde$age))
# Inverse probability of censoring weights
W <- WeightIt::weightit(.cens(C) ~ age + educ + race,
data = lalonde, method = "glm")
# Balance of the weighted uncensored units against the
# full at-risk sample
bal.tab(W, un = TRUE)
# The same thing without WeightIt, using the weights directly
bal.tab(.cens(C) ~ age + educ + race, data = lalonde,
weights = W$weights, un = TRUE)
}
Run the code above in your browser using DataLab