Skip to content

Instantly share code, notes, and snippets.

@robjhyndman
Created March 27, 2023 21:47
Show Gist options
  • Save robjhyndman/a11eba538d26ba60454abd600ea6204d to your computer and use it in GitHub Desktop.
Save robjhyndman/a11eba538d26ba60454abd600ea6204d to your computer and use it in GitHub Desktop.
Using stretch_tsibble with covariates
library(fpp3)
# Stretched data
stretch_uschange <- us_change |>
stretch_tsibble(.init = 5)
# Fit models to all folds of data
fit <- stretch_uschange |>
model(lm = TSLM(Consumption ~ Income))
# Set up covariates for 4 steps ahead
future_covariates <- stretch_uschange |>
new_data(n = 4) |>
left_join(us_change, by = "Quarter")
# Forecast 4 steps ahead
fc <- fit |>
forecast(new_data = future_covariates)
# Check accuracy of forecasts
accuracy(fc, us_change)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment