An open API service indexing awesome lists of open source software.

https://github.com/epiforecasts/covid19.forecasts.uk

Data and code accompanying the preprint "Short-term forecasts to inform the response to the Covid-19 epidemic in the UK"
https://github.com/epiforecasts/covid19.forecasts.uk

Last synced: 12 months ago
JSON representation

Data and code accompanying the preprint "Short-term forecasts to inform the response to the Covid-19 epidemic in the UK"

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
Title <- "Short-term forecasts to inform the response to the Covid-19 epidemic in the UK"
```

# Short-term forecasts to inform the response to the Covid-19 epidemic in the UK

This repository contains the data and code for our manuscript:

> Funk S, Abbott S, Atkins B, Baguelin M, Baillie JK, Birrell P, Blake J, Bosse NI, Burton J, Carruthers J, Davies NG, De Angelis D, Dyson L, Edmunds WJ, Eggo RM, Ferguson NM, Gaythorpe K, Gorsich E, Guyver-Fletcher G, Hellewell J, Hill EM, Holmes A, House TA, Jewell C, Jit M, Jombart T, Joshi I, Keeling MJ, Kendall E, Knock E, Kucharski AJ, Lythgoe KA, Meakin SR, Munday JD, Openshaw PJM, Overton CE, Pagani F, Pearson J, Pellis L, Scarabel F, Semple MG, Sherratt K, Tang M, Tildesley MJ, Van Leeuwen E, Whittles LK, CMMID COVID-19 Working Group, Imperial College COVID-19 Response Team, ISARIC4C Investigators. _`r Title`_. MedRxiv:, online at

### How to download or install

You can download the compendium as a zip from from this URL:

Or you can install this compendium as an R package, `covid19.forecasts.uk`, from GitHub with:

```{r gh-installation, eval = FALSE}
# install.packages("devtools")
remotes::install_github("sbfnk/covid19.forecasts.uk")
```

### Included data sets

The package includes a publicly available data set of new hospitalisations and hospital bed occupancy with Covid-19 by NHS England region and devolved nation, and deaths by date of death in England.

```{r eval=FALSE}
data(covid_uk_data)
```

Data that are excluded from scoring because they were not available at the time the forecasts were made are listed in

```{r eval=FALSE}
data(exclude_data)
```

All the individual model forecasts are included also included.

```{r eval=FALSE}
data(uk_forecasts)
```

Lastly, the forecast ensembles described in the paper, and the weights of the quantile regression average, are included:

```{r eval=FALSE}
data(ensembles)
data(qra_weights)
```

The ensembles that are based on publicly available data can be re-created from the individual model forecasts using

```{r eval=FALSE}
ensembles_and_weights <- generate_ensembles(uk_forecasts, covid_uk_data)
ensembles <- ensembles_and_weights$ensembles
qra_weights <- ensembles_and_weights$qra_weights
```

To extract the best-performing equally-weighted quantiles (between mean and median) and QRA model, run

```{r eval=FALSE}
scored_ensembles <- ensembles %>%
score_forecasts(covid_uk_data, exclude_data) %>%
mutate(ensemble_type = substr(model, 1, 3))
ranked_ensembles <- scored_ensembles %>%
rank_forecasts()
best_ensembles <- ranked_ensembles %>%
group_by(ensemble_type) %>%
filter(mean == min(mean)) %>%
ungroup()
```

For later use, the package also includes a vector with the name of the National Health Service (NHS) England regions,

```{r eval = FALSE}
data(nhse_regions)
```

### Table and figures

To generate the tables and figures from the paper, we will need the `dplyr` and `cowplot` packages:

```{r eval=FALSE}
library("dplyr")
library("tidyr")
library("purrr")
library("cowplot")
```
To generate Figure 1, run

```{r eval=FALSE}
plot_data <- covid_uk_data %>%
filter(value_type %in% c("death_inc_line", "hospital_inc", "hospital_prev"),
geography %in% c("England", "Northern Ireland", "Scotland", "Wales"))

p <- plot_data_forecasts(uk_forecasts, plot_data, uncertainty = TRUE, exclude = exclude_data)
save_plot("figure1.png", p, base_height = 9)
```

To generate Figure 2 (excluding data that is not publicly available), run

```{r eval=FALSE}
complete_forecasts <- uk_forecasts %>%
pivot_wider(names_from = "quantile", values_from = "value") %>%
nest(data = matches("^[0-9]")) %>%
mutate(extrapolated = purrr::map(data, estimate_quantiles)) %>%
unnest(extrapolated) %>%
select(-data) %>%
pivot_longer(names_to = "quantile", values_to = "value", matches("^[0-9]")) %>%
mutate(quantile = as.numeric(quantile))
scored_forecasts <- complete_forecasts %>%
score_forecasts(covid_uk_data, exclude_data)
scored_selected_ensembles <- scored_ensembles %>%
filter(model %in% best_ensembles$model) %>%
mutate(model = ensemble_type, .keep = "unused")
scored_null <- fit_null_model(uk_forecasts, covid_uk_data) %>%
score_forecasts(covid_uk_data, exclude_data)
p <- null_model_plot(list(scored_selected_ensembles, scored_forecasts), scored_null)
save_plot("figure2.png", p, base_asp = 1.7, base_height = 7)
```

Because data on ICU bed occupancy were not publicly available at the time of writing the manuscript, this data is not included in the package and the corresponding panel in Figure 2 missing if using the command above.

To generate Table 1, run

```{r eval = FALSE}
scores_table(scored_selected_ensembles, file = "table1.pdf", common_creation_dates = TRUE)
```

To generate Figure 3, run

```{r eval = FALSE}
selected_ensembles <- ensembles %>%
filter(model %in% best_ensembles$model, nmodels > 1) %>%
mutate(model = substr(model, 1, 3))
p <- plot_data_forecasts(selected_ensembles, plot_data, exclude = exclude_data)
save_plot("figure3.png", p, base_height = 9)
```

To generate Figure 4, run

```{r eval = FALSE}
data(qra_weights)
plot_weights <- qra_weights %>%
filter(qra_model %in% best_ensembles$model,
geography == "England", quantile == 0.5)
p <- weights_plot(plot_weights)
save_plot("figure4.png", p, base_asp = 1.7, base_height = 7)
```

To generate Supplementary Table S1, run

```{r eval=FALSE}
scores_table(scored_forecasts, file = "si_table1.pdf")
```

To generate Supplementary Table S2, run

```{r eval=FALSE}
qra_rank_table(ranked_ensembles %>% filter(ensemble_type == "QRA"),
file = "si_table2.pdf")
```

To generate Supplementary Table S3, run

```{r eval=FALSE}
ewq_rank_table(ranked_ensembles %>% filter(ensemble_type == "EWQ"),
file = "si_table3.pdf")
```