library(survey)
# Create a survey design ----
data("involvement_survey_pop", package = "nrba")
data("involvement_survey_str2s", package = "nrba")
involvement_survey_sample <- svydesign(
data = involvement_survey_str2s,
weights = ~BASE_WEIGHT,
strata = ~SCHOOL_DISTRICT,
ids = ~ SCHOOL_ID + UNIQUE_ID,
fpc = ~ N_SCHOOLS_IN_DISTRICT + N_STUDENTS_IN_SCHOOL
)
# Subset to only include survey respondents ----
involvement_survey_respondents <- subset(
involvement_survey_sample,
RESPONSE_STATUS == "Respondent"
)
# Test whether percentages of categorical variable differ from benchmark ----
parent_email_benchmark <- c(
"Has Email" = 0.85,
"No Email" = 0.15
)
chisq_test_vs_external_estimate(
survey_design = involvement_survey_respondents,
y_var = "PARENT_HAS_EMAIL",
ext_ests = parent_email_benchmark
)
Run the code above in your browser using DataLab