options(width = 76)
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

epipredict

R-CMD-check

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.

Installation

To install (unless you're making changes to the package, use the stable version):

# Stable version
pak::pkg_install("cmu-delphi/epipredict@main")

# Dev version
pak::pkg_install("cmu-delphi/epipredict@dev")

Documentation

You can view documentation for the main branch at https://cmu-delphi.github.io/epipredict.

Goals for epipredict

We hope to provide:

  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:
    • 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

Target audiences:

The Advanced user should find their task to be relatively easy. Examples of these tasks are illustrated in the vignettes and articles.

See also the (in progress) Forecasting Book.

Intermediate example

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 and processed using {epiprocess}.[^1]

[^1]: Other epidemiological signals for non-Covid related illnesses are also available with {epidatr} which interfaces directly to Delphi's Epidata API

library(epipredict)
covid_case_death_rates

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.

two_week_ahead <- arx_forecaster(
  covid_case_death_rates,
  outcome = "death_rate",
  predictors = c("case_rate", "death_rate"),
  args_list = arx_args_list(
    lags = list(c(0, 1, 2, 3, 7, 14), c(0, 7, 14)),
    ahead = 14
  )
)
two_week_ahead

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.

two_week_ahead$epi_workflow

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.

two_week_ahead$predictions

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.



cmu-delphi/epipredict documentation built on March 5, 2025, 12:17 p.m.