-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME.Rmd
129 lines (99 loc) · 4.66 KB
/
README.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
---
output: github_document
---
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```
# EpiSoon
[](https://lifecycle.r-lib.org/articles/stages.html#experimental) [](https://github.com/epiforecasts/EpiSoon)
[](https://app.codecov.io/gh/epiforecasts/EpiSoon?branch=main) [](https://github.com/epiforecasts/EpiSoon/blob/main/LICENSE.md/) [](https://github.com/epiforecasts/EpiSoon/graphs/contributors) [](http://epiforecasts.r-universe.dev/ui/#package:EpiSoon) [](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 `stackr` 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.