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
Copy file name to clipboardExpand all lines: vignettes/epipredict.Rmd
+86
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,92 @@ library(recipes)
19
19
library(epipredict)
20
20
```
21
21
22
+
## Goals for `epipredict` (from README)
23
+
24
+
**We hope to provide:**
25
+
26
+
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:
27
+
* Baseline flatline forecaster
28
+
* Autoregressive forecaster
29
+
* Autoregressive classifier
30
+
* CDC FluSight flatline forecaster
31
+
2. A framework for creating custom forecasters out of modular components. There are four types of components:
32
+
* Preprocessor: do things to the data before model training
33
+
* Trainer: train a model on data, resulting in a fitted model object
34
+
* Predictor: make predictions, using a fitted model object
35
+
* Postprocessor: do things to the predictions before returning
36
+
37
+
**Target audiences:**
38
+
39
+
* Basic. Has data, calls forecaster with default arguments.
40
+
* Intermediate. Wants to examine changes to the arguments, take advantage of
41
+
built in flexibility.
42
+
* Advanced. Wants to write their own forecasters. Maybe willing to build up
43
+
from some components.
44
+
45
+
The Advanced user should find their task to be relatively easy. Examples of
46
+
these tasks are illustrated in the [vignettes and articles](https://cmu-delphi.github.io/epipredict).
47
+
48
+
See also the (in progress) [Forecasting Book](https://cmu-delphi.github.io/delphi-tooling-book/).
49
+
50
+
## Intermediate example
51
+
52
+
The package comes with some built-in historical data for illustration, but
53
+
up-to-date versions of this could be downloaded with the
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.
69
+
70
+
```{r make-forecasts, warning=FALSE}
71
+
two_week_ahead <- arx_forecaster(
72
+
covid_case_death_rates,
73
+
outcome = "death_rate",
74
+
predictors = c("case_rate", "death_rate"),
75
+
args_list = arx_args_list(
76
+
lags = list(c(0, 1, 2, 3, 7, 14), c(0, 7, 14)),
77
+
ahead = 14
78
+
)
79
+
)
80
+
two_week_ahead
81
+
```
82
+
83
+
In this case, we have used a number of different lags for the case rate, while
84
+
only using 3 weekly lags for the death rate (as predictors). The result is both
85
+
a fitted model object which could be used any time in the future to create
86
+
different forecasts, as well as a set of predicted values (and prediction
87
+
intervals) for each location 14 days after the last available time value in the
88
+
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
95
+
lagged predictors, estimating a linear model with `stats::lm()` and then
96
+
postprocessing the results to be meaningful for epidemiological tasks. We can
97
+
also examine the predictions.
98
+
99
+
```{r show-preds}
100
+
two_week_ahead$predictions
101
+
```
102
+
103
+
The results above show a distributional forecast produced using data through
104
+
the end of 2021 for the 14th of January 2022. A prediction for the death rate
105
+
per 100K inhabitants is available for every state (`geo_value`) along with a
0 commit comments