-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-Educators-Analysis.Rmd
524 lines (436 loc) · 20.3 KB
/
2-Educators-Analysis.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
---
output: html_document
---
## Source Code for _In-person schooling and associated COVID-19 risk in the United States over Spring Semester 2021_
#### Kirsten E. Wiens, Claire P. Smith, Elena Badillo-Goicoechea, Kyra H. Grantz, M. Kate Grabowski, Andrew S. Azman, Elizabeth A. Stuart, Justin Lessler
_________
Code is provided to reproduce the primary in-person schooling (`1-Main-Schooling-Analysis.Rmd`) and occupation/work outside home (`2-Educators-Analysis.Rmd`) analyses using a synthetic dataset. Hence, results produced when knitting these documents will **not** match those presented in the accompanying paper.
Data to reproduce paper figures/tables are freely available from the CMU Delphi Research Group to researchers at universities and non-profits as detailed at Getting Data Access - Delphi Epidata API (cmu-delphi.github.io).
Please reach out to justin[at]jhu.edu if you have any questions.
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo=FALSE, message = FALSE, warning = FALSE, error=TRUE)
```
```{r loading-pkgs}
##Source code and library stuff
library(tidyverse)
library(anytime)
library(survey)
library(srvyr)
library(maps)
library(R.utils)
library(data.table)
library(extrafont)
library(viridis)
library(gtsummary)
library(janitor)
library(pheatmap)
library(RColorBrewer)
library(RcppRoll)
library(gganimate)
library(transformr)
library(ggcorrplot)
library(cdlTools)
source("HelperFuncs.R")
source("MainTextFigures.R")
```
```{r warning-message}
knitr::knit_exit("**WARNING: This document will prepare tables and figures exploring the effects of in-person schooling using a synthetic dataset. Hence, results produced when knitting this document will not match those presented in the accompanying paper. Data to reproduce paper figures/tables are freely available from the CMU Delphi Research Group to researchers at universities and non-profits as detailed at Getting Data Access - Delphi Epidata API (cmu-delphi.github.io). To proceed with running this document with the synthetic dataset, please comment out or delete this line (ln 47 in the RMD).**")
```
```{r load data}
# load full dataset
df_ws <- readRDS("data/DATA_FOR_TESTING_ONLY_DOES_NOT_REPRODUCE_RESULTS_df_full_spring2021.rds")
# recode, without dropping HH with only 1 individual
df_ws <- standard_recode(df_ws, min_HH=1) %>%
filter(!is.na(State))
# add county data
cnty_dat<- read_csv("data/county_factors.csv")%>%
mutate(fips=str_pad(FIPS,width=5,pad="0"))%>%
select(-FIPS, -X1)
df_ws <- left_join(df_ws, cnty_dat)
rm(cnty_dat)
```
```{r edtype-recode}
##Make and occupation K12Educator
df_ws <- df_ws%>%
mutate(OccEdRecode = OccupationRed,
OccEdRecode = ifelse(OccEdRecode!="Education",
as.character(OccEdRecode),
ifelse(educationjob_type%in%
c("elemid_teacher",
"preKteacher",
"second_teacher"),
"K12Teacher","OtherEductation")))
## Just to simplify the analysis, lets group small categories into 'Other'
## NOTE: in paper, threshold used to decide grouping was n<100,000
other_cats <- c("Installation, maintenance, and repair", "Cleaning and maintenance",
"Arts/entertainment", "Comm/social service", "Production",
"Personal care and service", "Construction and extraction",
"Transportation and material moving/delivery", "Protective service")
df_ws <- df_ws%>%
group_by(OccEdRecode)%>%
mutate(OccEdRecode = ifelse(OccEdRecode %in% other_cats, "Other", OccEdRecode))%>%
ungroup()
##Make factor with Office and admin support as the
##intercept
df_ws <- df_ws%>%
mutate(OccEdRecode =factor(OccEdRecode),
OccEdRecode = relevel(OccEdRecode, ref="Office and admin support"))
# setting up the outcomes to explore and object for output
outcomes <- c("tst_pos","cli_pos", "cli2_pos")
outcome_nms <- c("Test+","Covid like illness","Loss taste/smell")
occ_reg_tbl <- NULL
## Just keep columns we absolutely need to save on memory
df_ws <- df_ws%>%
select(c('fips', 'State', 'weight',
'Date', 'wk', 'period', outcomes,
'OccEdRecode', 'work_outside_paid',
'IsMale',
'Age',
'OccupationRed',
'Educational_Level',
'HH_sz', 'num_kid_recode',
'Population',
'White',
'GINI',
'Poverty',
'Description',
'mask_level',
'trav_out_state',
'bar_rest_cafe_activ',
'large_event_activ',
'pub_transit_activ',
'any_vaccine'))
## add csse attack rates
csse <- read_csv("data/JHUCSSE.csv")
df_ws <- merge_csse(df_ws, csse)
rm(csse)
```
```{r edu-text}
# aggregate occupation and work outside the home data to national data
occ_all <- aggregate_national(df_ws, variables = 'work_outside_paid',
aggregate_by = c('OccEdRecode'))
# aggregate occupation and work outside the home data to national-monthly data
occ_mo <- aggregate_national(df_ws, variables = 'work_outside_paid',
aggregate_by = c('month', 'OccEdRecode'))
# aggregate occupation and work outside the home data to national-weekly data
occ_wk <- aggregate_national(df_ws, variables = 'work_outside_paid',
aggregate_by = c('wk', 'OccEdRecode'))
```
## Figure S7
Changes in paid work outside the home by occupation. Percent of all survey respondents in each occupation category that reported working outside of the home for pay in January and June, weighted to account for survey design. Respondents missing occupation designations are excluded. Occupations with fewer than 100,000 respondents are grouped in “Other”.
```{r figS7, fig.width=6, fig.height=3.5}
# make plot
occ_plot <- occ_mo %>%
filter(!is.na(OccEdRecode),
OccEdRecode != 'Not Employed') %>%
mutate(
OccEdRecode=factor(OccEdRecode,
levels = c('Office and admin support', 'K12Teacher',
'Food service', 'Healthcare', 'Sales',
'OtherEductation', 'Other')),
OccEdRecode=recode(OccEdRecode,
'Office and admin support'='Office/admin support',
'K12Teacher'='K-12 teacher',
'OtherEductation'='Other education')) %>%
filter(month %in% c(1, 6)) %>%
ggplot(aes(x = OccEdRecode, y = mean*100, fill = as.factor(month))) +
geom_bar(stat = 'identity', position = position_dodge(), width=0.8) +
labs(y = 'Work outside home (%)', x = NULL) +
theme_bw()+
scale_fill_manual(values = c('#A6611A', '#80CDC1'),
name = NULL, labels = c('January', 'June'))+
theme(axis.text.x = element_text( angle = 45, hjust=1),
legend.background = element_blank())
occ_plot
```
```{r outside-work-setup-models}
# exclude food service because less than 5% of respondents report working exclusively at home
df_ws <- df_ws%>%
filter(OccEdRecode!='Food service')
# set time periods
time_periods <- list(c('jan_feb', 'mar_apr', 'may_jun'),
'jan_feb',
'mar_apr',
'may_jun')
# running models for each outcome with occupation exposure
# adjusted, with interactions b/w occupation and work outside home
# or vaccination status and work outside home
for (t in time_periods) {
message(t)
for (i in 1:length(outcomes)) {
message(i)
f_lst <- NULL
##overall pop, adjusted, interaction with occupation
f_lst <- bind_rows(f_lst,c(
f=sprintf("%s~OccEdRecode+
OccEdRecode:work_outside_paid+
rel_avg_biwk_AR+
IsMale+Age+
Educational_Level+HH_sz+
Population+
White+
GINI+
Poverty+
Description+
mask_level+trav_out_state+
bar_rest_cafe_activ +
large_event_activ+
pub_transit_activ+
any_vaccine",outcomes[i]),
adjusted=TRUE,
interaction=TRUE,
subset=FALSE))
##subset to just teachers, adjusted, interaction with vaccination
f_lst <- bind_rows(f_lst,c(
f=sprintf("%s~any_vaccine+
any_vaccine:work_outside_paid+
rel_avg_biwk_AR+
IsMale+Age+
Educational_Level+HH_sz+
Population+
White+
GINI+
Poverty+
Description+
mask_level+trav_out_state+
bar_rest_cafe_activ +
large_event_activ+
pub_transit_activ",outcomes[i]),
adjusted=TRUE,
interaction=TRUE,
subset=TRUE))
# loop over models to run
for(j in 1:nrow(f_lst)) {
reg <- survey_reg(df_ws%>%
filter(if (f_lst$subset[j]==TRUE) {
# subset to just respondents who are K-12 teachers
# as well as period for analysis
OccEdRecode == 'K12Teacher' & period %in% t
} else {
# otherwise, include all data within the period for analysis
period %in% t
}),
formula(f_lst$f[j]))
# run regressions set up above
occ_reg_tbl <- gtsummary::tbl_regression(reg)$table_body%>%
# save regression results with informative labels
mutate(adjusted=f_lst$adjusted[j],
interaction=f_lst$interaction[j],
subset=f_lst$subset[j],
outcome=outcome_nms[i],
period=ifelse(length(t)>1, 'Jan-Jun',
ifelse(t=='jan_feb', 'Jan-Feb',
ifelse(t=='mar_apr', 'Mar-Apr', 'May-Jun'))))%>%
bind_rows(occ_reg_tbl)
}
}
}
```
## Figure 9
Risk by occupation and paid work outside the home. Odds ratio of COVID-19-related outcomes, contrasting office workers not reporting extra-household work for pay to those in other employment categories not reporting work for pay outside the home (top row), and to those reporting work for pay outside the home (bottom row). The middle row shows the odds ratio (i.e., increased risk) within each category associated with working outside the home compared to no work outside the home. Food service workers are excluded from this analysis because less than 5% reported working exclusively from home (Fig. S7). Results are shown across the study period from Jan. 12 to Jun. 12.
```{r figS8-fig9-outside-work}
# periods to plot
plot_periods <- list(
c('Jan-Feb', 'Mar-Apr', 'May-Jun'),
c('Jan-Jun')
)
for (p in plot_periods) {
occ_reg_tbl_9 <- occ_reg_tbl%>%
filter(subset == FALSE) %>%
mutate(main_term = ifelse(var_type=="interaction",
str_extract(label,"(.+)(?= \\*)" ),
label))
# reformatting object for plotting
tmp <- occ_reg_tbl_9 %>%
mutate(adjusted=adjusted=="TRUE",interaction=interaction=="TRUE")%>%
filter(adjusted,interaction,
str_detect(variable,"OccEdRecode"),
label!="OccEdRecode",
label!="Office and admin support",
row_type!="label")%>%
select(period, label, main_term, estimate,
std.error,
outcome, adjusted, interaction)%>%
group_by(period, main_term, outcome)%>%
summarize(estimate=sum(estimate),
std.error=sqrt(sum(std.error^2)))%>%
ungroup()%>%mutate(inter_term="outside work*baseline")
tmp <- occ_reg_tbl_9 %>%
mutate(adjusted=adjusted=="TRUE",interaction=interaction=="TRUE")%>%
filter(adjusted,interaction,
str_detect(variable,"OccEdRecode"),
label!="OccEdRecode",
label!="Office and admin support",
row_type!="label")%>%
filter(var_type=="interaction")%>%
select(period, main_term, estimate,
std.error,outcome)%>%
mutate(inter_term="outside work")%>%
bind_rows(tmp)
tmp <- occ_reg_tbl_9 %>%
mutate(adjusted=adjusted=="TRUE",interaction=interaction=="TRUE")%>%
filter(adjusted,interaction,
str_detect(variable,"OccEdRecode"),
label!="OccEdRecode",
label!="Office and admin support",
row_type!="label")%>%
filter(var_type=="categorical")%>%
select(period, main_term, estimate,
std.error,outcome)%>%
mutate(inter_term="baseline")%>%
bind_rows(tmp)
overall_interact_plt <-tmp %>%
filter(period %in% p) %>%
mutate(main_term=factor(main_term,
levels = c('Office and admin support', 'K12Teacher',
'Food service', 'Healthcare', 'Sales',
'OtherEductation', 'Other')),
main_term=recode(main_term,
'Office and admin support'='Office/admin support',
'K12Teacher'='K-12 teacher',
'OtherEductation'='Other education'),
outcome=recode(outcome,
'Test+'='Overall Test+'))%>%
mutate(conf.low=exp(estimate-1.96*std.error),
conf.high=exp(estimate+1.96*std.error),
estimate=exp(estimate))%>%
ggplot(aes(x=main_term, y=estimate, ymin=conf.low, ymax=conf.high,
color=outcome))+
geom_pointrange(position=position_dodge(width=.5))+
scale_y_log10()+
scale_color_brewer(type="qual", palette = "Dark2", name=NULL)+
theme_bw()+
theme(legend.position="bottom",
axis.text.x = element_text( angle = 45, hjust=1))+
geom_hline(yintercept=1) +
labs(x=NULL, y='Odds ratio')
if (length(p)>1) {
overall_interact_plt1 <- overall_interact_plt +
facet_grid(rows=vars(inter_term),
cols=vars(period),
scales="free_y")
} else {
overall_interact_plt2 <- overall_interact_plt +
facet_grid(rows=vars(inter_term),
scales="free_y")
}
}
```
```{r fig9, fig.width=4.5, fig.height=6}
overall_interact_plt2
```
## Figure S8
Risk by occupation and paid work outside the home. Odds ratio of COVID-19-related outcomes, contrasting office workers not reporting extra-household work for pay to those in other employment categories not reporting work for pay outside the home (top row), and to those reporting work for pay outside the home (bottom row). The middle row shows the odds ratio (i.e., increased risk) within each category associated with working outside the home compared to no work outside the home. Food service workers are excluded from this analysis because less than 5% reported working exclusively from home (Fig. S7). Results are shown stratified by time periods Jan. 12 to Feb. 28 (Jan-Feb), Mar. 1 to Apr. 30 (Mar-Apr), and May 1 to Jun. 12 (May-Jun)).
```{r figS8, fig.width=8, fig.height=8}
overall_interact_plt1
```
## Figure S9
COVID-19 risk among K-12 Teachers by vaccination status and paid work outside the home. Odds ratio of COVID-19-related outcomes, contrasting unvaccinated K-12 Teachers not reporting extra-household work for pay to vaccinated (any doses) K-12 teachers not reporting work for pay outside the home (top), and to those reporting work for pay outside the home (bottom). The middle row shows the odds ratio (i.e., increased risk) within each vaccination category associated with working outside the home compared to no work outside the home.
```{r figS9, fig.width=4, fig.height=5.5}
# periods to plot
plot_periods <- list(
c('Jan-Jun')
)
for (p in plot_periods) {
occ_reg_tbl_S9 <- occ_reg_tbl%>%
filter(subset == TRUE) %>%
mutate(main_term = ifelse(var_type=="interaction",
str_extract(label,"(.+)(?= \\*)" ),
label))
# reformatting object for plotting
tmp <- occ_reg_tbl_S9 %>%
mutate(adjusted=adjusted=="TRUE",interaction=interaction=="TRUE")%>%
filter(adjusted,interaction,
str_detect(variable,"any_vaccine"),
label!="any_vaccine",
row_type!="label")%>%
select(period, label, main_term, estimate,
std.error,
outcome, adjusted, interaction)%>%
group_by(period, main_term, outcome)%>%
summarize(estimate=sum(estimate),
std.error=sqrt(sum(std.error^2)))%>%
ungroup()%>%mutate(inter_term="outside work*baseline")
tmp <- occ_reg_tbl_S9 %>%
mutate(adjusted=adjusted=="TRUE",interaction=interaction=="TRUE")%>%
filter(adjusted,interaction,
str_detect(variable,"any_vaccine"),
label!="any_vaccine",
row_type!="label")%>%
filter(var_type=="interaction")%>%
select(period, main_term, estimate,
std.error,outcome)%>%
mutate(inter_term="outside work")%>%
bind_rows(tmp)
tmp <- occ_reg_tbl_S9 %>%
mutate(adjusted=adjusted=="TRUE",interaction=interaction=="TRUE")%>%
filter(adjusted,interaction,
str_detect(variable,"any_vaccine"),
label!="any_vaccine",
row_type!="label")%>%
filter(var_type=="categorical")%>%
select(period, main_term, estimate,
std.error,outcome)%>%
mutate(inter_term="baseline")%>%
bind_rows(tmp)
overall_interact_plt <-tmp %>%
filter(period %in% p) %>%
mutate(main_term=ifelse(main_term=='NA', 'any_vaccineFALSE', main_term),
main_term=factor(main_term,
levels = c('any_vaccineFALSE',
'any_vaccineTRUE')),
main_term=recode(main_term,
'any_vaccineFALSE'='Unvaccinated',
'any_vaccineTRUE'='Vaccinated'),
outcome=recode(outcome,
'Test+'='Overall Test+'))%>%
mutate(conf.low=exp(estimate-1.96*std.error),
conf.high=exp(estimate+1.96*std.error),
estimate=exp(estimate))%>%
ggplot(aes(x=main_term, y=estimate, ymin=conf.low, ymax=conf.high,
color=outcome))+
geom_pointrange(position=position_dodge(width=.5))+
scale_y_log10()+
scale_color_brewer(type="qual", palette = "Dark2", name=NULL)+
theme_bw()+
theme(legend.position="bottom")+
geom_hline(yintercept=1) +
labs(x=NULL, y='Odds ratio')
overall_interact_plt <- overall_interact_plt +
facet_grid(rows=vars(inter_term),
cols=vars(period),
scales="free_y")
}
overall_interact_plt
```
## Table S8
Relative odds of COVID-19-related outcomes among respondents who did, and did not, report any paid work outside the home during different time periods compared to office and administrative staff not working outside of the home for pay.
```{r tableS8}
# prep to make table
occ_reg_tbl_9 <- occ_reg_tbl_9 %>%
filter(subset == FALSE,
str_detect(variable,"OccEdRecode"))
# make pretty table
occ_reg_disp_tbl <- reg_tbl_period_wrangle(occ_reg_tbl_9, 'Occupation')
# print result
occ_reg_disp_tbl
# save
gt::gtsave(occ_reg_disp_tbl, paste0('tables/tableS8.html'))
```
## Table S9
Relative odds of COVID-19-related outcomes among K-12 teachers who were vaccinated with any number of COVID-19 vaccine doses and who did, or did not, report any paid work outside the home during different time periods compared to K-12 teachers who were unvaccinated and not working outside of the home for pay.
```{r tableS9}
# prep to make table
occ_reg_tbl_S9 <- occ_reg_tbl_S9 %>%
filter(subset == TRUE,
str_detect(variable,"any_vaccine")) %>%
mutate(label = ifelse(term == 'any_vaccineFALSE:work_outside_paidTRUE',
'unvaccinated * NA', label),
label = gsub('any_vaccineTRUE', 'vaccinated', label))
# make pretty table
occ_reg_disp_tbl <- reg_tbl_period_wrangle(occ_reg_tbl_S9, 'Vaccine status')
# print result
occ_reg_disp_tbl
# save
gt::gtsave(occ_reg_disp_tbl, paste0('tables/tableS9.html'))
```