# Load example data
suppressPackageStartupMessages(library(survey))
data(api)
base_weights_design <- svydesign(
data = apiclus1,
id = ~dnum,
weights = ~pw,
fpc = ~fpc
) |> as.svrepdesign(type = "JK1")
base_weights_design$variables$response_status <- sample(
x = c("Respondent", "Nonrespondent"),
prob = c(0.75, 0.25),
size = nrow(base_weights_design),
replace = TRUE
)
# Assess range of bias for mean of `api00`
# based on assuming nonrespondent means
# are equal to the 25th percentile or 75th percentile
# among respondents, within nonresponse adjustment cells
assess_range_of_bias(
survey_design = base_weights_design,
y_var = "api00",
comparison_cell = "stype",
status = "response_status",
status_codes = c("ER" = "Respondent",
"EN" = "Nonrespondent",
"IE" = "Ineligible",
"UE" = "Unknown"),
assumed_percentile = c(0.25, 0.75)
)
# Assess range of bias for proportions of `sch.wide`
# based on assuming nonrespondent proportions
# are equal to some multiple of respondent proportions,
# within nonresponse adjustment cells
assess_range_of_bias(
survey_design = base_weights_design,
y_var = "sch.wide",
comparison_cell = "stype",
status = "response_status",
status_codes = c("ER" = "Respondent",
"EN" = "Nonrespondent",
"IE" = "Ineligible",
"UE" = "Unknown"),
assumed_multiple = c(0.25, 0.75)
)
Run the code above in your browser using DataLab