-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis.rmd
414 lines (297 loc) · 11.9 KB
/
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
---
title: "covid_analysis"
output: html_document
date: "2023-09-20"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(tidyverse)
library(lubridate)
library(dplyr)
install.packages("writexl")
library(writexl)
library(ggplot2)
library(janitor)
library(readxl)
#install.packages("plyr")
library(plyr)
```
# victoria adding in and cleaning new covid historic data 9-20-2022 - 9-05-2023
# hic checked
```{r}
# read in covid positive report data 9-20-2022 - 9-05-2023
data23 <- read_csv('newdatarightformat.csv')
#get rid of totals rows for each year
data23 <- data23[-c(1,105,293),]
# clean names and create 1 column for role type instead of having 1 column for each different role
data23 <- data23 %>%
clean_names() %>%
pivot_longer(cols = c(contains('faculty'), contains('staff'), contains('student')))
# rename the columns to match what the old dataframe below has
colnames(data23) <- c('date','drop','role','count')
# make the dates consistent with the old datas format
data23$date <- as.Date(parse_date_time(data23$date, "mdy"))
# select only the columns I need, we don't need the column that has the totals for each day
data23 <- data23 %>%
select(role, date, count)
# make all the NAs
data23[is.na(data23)] <- 0
```
# this is Devon's old code, I have commented where I adjusted it
```{r}
# this is all devon adding in the dataframe we had last year, adjusting column names, getting rid of nas
data <- read_csv('data930.csv')
colnames(data) <- c('drop','type','role','date','count')
data <- data%>%
drop_na(drop)
data <- subset(data, select = -c(drop))
#victoria 9/21/2023 also dropping type column from the old data to match our current data
data <- subset(data, select = -c(type))
# this was devon, just adjustng the date
data$date <- as.Date(parse_date_time(data$date, "dmy"))
#victoria 9/21/2023 making all nas equal to zero in old data
data[is.na(data)] <- 0
```
#victoria 9/21/2023 joining the dataframe 'data' and the dataframe 'data23' to create a dataframe for total historic recorded positive covid cases
```{r}
# joining the two dataframes
historic_data <- rbind(data, data23) %>%
# removing the role column because we really just want the totals
select(-c(role))
# now I'm summing the case count for each date
historic_data <- aggregate(.~date,data=historic_data,FUN=sum)
#historic_data <- historic_data %>%
# mutate(sum = rowSums(across(where(is.numeric)), na.rm=TRUE))
# hic gut check:
# 12 on june 1, 2021 in 'historic_data'
# 12 on june 1, 2021 in 'data'
# 10 on june 1, 2023 in 'historic_data'
# 10 on june 1, 2023 in 'data'
# and then I'm writing it out to this file
write_xlsx(historic_data, "newcasedata.xlsx")
```
# Victoria - now I'm using the new complete dataframe to see how many cases were in the same time period (first 9 days of the semester) this year compared to last year
# hic checked
```{r}
v_fall2022 <- historic_data[historic_data$date >= "2022-08-29" & historic_data$date <= "2022-09-06",]
v_fall2023 <- historic_data[historic_data$date >= "2023-08-28" & historic_data$date <= "2023-09-05",]
sum(v_fall2022$count)
sum(v_fall2023$count)
# This is the end of victoria stuff
```
```{r}
#create dfs by semester
fall2020 <- historic_data[historic_data$date >= "2020-08-30" & historic_data$date <= "2020-12-22", ]
spring2021 <- historic_data[historic_data$date >= "2021-01-25" & historic_data$date <= "2021-05-19", ]
fall2021 <- historic_data[historic_data$date >= "2021-08-30" & historic_data$date <= "2021-12-22", ]
spring2022 <- historic_data[historic_data$date >= "2022-01-24" & historic_data$date <= "2022-05-18", ]
fall2022 <- historic_data[historic_data$date >= "2022-08-29",]
#devon semesters - adjust start date for fall 2020, end date for fall 2021 -- USE THIS FOR TOTAL SEM COUNT
d_fall2020 <- historic_data[historic_data$date >= "2020-08-31" & historic_data$date <= "2020-12-22", ]
d_spring2021 <- historic_data[historic_data$date >= "2021-01-25" & historic_data$date <= "2021-05-19", ]
d_fall2021 <- historic_data[historic_data$date >= "2021-08-30" & historic_data$date <= "2021-12-21", ]
d_spring2022 <- historic_data[historic_data$date >= "2022-01-24" & historic_data$date <= "2022-05-18", ]
d_fall2022 <- historic_data[historic_data$date >= "2022-08-29" & historic_data$date <= "",]
```
```{r}
sum(fall2020$count)
sum(spring2021$count)
sum(fall2021$count)
sum(spring2022$count)
sum(fall2022$count)
#devon sums with new adjusted semesters -- USE THIS FOR TOTAL SEM COUNT
sum(d_fall2020$count)
sum(d_spring2021$count)
sum(d_fall2021$count)
sum(d_spring2022$count)
sum(d_fall2022$count)
```
#3 dont use this block
```{r}
shortfall2020 <- historic_data[historic_data$date >= "2020-08-30" & historic_data$date <= "2020-09-21", ]
shortspring2021 <- historic_data[historic_data$date >= "2021-01-25" & historic_data$date <= "2021-02-10", ] #why is this shorter? - devon
shortfall2021 <- historic_data[historic_data$date >= "2021-08-30" & historic_data$date <= "2021-09-21", ]
shortspring2022 <- historic_data[historic_data$date >= "2022-01-24" & historic_data$date <= "2022-02-11", ] #why is this shorter? - devon
fall2022 <- historic_data[historic_data$date >= "2022-08-29",]
#devon short sems adjusting fall 2020 start, spring 2021 end, fall 2021 end, spring 2022 end
d_shortfall2020 <- historic_data[historic_data$date >= "2020-08-31" & historic_data$date <= "2020-09-21", ]
d_shortspring2021 <- historic_data[historic_data$date >= "2021-01-25" & historic_data$date <= "2021-02-15", ]
d_shortfall2021 <- historic_data[historic_data$date >= "2021-08-30" & historic_data$date <= "2021-09-20", ]
d_shortspring2022 <- historic_data[historic_data$date >= "2022-01-24" & historic_data$date <= "2022-02-14", ]
d_fall2022 <- historic_data[historic_data$date >= "2022-08-29",]
```
## good block
```{r}
#again, again with new historic_data --> 32 day periods -- USE THIS FOR 32-DAY PERIODS
newshortfall2020 <- historic_data[historic_data$date >= "2020-08-31" & historic_data$date <= "2020-10-02", ]
newshortspring2021 <- historic_data[historic_data$date >= "2021-01-25" & historic_data$date <= "2021-02-26", ]
newshortfall2021 <- historic_data[historic_data$date >= "2021-08-30" & historic_data$date <= "2021-10-01", ]
newshortspring2022 <- historic_data[historic_data$date >= "2022-01-24" & historic_data$date <= "2022-02-25", ]
newfall2022 <- historic_data[historic_data$date >= "2022-08-29",]
#devon 30 day periods - USE THIS FOR 30-day periods
d_newshortfall2020 <- historic_data[historic_data$date >= "2020-08-31" & historic_data$date <= "2020-09-30", ]
d_newshortspring2021 <- historic_data[historic_data$date >= "2021-01-25" & historic_data$date <= "2021-02-24", ]
d_newshortfall2021 <- historic_data[historic_data$date >= "2021-08-30" & historic_data$date <= "2021-09-29", ]
d_newshortspring2022 <- historic_data[historic_data$date >= "2022-01-24" & historic_data$date <= "2022-02-23", ]
d_newthirtyfall2022 <- historic_data[historic_data$date >= "2022-08-29" & historic_data$date <= "2022-09-28",]
d_newfall2022 <- historic_data[historic_data$date >= "2022-08-29",] #32 days in this one
d_newfall2023 <- historic_data[historic_data$date >= "2023-8-28",]
d_tryfall2022 <- historic_data[historic_data$date >= "2022-8-28" & historic_data$date <= "2022-09-05",]
```
```{r}
#ignore this
sum(newshortfall2020$count)
sum(newshortspring2021$count)
sum(newshortfall2021$count)
sum(newshortspring2022$count)
sum(newfall2022$count)
#devon sums with adjusted semesters -- ignore this
sum(d_shortfall2020$count)
sum(d_shortspring2021$count)
sum(d_shortfall2021$count)
sum(d_shortspring2022$count)
sum(d_fall2022$count)
#rina sums with new time periods -- USE THIS FOR 32-DAY COUNTS
sum(newshortfall2020$count)
sum(newshortspring2021$count)
sum(newshortfall2021$count)
sum(newshortspring2022$count)
sum(newfall2022$count)
#devon sums with 30-day periods -- USE THIS FOR 30-DAY COUNTS
sum(d_newshortfall2020$count)
sum(d_newshortspring2021$count)
sum(d_newshortfall2021$count)
sum(d_newshortspring2022$count)
sum(d_newthirtyfall2022$count)
sum(d_newfall2022$count)
sum(d_newfall2023$count)
sum(d_tryfall2022$count)
```
```{r}
historic_databydate <- historic_data %>% group_by(date)
historic_databydate <- subset(historic_databydate, select = -c(role))
newshortfall2020sr <-
newshortfall2020%>%
filter(type == "Self Reported")
newshortspring2021sr <-
newshortspring2021%>%
filter(type == "Self Reported")
newshortfall2021sr <-
newshortfall2021%>%
filter(type == "Self Reported")
newshortspring2022sr <-
newshortspring2022%>%
filter(type == "Self Reported")
newfall2022sr <-
newfall2022%>%
filter(type == "Self Reported")
```
```{r}
sum(newshortfall2020sr$count)
sum(newshortspring2021sr$count)
sum(newshortfall2021sr$count)
sum(newshortspring2022sr$count)
sum(newfall2022sr$count)
```
```{r}
sum(fall2020sr$count)
sum(spring2021sr$count)
sum(fall2021sr$count)
sum(spring2022sr$count)
sum(fall2022sr$count)
```
```{r}
newshortfall2020u <-
newshortfall2020%>%
filter(type =="UHC Reported")
shortspring2021u <-
shortspring2021%>%
filter(type == "UHC Reported")
shortfall2021u <-
shortfall2021%>%
filter(type == "UHC Reported")
shortspring2022u <-
shortspring2022%>%
filter(type == "UHC Reported")
fall2022u <-
fall2022%>%
filter(type == "UHC Reported")
```
```{r}
sum(fall2020u$count)
sum(spring2021u$count)
sum(fall2021u$count)
sum(spring2022u$count)
sum(fall2022u$count)
```
```{r}
sum(fall2020u$count) + sum(fall2020sr$count)
sum(shortspring2021u$count) + sum(shortspring2021sr$count)
sum(shortfall2021u$count)+sum(shortfall2021sr$count)
sum(shortspring2022u$count)+sum(shortspring2022sr$count)
sum(fall2022u$count)+sum(fall2022sr$count)
```
Pivoting, binding, and cleaning historic_data here -- Shreya --- old and irrelevant :wave:
```{r}
#load in historic_data
historic_data <- read_csv('historic_data.csv') %>%
clean_names() %>%
rename(
date = positive_test_result_date
) %>%
drop_na(question_from_laura) #%>%
# mutate(
# number_of_cases = as.double(number_of_cases)
# )
#clean date
historic_data$date <- as.Date(parse_date_time(historic_data$date, "dmy"))
historic_data$year <- as.numeric(format(historic_data$date, "%Y"))
clean_historic_historic_data <- historic_data %>%
pivot_wider(names_from=primary_role, values_from=number_of_cases, values_fn = length, values_fill = 0) %>%
clean_names() %>%
mutate(
student = as.character(student)
)
#mutate(across(student:faculty, ~replace(., lengths(.) == 0, NA)))
#export to excel because efficiency and I don't know how
write_xlsx(clean_historic_historic_data, "clean_historic_historic_data.xlsx")
self_reports_clean <- clean_historic_historic_data %>%
filter(self_reported_or_uhc_reported == "Self Reported")
# test
fall2020 <- clean_historic_historic_data[clean_historic_historic_data$date >= "2020-08-30" & clean_historic_historic_data$date <= "2020-12-22", ]
self_reports_clean[is.null(self_reports_clean)] = 0
uhc_reports_clean <- clean_historic_historic_data %>%
filter(self_reported_or_uhc_reported == "UHC Reported")
```
Joining the important policy dates to cases -- Shreya
```{r}
#load in historic_data
new_historic_data <- read_xlsx("latest_9_30_covid_historic_data.xlsx") %>%
clean_names() %>%
rename(
date = positive_test_result_date
)
### policy dates
historic_dates <- read_csv("historical_covid_dates.csv") %>%
select(dates, what_happened) %>%
rename(
date = dates
)
##pivoted historic_data
join_dates_and_cases <- new_historic_data %>%
left_join(historic_dates, by=c("date")) %>%
pivot_wider(names_from=primary_role, values_from=no_of_cases) %>%
clean_names()
##wider for fun
wide_join_dates_and_cases <- new_historic_data %>%
left_join(historic_dates, by=c("date")) %>%
select(-diamondback_request) %>%
group_by(reporting_type) %>%
pivot_wider(names_from=c("primary_role", "reporting_type"), values_from=no_of_cases) %>%
clean_names() %>%
mutate_at(c(3:8), ~replace_na(.,0))
write_xlsx(join_dates_and_cases, "join_dates_and_cases.xlsx")
write_xlsx(wide_join_dates_and_cases, "wide_join_dates_and_cases.xlsx")
```