Creates predictions based on residual quantiles
Source:R/layer_residual_quantiles.R
layer_residual_quantiles.Rd
Creates predictions based on 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.
- 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
library(dplyr)
jhu <- case_death_rate_subset %>%
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.0275, 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)
#> Warning: Some grouping keys are not in data.frame returned by the
#> `residuals()` method. Groupings may not be correct.