Skip to content

Commit

Permalink
rebuild README, simplify getting started
Browse files Browse the repository at this point in the history
  • Loading branch information
dajmcdon committed Nov 11, 2024
1 parent e513285 commit bc155b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ Suggests:
VignetteBuilder:
knitr
Remotes:
cmu-delphi/delphidocs,
cmu-delphi/epidatr,
cmu-delphi/epiprocess,
cmu-delphi/delphidocs
dajmcdon/smoothqr
Config/testthat/edition: 3
Config/Needs/website: cmu-delphi/delphidocs
Expand Down
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,24 @@ You can view documentation for the `main` branch at
You should be able to do a reasonably limited amount of
customization on them. For the basic forecasters, we currently
provide:
- Baseline flatline forecaster
- Autoregressive forecaster
- Autoregressive classifier
- CDC FluSight flatline forecaster
- Baseline flatline forecaster
- Autoregressive forecaster
- Autoregressive classifier
- CDC FluSight flatline forecaster
2. A framework for creating custom forecasters out of modular
components. There are four types of components:
- Preprocessor: do things to the data before model training
- Trainer: train a model on data, resulting in a fitted model
object
- Predictor: make predictions, using a fitted model object
- Postprocessor: do things to the predictions before returning
- Preprocessor: do things to the data before model training
- Trainer: train a model on data, resulting in a fitted model object
- Predictor: make predictions, using a fitted model object
- Postprocessor: do things to the predictions before returning

**Target audiences:**

- Basic. Has data, calls forecaster with default arguments.
- Intermediate. Wants to examine changes to the arguments, take
advantage of built in flexibility.
- Advanced. Wants to write their own forecasters. Maybe willing to
build up from some components.
- Basic. Has data, calls forecaster with default arguments.
- Intermediate. Wants to examine changes to the arguments, take
advantage of built in flexibility.
- Advanced. Wants to write their own forecasters. Maybe willing to build
up from some components.

The Advanced user should find their task to be relatively easy. Examples
of these tasks are illustrated in the [vignettes and
Expand All @@ -71,7 +70,7 @@ The package comes with some built-in historical data for illustration,
but up-to-date versions of this could be downloaded with the
[`{epidatr}` package](https://cmu-delphi.github.io/epidatr/) and
processed using
[`{epiprocess}`](https://cmu-delphi.github.io/epiprocess/).\[1\]
[`{epiprocess}`](https://cmu-delphi.github.io/epiprocess/).[^1]

``` r
library(epipredict)
Expand Down Expand Up @@ -114,7 +113,7 @@ two_week_ahead <- arx_forecaster(
two_week_ahead
#> ══ A basic forecaster of type ARX Forecaster ═══════════════════════════════
#>
#> This forecaster was fit on 2024-01-29 15:10:01.
#> This forecaster was fit on 2024-11-11 11:38:31.
#>
#> Training data was an <epi_df> with:
#> • Geography: state,
Expand Down Expand Up @@ -207,7 +206,7 @@ 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.

1. Other epidemiological signals for non-Covid related illnesses are
[^1]: Other epidemiological signals for non-Covid related illnesses are
also available with
[`{epidatr}`](https://github.com/cmu-delphi/epidatr) which
interfaces directly to Delphi’s [Epidata
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ home:
- text: The epiprocess package
href: https://cmu-delphi.github.io/epiprocess/
sidebar:
structure: [links, license, community, citation, authors, related, dev]
structure: [links, license, community, citation, authors, dev, related]
components:
related:
title: Delphi packages and resources
Expand Down
25 changes: 14 additions & 11 deletions vignettes/epipredict.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ library(dplyr)
library(parsnip)
library(workflows)
library(recipes)
library(epiprocess)
library(epipredict)
```

Expand Down Expand Up @@ -226,17 +225,15 @@ symmetrized). Here, we used 23 quantiles, but one can grab a particular
quantile,

```{r q1}
head(quantile(out_q$predictions$.pred_distn, p = .4))
round(head(quantile(out_q$predictions$.pred_distn, p = .4)), 3)
```

or extract the entire distribution into a "long" `epi_df` with `quantile_levels`
being the probability and `values` being the value associated to that quantile.

```{r q2}
out_q$predictions %>%
# first create a "nested" list-column
mutate(.pred_distn = nested_quantiles(.pred_distn)) %>%
unnest(.pred_distn) # then unnest it
pivot_quantiles_longer(.pred_distn)
```

Additional simple adjustments to the basic forecaster can be made using the
Expand All @@ -262,26 +259,32 @@ package:

```{r ranger, warning = FALSE}
out_rf <- arx_forecaster(
jhu, "death_rate", c("case_rate", "death_rate"),
rand_forest(mode = "regression")
jhu,
outcome = "death_rate",
predictors = c("case_rate", "death_rate"),
trainer = rand_forest(mode = "regression")
)
```

Or boosted regression trees with `{xgboost}`:

```{r xgboost, warning = FALSE}
out_gb <- arx_forecaster(
jhu, "death_rate", c("case_rate", "death_rate"),
boost_tree(mode = "regression", trees = 20)
jhu,
outcome = "death_rate",
predictors = c("case_rate", "death_rate"),
trainer = boost_tree(mode = "regression", trees = 20)
)
```

Or quantile regression, using our custom forecasting engine `quantile_reg()`:

```{r quantreg, warning = FALSE}
out_qr <- arx_forecaster(
jhu, "death_rate", c("case_rate", "death_rate"),
quantile_reg()
jhu,
outcome = "death_rate",
predictors = c("case_rate", "death_rate"),
trainer = quantile_reg()
)
```

Expand Down

0 comments on commit bc155b7

Please sign in to comment.