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 may not work as expected. Please file bug reports as issues in this repo, and we will do our best to address them quickly.
21
+
This package contains data sets used to compile vignettes
22
+
and other documentation in Delphi R Packages. The goal is to
23
+
avoid calls to the Delphi Epidata API, and deposit some
24
+
examples here for easy offline use.
23
25
24
26
## Installation
25
27
26
-
You can install the development version of epipredict from [GitHub](https://github.com/) with:
28
+
You can install the development version of `{epidatasets}` like so:
27
29
28
30
```r
29
31
# install.packages("remotes")
30
-
remotes::install_github("cmu-delphi/epipredict")
32
+
remotes::install_github("cmu-delphi/epidatasets")
31
33
```
32
34
33
-
## Documentation
34
35
35
-
You can view documentation for the `main` branch at <https://cmu-delphi.github.io/epipredict>.
36
+
## Contents
36
37
38
+
This package contains a number of different datasets, along
39
+
with the code used to generate them. See the Source Code if
40
+
you want to examine the necessary API calls.
37
41
38
-
## Goals for `epipredict`
42
+
All data included here is in `epi_df` format, which is a
43
+
subclass of `tbl_df` which is a subclass of `data.frame`.
44
+
The data will print nicely if you load the `{epiprocess}`
45
+
or `{tibble}` packages, but these are not required to access
46
+
or inspect the data sets. For example,
39
47
40
-
**We hope to provide:**
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. For the basic forecasters, we currently provide:
43
-
* Baseline flat-line forecaster
44
-
* Autoregressive forecaster
45
-
* Autoregressive classifier
46
-
2. A framework for creating custom forecasters out of modular components. There are four types of components:
47
-
* Preprocessor: do things to the data before model training
48
-
* Trainer: train a model on data, resulting in a fitted model object
49
-
* Predictor: make predictions, using a fitted model object
50
-
* Postprocessor: do things to the predictions before returning
51
-
52
-
**Target audiences:**
53
-
54
-
* Basic. Has data, calls forecaster with default arguments.
55
-
* Intermediate. Wants to examine changes to the arguments, take advantage of built in flexibility.
56
-
* Advanced. Wants to write their own forecasters. Maybe willing to build up from some components that we write.
57
-
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
-
)
48
+
```{r}
49
+
library(epidatasets)
50
+
head(cases_deaths_subset)
86
51
```
87
52
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
53
+
Compared to
54
+
```{r}
55
+
library(tibble)
56
+
cases_deaths_subset
98
57
```
99
58
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
-
<!--
103
-
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.
105
-
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.
107
-
108
-
The basic framework should allow for something like the following. This would
109
-
feel very familiar to anyone working in `R`+`{tidyverse}`.
110
-
111
-
**Simple linear autoregressive model with scaling (modular)**
112
-
113
-
```{r ideal-framework, eval=FALSE}
114
-
my_fcaster = new_epi_predictor() %>%
115
-
add_preprocessor(scaler, var = cases, by = pop) %>%
116
-
add_preprocessor(lagger, var = dv_cli, lags = c(0, 7, 14)) %>%
117
-
add_trainer(lm) %>%
118
-
add_predictor(lm.predict) %>%
119
-
add_postprocessor(scaler, by = 1/pop)
59
+
Compared to
60
+
```{r, message=FALSE}
61
+
library(epiprocess)
62
+
cases_deaths_subset
120
63
```
121
64
122
-
Then you could run this on an `epi_df` with one line.
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.
129
-
130
-
131
-
132
-
133
-
### What this isn't
134
-
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