forked from reichlab/covid19-forecast-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2020-09-08-weekly-report.Rmd
408 lines (325 loc) · 19.6 KB
/
2020-09-08-weekly-report.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
---
title: "COVID-19 Forecast Hub weekly report"
author: "Nicholas G Reich, Estee Y Cramer, Martha W Zorn"
date: "report generated 2020-09-08, updated `r Sys.Date()`"
output:
html_document:
toc: true
toc_float:
collapsed: false
smooth_scroll: false
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(lubridate)
library(DT)
library(zoltr) ## devtools::install_github("reichlab/zoltr")
library(scico)
source("../processing-fxns/get_next_saturday.R")
library(tidyverse)
library(htmltools)
theme_set(theme_bw())
```
```{r zoltar-setup}
## connect to Zoltar
zoltar_connection <- new_connection()
zoltar_authenticate(zoltar_connection, Sys.getenv("Z_USERNAME"), Sys.getenv("Z_PASSWORD"))
## construct Zoltar query
project_url <- "https://www.zoltardata.com/api/project/44/"
```
```{r get-date-boundaries}
next_saturday <- get_next_saturday(today())
# # use fixed date
# # use fixed date
next_saturday <- as.Date("2020-09-12")
saturday_4_wk_ahead <- next_saturday + 7*3
saturday_4_wk_ahead_txt <- format(saturday_4_wk_ahead, "%B %d")
last_5_saturdays <- next_saturday - 7*c(5:1)
this_monday <- next_saturday - 5
```
# Background
This report provides a brief summary of the weekly ensemble forecast from the [COVID-19 Forecast Hub](https://covid19forecasthub.org/) based on forecasts submitted on `r format(this_monday, "%B %d, %Y")`. In collaboration with the US CDC, our team aggregates COVID-19 forecasts from dozens of teams around the globe. Typically on Wednesday or Thursday of each week, a summary of the week's forecasts from the COVID-19 Forecast Hub appear on the [official CDC COVID-19 forecasting page](https://www.cdc.gov/coronavirus/2019-ncov/covid-data/forecasting-us.html).
```{r nmodels-this-week}
models_this_week <- zoltr::do_zoltar_query(
zoltar_connection, project_url, TRUE,
targets = c("1 wk ahead cum death", "1 wk ahead inc death", "1 wk ahead inc case", "1 day ahead inc hosp"),
timezeros = as.character(seq.Date(this_monday, this_monday-6, by="-1 day")),
types = c("point"),
verbose = FALSE,
models = c(),
units = c()) %>%
pull(model) %>%
unique()
nmodels_this_week <- length(models_this_week)
```
Every week, teams submit their forecasts to the COVID-19 Forecast Hub.
This past week, `r nmodels_this_week`* models were submitted.
Each Monday evening or Tuesday morning, we combine the most recent forecasts from each team into a single "ensemble" forecast of reported COVID-19 cases at the county, state, and national level and deaths at the state and national level. At the moment, we only generate ensemble forecasts for four weeks into the future, as we don't have reliable evidence that the models are accurate past that horizon.
An archive of weekly reports from the COVID-19 Forecast Hub can be found at [this page](https://covid19forecasthub.org/doc/reports/).
*(updated 9/17/2020 due to error found)
```{r count-models}
## how many models in inc_death ensemble?
inc_death_models <- read_csv(paste0("../../ensemble-metadata/", this_monday, "-inc_death-model-weights.csv")) %>%
select(-locations) %>%
apply(MARGIN = 2, FUN=function(x) sum(x))
n_inc_death_models <- sum(inc_death_models>0)
## how many models in cum_death ensemble?
cum_death_models <- read_csv(paste0("../../ensemble-metadata/", this_monday, "-cum_death-model-weights.csv")) %>%
select(-locations) %>%
apply(MARGIN = 2, FUN=function(x) sum(x))
n_cum_death_models <- sum(cum_death_models>0)
## how many models in inc_case ensemble?
inc_case_models <- read_csv(paste0("../../ensemble-metadata/", this_monday, "-inc_case-model-weights.csv"))%>%
select(-locations) %>%
apply(MARGIN = 2, FUN=function(x) sum(x))
n_inc_case_models <- sum(inc_case_models>0)
n_unique_models <- length(unique(c(names(inc_death_models)[inc_death_models>0],
names(cum_death_models)[cum_death_models>0],
names(inc_case_models)[inc_case_models>0])))
```
```{r aux-data}
## get our FIPS codes
fips_codes <- read_csv("../../data-locations/locations.csv")
## this has populations
locs <- read_csv("https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/UID_ISO_FIPS_LookUp_Table.csv") %>%
mutate(FIPS = ifelse(UID==840, "US", FIPS)) %>%
mutate(state_fips = substr(FIPS, 0, 2)) %>%
right_join(select(fips_codes, -location_name), by=c("state_fips" = "location")) %>%
mutate(loc_name = reorder(factor(Province_State), X=-Population)) %>%
select(FIPS, abbreviation, Population)
```
```{r download-ensemble-data}
inc_death_targets <- paste(1:4, "wk ahead inc death")
cum_death_targets <- paste(1:4, "wk ahead cum death")
# submit query
dat <- zoltr:: do_zoltar_query(
zoltar_connection, project_url, TRUE,
models = c("COVIDhub-ensemble"),
targets = c(inc_death_targets, cum_death_targets),
timezeros = as.character(this_monday),
types = c("point", "quantile"),
units = c(),
verbose = FALSE) %>%
## choose only columns we need and with data
select(model, timezero, unit, target, class, quantile, value) %>%
rename(fips=unit) %>%
## create rate variable and week-ahead
mutate(week_ahead = as.numeric(substr(target, 0,1)),
## recreates the target_end_date from GitHub
target_end_date = get_next_saturday(timezero + 7*(week_ahead-1)))
```
# COVID-19 Mortality Forecasts
## National level
This week, our ensemble combined forecasts from `r n_unique_models` different models.
```{r us-summary}
us_cum_deaths <- dat %>%
filter(fips=="US", target=="4 wk ahead cum death", class=="point") %>%
pull(value) %>%
round(-2) %>%
format(big.mark = ",")
us_inc_death_range <- dat %>%
filter(fips=="US", target %in% inc_death_targets, class=="point") %>%
pull(value) %>% range() %>%
round(-2) %>% format(big.mark = ",")
us_inc_death_wk_pi_round <- dat %>%
filter(fips=="US", target == "4 wk ahead inc death", quantile %in% c(0.025, 0.975)) %>%
pull(value) %>% sort() %>%
round(-2) %>% format(big.mark = ",")
us_inc_death_wk_pi <- dat %>%
filter(fips=="US", target == "4 wk ahead inc death", quantile %in% c(0.025, 0.975)) %>%
pull(value) %>% sort() %>%
format(big.mark = ",")
```
At the national level, the ensemble model's best guess is that we will see between `r us_inc_death_range[1]` and `r us_inc_death_range[2]` deaths each week for the next four weeks with around `r us_cum_deaths` deaths by `r saturday_4_wk_ahead_txt` (Figure 1). For the week ending `r saturday_4_wk_ahead_txt`, the ensemble forecasts that reported COVID-19 deaths in the US will be between `r us_inc_death_wk_pi_round[1]` and `r us_inc_death_wk_pi_round[2]` (95% prediction interval: `r us_inc_death_wk_pi[1]` - `r us_inc_death_wk_pi[2]`).
<!-- Throughought most of July, models have in general shown broad agreement about the trajectory of the outbreak over the coming weeks. However, the recent surge in cases has left models with quite different interpretations about what the next few weeks hold in terms of how many reported deaths from COVID-19 we will see. -->
You can explore the full set of models, including their forecasts for past weeks online at our [interactive forecast visualization](https://viz.covid19forecasthub.org/).
```{r make-US-inc-death-plot, fig.cap="__Figure 1__: Weekly observed and forecasted COVID-19 deaths. Observed data from [JHU CSSE](https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/) and forecasts from the [COVID-19 Forecast Hub](https://covid19forecasthub.org/).", fig.topcaption=TRUE}
quantiles_to_plot <- c(0.025, 0.1, 0.25, 0.75, 0.9, 0.975)
blues <- RColorBrewer::brewer.pal(n=length(quantiles_to_plot)/2+1, "Blues")
inc_death_forecast <- dat %>%
filter(target %in% inc_death_targets)
## get full inc death truth for plotting
inc_death_truth <- read_csv("../../data-truth/truth-Incident Deaths.csv") %>%
rename(target_end_date = date, fips = location) %>%
mutate(model = "observed data (JHU)") %>%
group_by(fips, model) %>% arrange(target_end_date) %>%
mutate(value = RcppRoll::roll_sum(value, 7, align = "right", fill = NA)) %>%
ungroup() %>%
left_join(locs, by=c("fips" = "FIPS")) %>%
filter(target_end_date %in% seq.Date(as.Date("2020-01-25"), to = this_monday, by="1 week"),
fips %in% unique(inc_death_forecast$fips))
inc_death_all_points <- inc_death_truth %>%
bind_rows(filter(inc_death_forecast, class=="point")) %>%
bind_rows(filter(inc_death_truth, target_end_date==last_5_saturdays[5]) %>% mutate(model="COVIDhub-ensemble")) %>%
mutate(model = relevel(factor(model), ref="observed data (JHU)"))
## inc death data for code of uncertainty
dummy_inc_death <- tibble(
quantile = quantiles_to_plot,
target_end_date=last_5_saturdays[5]) %>%
right_join(inc_death_all_points %>%
select(-quantile) %>%
filter(target_end_date == last_5_saturdays[5]))
inc_death_quantiles <- inc_death_forecast %>%
dplyr::filter(class=="quantile") %>%
bind_rows(dummy_inc_death) %>%
dplyr::filter(quantile %in% quantiles_to_plot) %>%
dplyr::mutate(endpoint_type = ifelse(quantile < 0.5, 'lower', 'upper'),
alpha = ifelse(endpoint_type == 'lower',
format(2*quantile, digits=3, nsmall=3),
format(2*(1-quantile), digits=3, nsmall=3)),
`Prediction Interval` = fct_rev(paste0((1-as.numeric(alpha))*100, "%"))
) %>%
dplyr::filter(alpha != "1.000") %>%
dplyr::select(-quantile) %>%
tidyr::pivot_wider(names_from='endpoint_type', values_from='value')
ggplot() +
geom_ribbon(data = inc_death_quantiles %>% dplyr::filter(fips=="US"),
mapping = aes(x = target_end_date,
ymin=lower, ymax=upper,
fill=`Prediction Interval`)) +
geom_line(data=inc_death_all_points %>%
dplyr::filter(fips == "US"),
mapping = aes(x = target_end_date, y = value, color = model)) +
geom_point(data=inc_death_all_points %>%
dplyr::filter(fips == "US", !(model=="COVIDhub-ensemble" & target_end_date <= this_monday)),
mapping = aes(x = target_end_date, y = value, color = model)) +
scale_fill_manual(values = blues[1:(length(blues)-1)]) +
scale_color_manual(values = c("black", tail(blues,1))) +
scale_x_date(name = NULL, date_breaks="1 month", date_labels = "%b %d") +
ylab("incident deaths") +
labs(title="Weekly reported COVID-19 deaths in the US: observed and forecasted",
caption="source: JHU CSSE (observed data), COVID-19 Forecast Hub (forecasts)") +
theme(legend.position = c(.05,.95), legend.justification = c(0,1))
```
```{r prep-datatable}
## get last saturday observed cumulative deaths
cum_death_start <- read_csv("../../data-truth/truth-Cumulative Deaths.csv") %>%
filter(date == last_5_saturdays[5]) %>%
select(date, location, location_name, value) %>%
rename(cum_deaths_at_forecast_start = value)
## get recent observed inc deaths
recent_inc_death_totals <- read_csv("../../data-truth/truth-Incident Deaths.csv") %>%
# filter(date > last_5_saturdays[3] & date <= last_5_saturdays[5]) %>%
mutate(last_2wk = date > last_5_saturdays[3] & date <= last_5_saturdays[5],
last_4wk = date > last_5_saturdays[1] & date <= last_5_saturdays[5]) %>%
select(date, location, location_name, value, last_2wk, last_4wk) %>%
group_by(location, location_name) %>%
summarize(last_2wk_deaths = sum(value*last_2wk),
last_4wk_deaths = sum(value*last_4wk)) %>%
ungroup() %>%
left_join(locs, by=c("location" = "FIPS")) %>%
left_join(cum_death_start) %>%
rename(fips = location, target_end_date = date)
```
```{r process-ensemble-data}
ensemble_pointdat <- dat %>%
filter(grepl('cum death', target)) %>%
filter(class=="point") %>%
select(fips, target, value, timezero)
wide_point_dat <- spread(ensemble_pointdat, target, value) %>%
left_join(recent_inc_death_totals) %>%
mutate(next_2wk_deaths = `2 wk ahead cum death` - cum_deaths_at_forecast_start,
diff_2wk_deaths = next_2wk_deaths - last_2wk_deaths,
next_4wk_deaths = `4 wk ahead cum death` - cum_deaths_at_forecast_start,
diff_4wk_deaths = next_4wk_deaths - last_4wk_deaths,
pop_x_1k = round(Population/1000),
last_2wk_deaths_rate = round(last_2wk_deaths/Population*100000/14,3),
last_4wk_deaths_rate = round(last_4wk_deaths/Population*100000/28,3),
next_2wk_deaths_rate = round(next_2wk_deaths/Population*100000/14,3),
next_4wk_deaths_rate = round(next_4wk_deaths/Population*100000/28, 3),
diff_2wk_deaths_rate = round(next_2wk_deaths_rate - last_2wk_deaths_rate, 3),
diff_4wk_deaths_rate = round(next_4wk_deaths_rate - last_4wk_deaths_rate, 3),
next_2wk_cum_deaths = `2 wk ahead cum death` - cum_deaths_at_forecast_start) %>%
select(location_name, Population, pop_x_1k, cum_deaths_at_forecast_start,
last_2wk_deaths, next_2wk_deaths, diff_2wk_deaths,
last_4wk_deaths, next_4wk_deaths, diff_4wk_deaths,
last_2wk_deaths_rate, next_2wk_deaths_rate,
last_4wk_deaths_rate, next_4wk_deaths_rate,
diff_2wk_deaths_rate, diff_4wk_deaths_rate, next_2wk_cum_deaths)
#filter quantile data for predicting future weeks
ensemble_quantdat <- dat %>%
filter(target == "2 wk ahead cum death") %>%
filter(class == "quantile")
wide_quant_dat <- spread(ensemble_quantdat, target, value) %>%
left_join(recent_inc_death_totals %>% select(fips, location_name, last_2wk_deaths, cum_deaths_at_forecast_start)) %>%
mutate(next_2wk_deaths = `2 wk ahead cum death` - cum_deaths_at_forecast_start)
quant.5_cutoff <- wide_quant_dat %>%
filter(quantile == .5, next_2wk_deaths >= last_2wk_deaths)
quant.25_cutoff <- wide_quant_dat %>%
filter(quantile == .25, next_2wk_deaths >= last_2wk_deaths)
```
## State-by-state Breakdown
The ensemble model estimates that `r nrow(quant.5_cutoff)` states and territories of the US have a greater than 50% chance of having more deaths in the next two weeks compared to the past two weeks (Table 1).The model forecasts that `r nrow(quant.25_cutoff)` states and territories have a greater than 75% chance of an increase over the next two weeks (`r paste(quant.25_cutoff$location_name, collapse=", ")`).
The sortable and searchable table below shows the total number of reported COVID-19 deaths at the US level and by state over the last two weeks (ending Saturday, `r format(last_5_saturdays[5], "%B %d, %Y")`) and the forecasted counts for the subsequent two weeks (ending `r format(last_5_saturdays[5]+14, "%B %d, %Y")`).
```{r make-datatable-inc-death-counts}
death_max_2wk <- max(abs(wide_point_dat$diff_2wk_deaths))
brks <- seq(-death_max_2wk, death_max_2wk, length.out = 100) #quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
#clrs <- scico(n=length(brks)+1, palette="roma")
clrs <- colorRampPalette(colors = rev(RColorBrewer::brewer.pal(n=3, "RdBu")))(length(brks)+1)
table1_cap <- paste0("Table 1: US national and state-level observed deaths to date and for the previous two weeks (ending ", format(last_5_saturdays[5], "%B %d, %Y") ,") and the next two weeks (ending ", format(last_5_saturdays[5]+14, "%B %d, %Y"), ").")
datatable(wide_point_dat %>%
select(location_name, Population,
cum_deaths_at_forecast_start,
last_2wk_deaths, next_2wk_deaths, diff_2wk_deaths) %>%
arrange(desc(diff_2wk_deaths)),
caption = table1_cap,
options = list(
autoWidth = TRUE,
columnDefs = list(list(width = '100px', targets = c(0, 1, 2, 3, 4, 5)))
), #width=paste0(c(10, 100, 100, 100), 'px'),
rownames=FALSE,
colnames=c('state'='location_name',
#'Population, \'000'='pop_x_1k',
'Population' = 'Population',
'Total COVID-19 deaths'='cum_deaths_at_forecast_start',
'COVID-19 deaths, last 2 weeks'='last_2wk_deaths',
'COVID-19 deaths, next 2 weeks'='next_2wk_deaths',
'Difference' = 'diff_2wk_deaths')) %>%
## formatStyle("Daily deaths, last 2 weeks", backgroundColor = styleInterval(brks, clrs)) %>%
## formatStyle("Daily deaths, next 2 weeks", backgroundColor = styleInterval(brks, clrs)) %>%
formatStyle("Difference", backgroundColor = styleInterval(brks, clrs)) %>%
formatCurrency('Total COVID-19 deaths',currency = "", interval = 3, mark = ",", digits=0) %>%
formatCurrency('Population',currency = "", interval = 3, mark = ",", digits=0) %>%
formatCurrency('COVID-19 deaths, last 2 weeks',currency = "", interval = 3, mark = ",", digits=0) %>%
formatCurrency('COVID-19 deaths, next 2 weeks',currency = "", interval = 3, mark = ",", digits=0)
```
The sortable and searchable table below shows the total number of reported COVID-19 deaths at the US level and by state as of Saturday, `r format(last_5_saturdays[5], "%B %d, %Y")` ("Total COVID-19 Deaths") as well as the rate of reported COVID-19 deaths in the population (standardized per 100,000 population) over the last two weeks and over the next two weeks. Looking at the rates allows for easier comparison across states, where you can see which states have had or are predicted to have propoportionally higher rates in comparison to other states. These tables calculate an average daily number of deaths per 100,000 population across the last two weeks (ending Saturday, `r format(last_5_saturdays[5], "%B %d, %Y")`) and forecasted for the following two weeks (ending `r format(last_5_saturdays[5]+14, "%B %d, %Y")`).
```{r make-datatable-inc-death-rates}
## color for rates
death_rate_max_2wk <- max(c(wide_point_dat$last_2wk_deaths_rate, wide_point_dat$next_2wk_deaths_rate))
brks <- seq(0, death_rate_max_2wk, length.out = 100) #quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
clrs <- round(seq(255, 40, length.out = length(brks) + 1), 0) %>%
{paste0("rgb(255,", ., ",", ., ")")}
## colors for rate difference
death_rate_diff_2wk <- max(abs(wide_point_dat$diff_2wk_deaths_rate))
brks1 <- seq(-death_rate_diff_2wk, death_rate_diff_2wk, length.out = 100) #quantile(df, probs = seq(.05, .95, .05), na.rm = TRUE)
clrs1 <- colorRampPalette(colors = rev(RColorBrewer::brewer.pal(n=3, "RdBu")))(length(brks1)+1)
table2_cap <- paste0("Table 2: US national and state-level observed and predicted daily death rates for the previous two weeks (ending ", format(last_5_saturdays[5], "%B %d, %Y") ,") and the next two weeks (ending ", format(last_5_saturdays[5]+14, "%B %d, %Y"), ").")
datatable(wide_point_dat %>%
select(location_name, Population,
cum_deaths_at_forecast_start,
last_2wk_deaths_rate, next_2wk_deaths_rate, diff_2wk_deaths_rate) %>%
arrange(desc(diff_2wk_deaths_rate)),
caption = table2_cap,
options = list(
autoWidth = TRUE,
columnDefs = list(list(width = '100px', targets = c(0, 1, 2, 3, 4, 5)))
), #width=paste0(c(10, 100, 100, 100), 'px'),
rownames=FALSE,
colnames=c('state'='location_name',
#'Population, \'000'='pop_x_1k',
'Population' = 'Population',
'Total COVID-19 deaths'='cum_deaths_at_forecast_start',
'Daily deaths per 100k, last 2 weeks'='last_2wk_deaths_rate',
'Daily deaths per 100k, next 2 weeks'='next_2wk_deaths_rate',
'Death rate difference' = 'diff_2wk_deaths_rate')) %>%
## formatStyle("Daily deaths per 100k, last 2 weeks", backgroundColor = styleInterval(brks, clrs)) %>%
## formatStyle("Daily deaths per 100k, next 2 weeks", backgroundColor = styleInterval(brks, clrs)) %>%
formatStyle('Death rate difference', backgroundColor = styleInterval(brks1, clrs1)) %>%
formatCurrency('Total COVID-19 deaths',currency = "", interval = 3, mark = ",", digits=0) %>%
formatCurrency('Population',currency = "", interval = 3, mark = ",", digits=0)
```
This report was reproducibly and dynamically generated using RMarkdown. The code for the report can be found [here](https://github.com/reichlab/covid19-forecast-hub/tree/master/code/reports).
```{r}
htmltools::includeScript("statcounter.js")
```