-
Notifications
You must be signed in to change notification settings - Fork 1
/
milwaukee.Rmd
322 lines (291 loc) · 9.66 KB
/
milwaukee.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
---
title: "Cases and Wastewater"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, error = FALSE, message = FALSE)
```
```{r}
library(tidyverse)
library(RcppRoll)
library(lubridate)
library(patchwork)
```
```{r}
abbrev_site <- function(x) {
x <- str_remove(x, " W[WP].*")
x <- str_remove(x, " MSD")
x <- str_remove(x, " Water &")
x <- str_remove(x, " Wastewater Utility")
abbreviate(x, 10)
}
```
```{r}
caseww <- full_join(
read_csv("data/wastewater/uwm_ww_data_20210507.csv") %>%
select(wwtp_name, sample_collect_date, capacity_mgd,
n1_sars_cov2_conc, n2_sars_cov2_conc,
ppmov_conc, hf183_conc, bcov_rec_rate,
average_flow_rate, equiv_sewage_amt) %>%
rename(Date = "sample_collect_date",
Site = "wwtp_name"),
read_csv("data/wastewater/uwm_case_data_20210507.csv") %>%
rename(Date = "SpecCollectedDate",
Site = "DISPLAY_NA"),
by = c("Site", "Date")) %>%
mutate(Site = abbrev_site(Site),
Day = factor(weekdays(Date), c("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")),
# Week 53 is the last week of the year bleeding into the next year
Week = epiweek(Date) + 53 * (2021 == year(Date) & epiweek(Date) < 53),
Week = Week + 1 - min(Week)) %>%
arrange(Site, Date)
```
```{r}
ww <- caseww %>%
filter(!is.na(n1_sars_cov2_conc))
case <- caseww %>%
filter(!is.na(cases))
```
```{r}
rollo <- function(x, n = 7) {
nn <- min(length(x), n)
x <- roll_sum(x, nn, na.rm = TRUE)
if(nn > 1) {
x <- c(rep(x[1], nn - 1), x)
}
x
}
```
Note that wastewater samples are on different days in different sites, and sometimes more than once in a week. Cases are measured most days, somewhat less on Sundays. It is difficult with this distribution of wastewater measurements to determine lead or lag in signal relative to cases.
```{r}
ggplot(ww) +
aes(Day) +
geom_bar() +
facet_wrap(~ Site) +
theme(axis.text.x = element_text(angle = 45)) +
ggtitle("Weekday of Wastewater Sample Collection")
```
```{r}
ggplot(ww) +
aes(Week, Day) +
geom_jitter(width = 0, height = 0.1, alpha = 0.5) +
facet_wrap(~ Site) +
ggtitle("Week and Day of Wastewater Sample Collection")
```
```{r}
ggplot(case) +
aes(Day) +
geom_bar() +
facet_wrap(~ Site) +
theme(axis.text.x = element_text(angle = 45)) +
ggtitle("Weekday of Cases")
```
```{r}
ggplot(case) +
aes(Week, Day) +
geom_jitter(width = 0, height = 0.1, alpha = 0.5) +
facet_wrap(~ Site) +
ggtitle("Week and Day of Cases")
```
```{r}
ggplot(ww) +
aes(Week,
n1_sars_cov2_conc) +
scale_y_log10() +
geom_line() +
facet_grid(Site ~ Day) +
theme(strip.text.y = element_text(angle = 0)) +
ggtitle("N1 by Week and Day")
```
```{r}
ggplot(ww) +
aes(Date,
rollo(n1_sars_cov2_conc)) +
scale_y_log10() +
geom_line() +
facet_wrap(~ Site) +
ggtitle("N1 Rolling Mean by Date")
```
```{r}
ggplot(case) +
aes(Week,
cases) +
geom_line() +
facet_grid(Site ~ Day, scales = "free_y") +
theme(strip.text.y = element_text(angle = 0)) +
ggtitle("Cases by Week and Day")
```
```{r}
ggplot(case) +
aes(Week,
rollo(cases, 7)) +
geom_line() +
facet_grid(Site ~ Day, scales = "free_y") +
theme(strip.text.y = element_text(angle = 0)) +
ylab("Cases Rolling Week Mean") +
ggtitle("Rolling Mean of Cases by Week and Day")
```
```{r}
ggplot(case) +
aes(Date,
rollo(cases)) +
geom_line() +
facet_wrap(~ Site, scales = "free_y") +
ylab("Cases Rolling Week Mean") +
ggtitle("Rolling Mean of Cases by Date")
```
## Burlington
Brief look at one site. Note similarity of N1 and N2, odd point for PPMoV, and disparate trend for BCoV.
```{r}
burl <- caseww %>%
filter(Site == "Burlington") %>%
select(Week, cases, n1_sars_cov2_conc:bcov_rec_rate) %>%
group_by(Week) %>%
summarize(across(everything(), sum, na.rm = TRUE)) %>%
mutate(across(everything(), function(x) ifelse(x == 0, NA, x)))
```
```{r}
ggplot(
burl %>%
pivot_longer(cases:bcov_rec_rate,
names_to = "meas", values_to = "values") %>%
mutate(meas = factor(meas,
c("cases", "n1_sars_cov2_conc", "n2_sars_cov2_conc",
"ppmov_conc", "bcov_rec_rate", "hf183_conc")))) +
aes(Week, values) +
geom_path() +
geom_point() +
facet_wrap(~ meas, scales = "free_y") +
ggtitle("Burlington")
```
```{r}
coeff <- 1000
ggplot(burl) +
aes(Week) +
geom_path(aes(y = n1_sars_cov2_conc / coeff), col = "red") +
geom_point(aes(y = n1_sars_cov2_conc / coeff), col = "red") +
geom_path(aes(y = cases), col = "blue") +
geom_point(aes(y = cases), col = "blue") +
scale_y_continuous(name = "Cases",
# trans = "log10",
sec.axis = sec_axis(~.*coeff, name = "N1")) +
theme(
axis.title.y = element_text(color = "blue"),
axis.title.y.right = element_text(color = "red")
) +
ggtitle("Burlington: Weekly Cases and N1")
```
```{r}
coeff <- 1000
ggplot(caseww %>%
filter(Site == "Burlington")) +
aes(Date) +
geom_path(aes(y = rollo(n1_sars_cov2_conc / coeff)), col = "red") +
geom_point(aes(y = rollo(n1_sars_cov2_conc / coeff)), col = "red") +
geom_path(aes(y = rollo(cases)), col = "blue") +
geom_point(aes(y = rollo(cases)), col = "blue") +
scale_y_continuous(name = "Cases",
# trans = "log10",
sec.axis = sec_axis(~.*coeff, name = "N1")) +
theme(
axis.title.y = element_text(color = "blue"),
axis.title.y.right = element_text(color = "red")
) +
ggtitle("Burlington: Rolling Week Sum of Cases and N1")
```
## All Sites by Week
In these plots, N1 is rescaled to 1000 times the cases, which works for some less populated areas, but not for Milwaukee, Green Bay or Racine. Not that there is not a consistent scaling, which might reflect population differences as well as other characteristics of the samples in different locations.
```{r fig.width = 7, fig.height = 10}
coeff <- 1000
ggplot(caseww %>%
select(Site, Week, cases, n1_sars_cov2_conc:bcov_rec_rate) %>%
group_by(Site, Week) %>%
summarize(across(everything(), sum, na.rm = TRUE)) %>%
mutate(across(everything(), function(x) ifelse(x == 0, NA, x)))) +
aes(Week) +
geom_path(aes(y = n1_sars_cov2_conc / coeff), col = "red") +
geom_point(aes(y = n1_sars_cov2_conc / coeff), col = "red") +
geom_path(aes(y = cases), col = "blue") +
geom_point(aes(y = cases), col = "blue") +
scale_y_continuous(name = "Cases",
# trans = "log10",
sec.axis = sec_axis(~.*coeff, name = "N1")) +
facet_wrap(~ Site, ncol = 3, scales = "free_y") +
theme(
axis.title.y = element_text(color = "blue"),
axis.title.y.right = element_text(color = "red")
) +
ggtitle("All Sites: Weekly Cases and N1")
```
```{r fig.width = 7, fig.height = 10}
coeff <- 1000
ggplot(caseww %>%
select(Site, Date, cases, n1_sars_cov2_conc:bcov_rec_rate) %>%
arrange(Site, Date)) +
aes(Date) +
geom_path(aes(y = rollo(n1_sars_cov2_conc / coeff)), col = "red") +
geom_point(aes(y = rollo(n1_sars_cov2_conc / coeff)), col = "red") +
geom_path(aes(y = rollo(cases)), col = "blue") +
geom_point(aes(y = rollo(cases)), col = "blue") +
scale_y_continuous(name = "Cases",
# trans = "log10",
sec.axis = sec_axis(~.*coeff, name = "N1")) +
facet_wrap(~ Site, ncol = 3, scales = "free_y") +
theme(
axis.title.y = element_text(color = "blue"),
axis.title.y.right = element_text(color = "red")
) +
ggtitle("All Sites: Rolling Week Sum of Cases and N1")
```
## All Sites by Week Rescaled
These plots allow one to focus on the shape of the curves, and the time of the maxima. If N1 were a consistent lead indicator of cases, then the red peak should generally be to the left of the blue peak, which it is not.
```{r fig.width = 7, fig.height = 10}
coeff <- 1
ggplot(
caseww %>%
select(Site, Week, cases, n1_sars_cov2_conc:bcov_rec_rate) %>%
group_by(Site, Week) %>%
summarize(across(everything(), sum, na.rm = TRUE)) %>%
mutate(across(everything(), function(x) ifelse(x == 0, NA, x))) %>%
group_by(Site) %>%
mutate(across(everything(), function(x) x / max(x, na.rm = TRUE)))) +
aes(Week) +
geom_path(aes(y = n1_sars_cov2_conc / coeff), col = "red") +
geom_point(aes(y = n1_sars_cov2_conc / coeff), col = "red") +
geom_path(aes(y = cases), col = "blue") +
geom_point(aes(y = cases), col = "blue") +
scale_y_continuous(name = "Cases",
# trans = "log10",
sec.axis = sec_axis(~.*coeff,
labels = NULL, name = "N1")) +
facet_wrap(~ Site, ncol = 3, scales = "free_y") +
theme(
axis.title.y = element_text(color = "blue"),
axis.title.y.right = element_text(color = "red")
) +
ggtitle("All Sites: Weekly Cases and N1")
```
```{r fig.width = 7, fig.height = 10}
coeff <- 1
ggplot(caseww %>%
select(Site, Date, cases, n1_sars_cov2_conc:bcov_rec_rate) %>%
arrange(Site, Date) %>%
group_by(Site) %>%
mutate(across(-Date, rollo),
across(-Date, function(x) x / max(x, na.rm = TRUE)))) +
aes(Date) +
geom_path(aes(y = n1_sars_cov2_conc), col = "red") +
geom_point(aes(y = n1_sars_cov2_conc), col = "red") +
geom_path(aes(y = cases), col = "blue") +
geom_point(aes(y = cases), col = "blue") +
scale_y_continuous(name = "Cases",
# trans = "log10",
sec.axis = sec_axis(~.*coeff,
labels = NULL, name = "N1")) +
facet_wrap(~ Site, ncol = 3, scales = "free_y") +
theme(
axis.title.y = element_text(color = "blue"),
axis.title.y.right = element_text(color = "red")
) +
ggtitle("All Sites: Rolling Week Sum of Cases and N1")
```