layer_residual_quantiles: Creates predictions based on residual quantiles

View source: R/layer_residual_quantiles.R

layer_residual_quantilesR Documentation

Creates predictions based on residual quantiles

Description

Creates predictions based on residual quantiles

Usage

layer_residual_quantiles(
  frosting,
  ...,
  quantile_levels = c(0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95),
  symmetrize = TRUE,
  by_key = character(0L),
  name = ".pred_distn",
  id = rand_id("residual_quantiles")
)

Arguments

frosting

a frosting postprocessor

...

Unused, include for consistency with other layers.

quantile_levels

numeric vector of probabilities with values in (0,1) referring to the desired quantile. Note that 0.5 will always be included even if left out by the user.

symmetrize

logical. If TRUE then interval will be symmetric.

by_key

A character vector of keys to group the residuals by before calculating quantiles. The default, c() performs no grouping.

name

character. The name for the output column.

id

a random id string

Value

an updated frosting postprocessor with additional columns of the residual quantiles added to the prediction

Examples

jhu <- covid_case_death_rates %>%
  filter(time_value > "2021-11-01", geo_value %in% c("ak", "ca", "ny"))

r <- epi_recipe(jhu) %>%
  step_epi_lag(death_rate, lag = c(0, 7, 14)) %>%
  step_epi_ahead(death_rate, ahead = 7) %>%
  step_epi_naomit()

wf <- epi_workflow(r, linear_reg()) %>% fit(jhu)

f <- frosting() %>%
  layer_predict() %>%
  layer_residual_quantiles(
    quantile_levels = c(0.025, 0.975),
    symmetrize = FALSE
  ) %>%
  layer_naomit(.pred)
wf1 <- wf %>% add_frosting(f)

p <- forecast(wf1)

f2 <- frosting() %>%
  layer_predict() %>%
  layer_residual_quantiles(
    quantile_levels = c(0.3, 0.7),
    by_key = "geo_value"
  ) %>%
  layer_naomit(.pred)
wf2 <- wf %>% add_frosting(f2)

p2 <- forecast(wf2)

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