Skip to content

Commit 852af7f

Browse files
authored
Merge pull request #1298 from cmu-delphi/contingency-cut-by-vaccinated
Add vaccination status breakdown to contingency tables
2 parents a1d2863 + 340cf4b commit 852af7f

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

facebook/delphiFacebook/R/contingency_indicators.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ get_aggs <- function() {
6363
c("gender", "edulevel"),
6464
c("occupation"),
6565
c("pregnant", "raceethnicity"),
66-
c("race", "hispanic", "pregnant")
66+
c("race", "hispanic", "pregnant"),
67+
c("vaccinationstatus")
6768
)
6869

6970
indicators <- tribble(

facebook/delphiFacebook/R/contingency_variables.R

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,40 @@ code_health <- function(input_data, wave) {
227227
return(input_data)
228228
}
229229

230+
#' Vaccinated summary variable for making table cuts
231+
#'
232+
#' @param input_data input data frame of raw survey data
233+
#' @param wave integer indicating survey version
234+
#'
235+
#' @return augmented data frame
236+
code_vaccinated_breakdown <- function(input_data, wave) {
237+
# grouping variable - vaccination status
238+
if (all(c("V1", "V3a", "V11a") %in% names(input_data))) {
239+
input_data$vaccinationstatus <- case_when(
240+
input_data$V1 == 1 ~ "Vaccinated",
241+
input_data$V3a == 1 ~ "Accept/Appointment",
242+
input_data$V3a == 2 ~ "Accept/Appointment",
243+
input_data$V11a == 1 ~ "Accept/Appointment",
244+
input_data$V3a == 3 ~ "Hesitant",
245+
input_data$V3a == 4 ~ "Hesitant",
246+
TRUE ~ NA_character_
247+
)
248+
} else if (all(c("V1", "V3") %in% names(input_data))) {
249+
input_data$vaccinationstatus <- case_when(
250+
input_data$V1 == 1 ~ "Vaccinated",
251+
input_data$V3 == 1 ~ "Accept/Appointment",
252+
input_data$V3 == 2 ~ "Accept/Appointment",
253+
input_data$V3 == 3 ~ "Hesitant",
254+
input_data$V3 == 4 ~ "Hesitant",
255+
TRUE ~ NA_character_
256+
)
257+
} else {
258+
input_data$vaccinationstatus <- NA
259+
}
260+
261+
return(input_data)
262+
}
263+
230264
#' COVID vaccination variables with modifications for contingency tables
231265
#'
232266
#' @param input_data input data frame of raw survey data

facebook/delphiFacebook/R/responses.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ load_response_one <- function(input_filename, params, contingency_run) {
220220
input_data <- code_race_ethnicity(input_data, wave)
221221
input_data <- code_occupation(input_data, wave)
222222
input_data <- code_education(input_data, wave)
223+
input_data <- code_vaccinated_breakdown(input_data, wave)
223224

224225
# Indicators
225226
input_data <- code_addl_vaccines(input_data, wave)

0 commit comments

Comments
 (0)