View source: R/layer_predictive_distn.R
layer_predictive_distn | R Documentation |
This function calculates an approximation to a parametric predictive
distribution. Predictive distributions from linear models require
x* (X'X)^{-1} x*
along with the degrees of freedom. This function approximates both. It
should be reasonably accurate for models fit using lm
when the new point
x*
isn't too far from the bulk of the data.
layer_predictive_distn(
frosting,
...,
dist_type = c("gaussian", "student_t"),
truncate = c(-Inf, Inf),
name = ".pred_distn",
id = rand_id("predictive_distn")
)
frosting |
a |
... |
Unused, include for consistency with other layers. |
dist_type |
Gaussian or Student's t predictive intervals |
truncate |
Do we truncate the distribution to an interval |
name |
character. The name for the output column. |
id |
a random id string |
an updated frosting
postprocessor with additional columns of the
residual quantiles added to the prediction
library(dplyr)
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_predictive_distn() %>%
layer_naomit(.pred)
wf1 <- wf %>% add_frosting(f)
p <- forecast(wf1)
p
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.