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
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.
89
+
90
+
```{r make-forecasts, warning=FALSE}
91
+
two_week_ahead <- arx_forecaster(
92
+
covid_case_death_rates,
93
+
outcome = "death_rate",
94
+
predictors = c("case_rate", "death_rate"),
95
+
args_list = arx_args_list(
96
+
lags = list(c(0, 1, 2, 3, 7, 14), c(0, 7, 14)),
97
+
ahead = 14
98
+
)
99
+
)
100
+
two_week_ahead
101
+
```
102
+
103
+
In this case, we have used a number of different lags for the case rate, while
104
+
only using 3 weekly lags for the death rate (as predictors). The result is both
105
+
a fitted model object which could be used any time in the future to create
106
+
different forecasts, as well as a set of predicted values (and prediction
107
+
intervals) for each location 14 days after the last available time value in the
108
+
data.
109
+
110
+
```{r print-model}
111
+
two_week_ahead$epi_workflow
112
+
```
113
+
114
+
The fitted model here involved preprocessing the data to appropriately generate
115
+
lagged predictors, estimating a linear model with `stats::lm()` and then
116
+
postprocessing the results to be meaningful for epidemiological tasks. We can
117
+
also examine the predictions.
118
+
119
+
```{r show-preds}
120
+
two_week_ahead$predictions
121
+
```
122
+
123
+
The results above show a distributional forecast produced using data through
124
+
the end of 2021 for the 14th of January 2022. A prediction for the death rate
125
+
per 100K inhabitants is available for every state (`geo_value`) along with a
126
+
90% predictive interval.
127
+
22
128
23
129
# Goals for the package
24
130
@@ -195,9 +301,9 @@ Here, we've used different lags on the `case_rate` and are now predicting 2
195
301
weeks ahead. This example also illustrates a major difficulty with the
196
302
"iterative" versions of AR models. This model doesn't produce forecasts for
197
303
`case_rate`, and so, would not have data to "plug in" for the necessary
198
-
lags.[^1]
304
+
lags.[^3]
199
305
200
-
[^1]: An obvious fix is to instead use a VAR and predict both, but this would
306
+
[^3]: An obvious fix is to instead use a VAR and predict both, but this would
201
307
likely increase the variance of the model, and therefore, may lead to less
0 commit comments