View source: R/summary_functions.R
run_benchmarking | R Documentation |
Wrapper function to run formal benchmarking on a set of pre-specified covariates. Returns a data.frame containing the benchmarked parameter values, the estimated bias, MRCS, and minimum k_sigma
and k_rho
values for a killer confounder.
run_benchmarking(
estimate,
RV,
formula = NULL,
weights = NULL,
pop_svy = NULL,
sample_svy = NULL,
Y = NULL,
weighting_vars = NULL,
benchmark_vars = "all",
data = NULL,
treatment = NULL,
outcome = NULL,
selection = NULL,
population_targets = NULL,
weighting_method = "ebal",
weight_max = Inf,
sigma2 = NULL,
estimand = "ATT"
)
estimate |
Weighted estimate |
RV |
Robustness Value |
formula |
Raking formula for survey estimand |
weights |
A vector, containing the estimated survey weights |
pop_svy |
Survey object, containing the population the survey sample is being re-weighted to |
sample_svy |
Survey object, containing the survey sample being re-weighted |
Y |
outcome of interest (used for survey object) |
weighting_vars |
Vector of variables to use in the weights estimation for ATT or PATE |
benchmark_vars |
Vector of variables to benchmark parameters for. If |
data |
A data.frame containing the observed covariates included in the weights; must include variables specified in weighting_vars |
treatment |
Denotes which variable is the treatment variable |
outcome |
Denotes which variable is the outcome variable |
selection |
Denotes which variable is the selection variable |
population_targets |
Population targets for the raking formula in surveys (optional, if not provided, will be generated from pop_svy) |
weighting_method |
Weighting method. Supports weighting methods from the package |
weight_max |
Maximum weight to trim at. Default set to |
sigma2 |
If |
estimand |
Specifies estimand; possible parameters include "ATT", "PATE", or "Survey" |
data.frame containing the benchmarked parameter values, the estimated bias, MRCS, and minimum k_sigma
and k_rho
values for a killer confounder for the set of pre-specified covariates.
# For the external validity setting:
data(jtpa_women)
site_name <- "NE"
df_site <- jtpa_women[which(jtpa_women$site == site_name), ]
df_else <- jtpa_women[which(jtpa_women$site != site_name), ]
# Estimate unweighted estimator:
model_dim <- estimatr::lm_robust(Y ~ T, data = df_site)
PATE <- coef(lm(Y ~ T, data = df_else))[2]
DiM <- coef(model_dim)[2]
# Generate weights using observed covariates:
df_all <- jtpa_women
df_all$S <- ifelse(jtpa_women$site == "NE", 1, 0)
model_ps <- WeightIt::weightit(
(1 - S) ~ . - site - T - Y,
data = df_all, method = "ebal", estimand = "ATT"
)
weights <- model_ps$weights[df_all$S == 1]
# Estimate IPW model:
model_ipw <- estimatr::lm_robust(Y ~ T, data = df_site, weights = weights)
ipw <- coef(model_ipw)[2]
# Estimate bound for var(tau):
vartau <- var(df_site$Y[df_site$T == 1]) - var(df_site$Y[df_site$T == 0])
RV <- robustness_value(estimate = ipw, b_star = 0, sigma2 = vartau, weights = weights)
# Select weighting variables:
weighting_vars <- names(df_all)[which(!names(df_all) %in% c("site", "S", "Y", "T"))]
# Run benchmarking:
df_benchmark <- run_benchmarking(
weighting_vars = weighting_vars,
data = df_all[, -1],
treatment = "T", outcome = "Y", selection = "S",
estimate = ipw,
RV = RV, sigma2 = vartau,
estimand = "PATE"
)
print(df_benchmark)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.