data("lalonde", package = "cobalt")
# Logistic regression model
fit1 <- glm_weightit(
re78 > 0 ~ treat * (age + educ + race + married +
re74 + re75),
data = lalonde, family = binomial, vcov = "none")
summary(predict(fit1))
# G-computation using predicted probabilities
p0 <- predict(fit1, type = "response",
newdata = transform(lalonde,
treat = 0))
p1 <- predict(fit1, type = "response",
newdata = transform(lalonde,
treat = 1))
mean(p1) - mean(p0)
# Multinomial logistic regression model
lalonde$re78_3 <- factor(findInterval(lalonde$re78,
c(0, 5e3, 1e4)),
labels = c("low", "med", "high"))
fit2 <- multinom_weightit(
re78_3 ~ treat * (age + educ + race + married +
re74 + re75),
data = lalonde, vcov = "none")
# Predicted probabilities
head(predict(fit2))
# Class assignment accuracy
mean(predict(fit2, type = "class") == lalonde$re78_3)
# G-computation using expected value of the outcome
values <- c("low" = 2500,
"med" = 7500,
"high" = 12500)
p0 <- predict(fit2, type = "mean", values = values,
newdata = transform(lalonde,
treat = 0))
p1 <- predict(fit2, type = "mean", values = values,
newdata = transform(lalonde,
treat = 1))
mean(p1) - mean(p0)
# Ordinal logistic regression
fit3 <- ordinal_weightit(
re78 ~ treat * (age + educ + race + married +
re74 + re75),
data = lalonde, vcov = "none")
# G-computation using expected value of the outcome;
# using original outcome values
p0 <- predict(fit3, type = "mean",
newdata = transform(lalonde,
treat = 0))
p1 <- predict(fit3, type = "mean",
newdata = transform(lalonde,
treat = 1))
mean(p1) - mean(p0)
Run the code above in your browser using DataLab