You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Note:** This package is currently in development and likely will not work as expected.
22
+
**Note:** This package is currently in development and may not work as expected. Please file bug reports as issues in this repo, and we will do our best to address them quickly.
23
23
24
24
## Installation
25
25
26
26
You can install the development version of epipredict from [GitHub](https://github.com/) with:
27
27
28
28
```r
29
-
# install.packages("devtools")
30
-
devtools::install_github("cmu-delphi/epipredict")
29
+
# install.packages("remotes")
30
+
remotes::install_github("cmu-delphi/epipredict")
31
31
```
32
32
33
33
## Documentation
@@ -39,7 +39,7 @@ You can view documentation for the `main` branch at <https://cmu-delphi.github.i
39
39
40
40
**We hope to provide:**
41
41
42
-
1. A set of basic, easy-to-use forecasters that work out of the box. You should be able to do a reasonably limited amount of customization on them. (Any serious customization happens with point number 2.) For the basic forecasters, we should provide, at least:
42
+
1. A set of basic, easy-to-use forecasters that work out of the box. You should be able to do a reasonably limited amount of customization on them. For the basic forecasters, we currently provide:
43
43
* Baseline flat-line forecaster
44
44
* Autoregressive forecaster
45
45
* Autoregressive classifier
@@ -49,15 +49,58 @@ You can view documentation for the `main` branch at <https://cmu-delphi.github.i
49
49
* Predictor: make predictions, using a fitted model object
50
50
* Postprocessor: do things to the predictions before returning
51
51
52
-
**Target audience:**
52
+
**Target audiences:**
53
53
54
54
* Basic. Has data, calls forecaster with default arguments.
55
55
* Intermediate. Wants to examine changes to the arguments, take advantage of built in flexibility.
56
56
* Advanced. Wants to write their own forecasters. Maybe willing to build up from some components that we write.
57
57
58
-
The Advanced user should find their task to be relatively easy (and we'll show them how).
58
+
The Advanced user should find their task to be relatively easy. Examples of these tasks are illustrated in the [vignettes and articles](https://cmu-delphi.github.io/epipredict).
59
+
60
+
## Intermediate example
61
+
62
+
The package comes with some built-in historical data for illustration, but
63
+
up-to-date versions of this could be downloaded with the [`{covidcast}` package](https://cmu-delphi.github.io/covidcast/covidcastR/index.html) and processed using [`{epiprocess}`](https://cmu-delphi.github.io/epiprocess/).[^1]
64
+
65
+
[^1]: Other epidemiological signals for non-Covid related illnesses are available with [`{epidatr}`](https://github.com/cmu-delphi/epidatr) which interfaces directly to Delphi's [Epidata API](https://cmu-delphi.github.io/delphi-epidata/)
66
+
67
+
```{r epidf, message=FALSE}
68
+
library(tidyverse)
69
+
library(epipredict)
70
+
jhu <- case_death_rate_subset
71
+
jhu
72
+
```
73
+
74
+
To create and train a simple auto-regressive forecaster to predict the death rate two weeks into the future using past (lagged) deaths and cases, we could use the following function.
75
+
76
+
```{r make-forecasts, warning=FALSE}
77
+
two_week_ahead <- arx_forecaster(
78
+
jhu,
79
+
outcome = "death_rate",
80
+
predictors = c("case_rate", "death_rate"),
81
+
args_list = arx_args_list(
82
+
lags = list(c(0,1,2,3,7,14), c(0,7,14)),
83
+
ahead = 14
84
+
)
85
+
)
86
+
```
87
+
88
+
In this case, we have used a number of different lags for the case rate, while only using 3 weekly lags for the death rate (as predictors). The result is both a fitted model object which could be used any time in the future to create different forecasts, as well as a set of predicted values (and prediction intervals) for each location 14 days after the last available time value in the data.
89
+
90
+
```{r print-model}
91
+
two_week_ahead$epi_workflow
92
+
```
93
+
94
+
The fitted model here involved preprocessing the data to appropriately generate lagged predictors, estimating a linear model with `stats::lm()` and then postprocessing the results to be meaningful for epidemiological tasks. We can also examine the predictions.
95
+
96
+
```{r show-preds}
97
+
two_week_ahead$predictions
98
+
```
99
+
100
+
The results above show a distributional forecast produced using data through the end of 2021 for the 14th of January 2022. A prediction for the death rate per 100K inhabitants is available for every state (`geo_value`) along with a 90% predictive interval.
101
+
102
+
<!--
59
103
60
-
**Example:**
61
104
During a quiet period, a user decides they want to first predict whether a surge is about to occur, say using variant information from GISAID. Then for surging locations, they want to train an AR model using past surges in the same location. Everywhere else, they predict a flat line. We should be able to do this in a few lines of code.
62
105
63
106
Delphi's own forecasts have been produced/evaluated in this way for a while now, but the code base is scattered and evolving. We want to consolidate, generalize, and simplify to allow others to benefit as well.
The hypothetical example of first classifying, then fitting different models would also fit into this framework. And this isn't far from our current production models.
86
129
87
-
### Why doesn't this exist
88
130
89
-
Closest neighbor is [`{fable}`](https://fable.tidyverts.org/). It does some of what we want but has a few major downsides:
90
131
91
-
1. Small set of standard Time Series models.
92
-
* Small modifications are hard (e.g. can't "just use" `glmnet` instead of `lm`) in an AR model.
93
-
1. Multi-period forecasting is model-based only.
94
-
* This is "iterative" forecasting, and is very bad in epidemiology.
95
-
* Much better with simple models to use "direct" forecasting.
96
-
1. Confidence bands are model-based only.
97
-
* In epi tasks, these dramatically under-cover.
98
-
1. Layering is not possible/natural
99
-
1. Can't use methods that aren't already implemented.
100
-
101
-
The forecasts we did above can't be produced with `{fable}`.
102
-
103
-
104
-
**However:** The developers behind `{fable}` wrote a package called `{fabletools}` that powers model creation (based on `R6`). We can almost certainly borrow some of that technology to lever up.
105
132
106
133
### What this isn't
107
134
108
135
This is not a framework for SIR models. We intend to create some simple versions, but advanced models---those that use variants, hospitalizations, different types of immunity, age stratification, etc.---cannot be compartmentalized in the same way (though see [pypm](https://pypm.github.io/home/)). These types of models also are better at scenario modeling than short term forecasts unless they are quite complicated.
0 commit comments