library(survey)
# Create a survey design ----
data(involvement_survey_srs, package = 'nrba')
survey_design <- svydesign(weights = ~ BASE_WEIGHT,
id = ~ UNIQUE_ID,
fpc = ~ N_STUDENTS,
data = involvement_survey_srs)
# Compare respondents' mean to the full sample mean ----
t_test_resp_vs_full(survey_design = survey_design,
y_vars = c("STUDENT_AGE", "WHETHER_PARENT_AGREES"),
status = 'RESPONSE_STATUS',
status_codes = c('ER' = "Respondent",
'EN' = "Nonrespondent",
'IE' = "Ineligible",
'UE' = "Unknown"))
# Compare respondents' mean to the mean of all eligible cases ----
t_test_resp_vs_full(survey_design = survey_design,
y_vars = c("STUDENT_AGE", "WHETHER_PARENT_AGREES"),
status = 'RESPONSE_STATUS',
status_codes = c('ER' = "Respondent",
'EN' = "Nonrespondent",
'IE' = "Ineligible",
'UE' = "Unknown"))
# One-sided tests ----
## Null Hypothesis: Y_bar_resp - Y_bar_full <= 0.1
## Alt. Hypothesis: Y_bar_resp - Y_bar_full > 0.1
t_test_resp_vs_full(survey_design = survey_design,
y_vars = c("STUDENT_AGE", "WHETHER_PARENT_AGREES"),
status = 'RESPONSE_STATUS',
status_codes = c('ER' = "Respondent",
'EN' = "Nonrespondent",
'IE' = "Ineligible",
'UE' = "Unknown"),
null_difference = 0.1, alternative = 'greater')
## Null Hypothesis: Y_bar_resp - Y_bar_full >= 0.1
## Alt. Hypothesis: Y_bar_resp - Y_bar_full < 0.1
t_test_resp_vs_full(survey_design = survey_design,
y_vars = c("STUDENT_AGE", "WHETHER_PARENT_AGREES"),
status = 'RESPONSE_STATUS',
status_codes = c('ER' = "Respondent",
'EN' = "Nonrespondent",
'IE' = "Ineligible",
'UE' = "Unknown"),
null_difference = 0.1, alternative = 'less')
Run the code above in your browser using DataLab