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

https://github.com/epiforecasts/episoon

Forecasting the effective reproduction number over short timescales
https://github.com/epiforecasts/episoon

case-forecasts forecasts

Last synced: 4 months ago
JSON representation

Forecasting the effective reproduction number over short timescales

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```

# EpiSoon

[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-blue.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![R build status](https://github.com/epiforecasts/EpiSoon/workflows/R-CMD-check/badge.svg)](https://github.com/epiforecasts/EpiSoon)
[![Codecov test coverage](https://codecov.io/gh/epiforecasts/EpiSoon/branch/main/graph/badge.svg)](https://app.codecov.io/gh/epiforecasts/EpiSoon?branch=main) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/epiforecasts/EpiSoon/blob/main/LICENSE.md/) [![GitHub contributors](https://img.shields.io/github/contributors/epiforecasts/EpiSoon)](https://github.com/epiforecasts/EpiSoon/graphs/contributors) [![universe](https://epiforecasts.r-universe.dev/badges/EpiSoon)](http://epiforecasts.r-universe.dev/ui/#package:EpiSoon) [![DOI](https://zenodo.org/badge/248311916.svg)](https://zenodo.org/badge/latestdoi/248311916)

This package provides tooling to forecast the time-varying reproduction number and use this to forecast reported case counts via a branching process. It supports a range of time series modelling packages including `bsts`, `forecast`, and `fable`. It also supports ensembles via `lopensemble` and `forecastHyrbid`. Forecasts can be assessed by iteractively fitting and then using proper scoring rules (via `scoringutils` and `scoringRules`) to compare to both observed case counts and estimated reproduction numbers.

## Installation

Install the stable development version of the package with:

```{r, eval = FALSE}
install.packages("EpiSoon", repos = "https://epiforecasts.r-universe.dev")
```

Install the unstable development version of the package with (few users should need to do this):

```{r, eval = FALSE}
remotes::install_github("epiforecasts/EpiSoon")
```

## Quick start

* Load packages (`bsts` and `fable` for models, `ggplot2` for plotting, and `cowplot` for theming)

```{r, message = FALSE}
library(EpiSoon)
library(bsts)
library(fable)
library(future)
library(cowplot)
library(dplyr)
```

* Set up example data (using `EpiSoon::example_obs_rts` and `EpiSoon::example_obs_cases` as starting data sets). When generating timeseries with `EpiNow` use `get_timeseries` to extract the required data.

```{r}
obs_rts <- EpiSoon::example_obs_rts %>%
dplyr::mutate(timeseries = "Region 1") %>%
dplyr::bind_rows(EpiSoon::example_obs_rts %>%
dplyr::mutate(timeseries = "Region 2"))

obs_cases <- EpiSoon::example_obs_cases %>%
dplyr::mutate(timeseries = "Region 1") %>%
dplyr::bind_rows(EpiSoon::example_obs_cases %>%
dplyr::mutate(timeseries = "Region 2"))
```

* Define the list of models to be compared.

```{r}
models <- list(
"AR 3" =
function(...) {
EpiSoon::bsts_model(
model =
function(ss, y) {
bsts::AddAr(ss, y = y, lags = 3)
}, ...
)
},
"Semi-local linear trend" =
function(...) {
EpiSoon::bsts_model(
model =
function(ss, y) {
bsts::AddSemilocalLinearTrend(ss, y = y)
}, ...
)
},
"ARIMA" =
function(...) {
EpiSoon::fable_model(model = fable::ARIMA(y ~ time), ...)
}
)
```

* Compare models across timeseries (change the `future::plan` to do this in parallel).

```{r}
future::plan("sequential")

## Compare models
forecasts <- EpiSoon::compare_timeseries(obs_rts, obs_cases, models,
horizon = 7, samples = 10,
serial_interval = EpiSoon::example_serial_interval
)

forecasts
```

* Plot an evaluation of Rt forecasts using iterative fitting.

```{r, fig.width = 7, fig.height = 7, dpi = 320, out.width = "60%"}
EpiSoon::plot_forecast_evaluation(forecasts$forecast_rts, obs_rts, c(7)) +
ggplot2::facet_grid(model ~ timeseries) +
cowplot::panel_border()
```

* Plot an evaluation of case forecasts using iterative fitting

```{r, fig.width = 7, fig.height = 7, dpi = 320, out.width = "60%"}
EpiSoon::plot_forecast_evaluation(forecasts$forecast_cases, obs_cases, c(7)) +
ggplot2::facet_grid(model ~ timeseries, scales = "free") +
cowplot::panel_border()
```

* Summarise the forecasts by model scored against observed cases

```{r}
EpiSoon::summarise_scores(forecasts$case_scores)
```

## Contributing

File an issue [here](https://github.com/epiforecasts/EpiSoon/issues) if you have identified an issue with the package. Please note that due to operational constraints priority will be given to users informing government policy or offering methodological insights. We welcome all contributions, in particular those that improve the approach or the robustness of the code base.