Skip to content

Instantly share code, notes, and snippets.

@brshallo
Last active June 22, 2022 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brshallo/f83fd9a1ccd467db78788e2a8804bd81 to your computer and use it in GitHub Desktop.
Save brshallo/f83fd9a1ccd467db78788e2a8804bd81 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(tidymodels)
library(workboots)
data <- tibble(x = abs(rnorm(1000)),
y = x + rnorm(1000, sd = 0.7) * x / (max(x))
)
rec <- recipe(y ~ ., data = data)
mod <- parsnip::linear_reg() %>%
set_engine("lm") %>%
set_mode("regression")
workflow <- workflows::workflow() %>%
add_recipe(rec) %>%
add_model(mod)
set.seed(345)
pred_int <-
workflow %>%
predict_boots(
n = 500,
training_data = data,
new_data = data
)
# summarise predictions with a 95% prediction interval
bind_cols(data,
pred_int %>% summarise_predictions()
) %>%
ggplot(aes(x = x, y = y))+
geom_line(aes(y = .pred, colour = ".pred"))+
geom_ribbon(aes(ymin = .pred_lower, ymax = .pred_upper), alpha = 0.2)+
geom_point()+
labs(title = "workboots also does not capture heteroskedasticity in intervals")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment