# NOT RUN {
# Simulation from Kang and Shafer (2007) and Imai and Ratkovic (2014)
tau <- 10
set.seed(12345)
n <- 1000
X <- matrix(rnorm(n * 4, mean = 0, sd = 1), nrow = n, ncol = 4)
prop <- 1 / (1 + exp(X[, 1] - 0.5 * X[, 2] + 0.25 * X[, 3] + 0.1 * X[, 4]))
treat <- rbinom(n, 1, prop)
y <- 210 + 27.4 * X[, 1] + 13.7 * X[, 2] + 13.7 * X[, 3] + 13.7 * X[, 4] +
tau * treat + rnorm(n)
# Data frame and formulas for propensity score estimation
df <- data.frame(X, treat, y)
colnames(df) <- c("x1", "x2", "x3", "x4", "treat", "y")
formula_c <- as.formula(treat ~ x1 + x2 + x3 + x4)
# Power weighting function with alpha = 2
# ATT estimation
fitatt <- nawt(formula = formula_c, outcome = "y", estimand = "ATT",
method = "score", data = df, alpha = 2)
plot_omega(fitatt)
# ATE estimation
fitate <- nawt(formula = formula_c, outcome = "y", estimand = "ATE",
method = "score", data = df, alpha = 2)
plot_omega(fitate)
# Use method = "both"
# Two-step estimation
fitateb2s <- nawt(formula = formula_c, outcome = "y", estimand = "ATE",
method = "both", data = df, alpha = 2, twostep = TRUE)
plot_omega(fitateb2s)
# Continuously-updating GMM estimation
# }
# NOT RUN {
fitatebco <- nawt(formula = formula_c, outcome = "y", estimand = "ATE",
method = "both", data = df, alpha = 2, twostep = FALSE)
plot_omega(fitatebco) # error
# }
Run the code above in your browser using DataLab