knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(fastTS)
library(tibble)
set.seed(123)

Lake Huron data set

data("LakeHuron")
years <- time(LakeHuron)
fit <- fastTS(LakeHuron, n_lags_max = 3)
fit

What does predict do?

Let $y_t$ refer to our outcome series, and $\hat y_t^{(k)}$ refer to the $k$-step-ahead prediction for $y_t$.

The predicted value returned at any time point $t$ is the model's prediction for that point $\hat y_t$, given the model and all data up to $t -$ n_ahead. This means that

Here is an example with the LakeHuron data set.

p1 <- predict(fit, n_ahead = 1)
p7 <- predict(fit, n_ahead = 7)
predictions <- tibble(years, LakeHuron, p1, p7)
head(predictions, 10)
tail(predictions)

Note: there is a "burn-in" component to fastTS objects that means the first n_lags_max observations are back-filled in.

Forecasting

By default, the predict function does not produce forecasts. In order to get forecasts, we need to set forecast_ahead = TRUE, which will return forecasted values at the tail end of the returned vector.

p1 <- predict(fit, n_ahead = 1, forecast_ahead = TRUE) 
predictions <- tibble(time = c(1973), p1)


# For 7-step ahead forecasts
p7 <- predict(fit, n_ahead = 7, forecast_ahead = TRUE)
predictions <- tibble(time = c(1973:1979), p7)
predictions

Finally, the return_intermediate option allows users to collect all of the step-ahead predictions up to $k$:

p1_p7 <- predict(fit, n_ahead = 7, return_intermediate = TRUE)

predictions <- tibble(years, LakeHuron, p1_p7)
tail(predictions)


petersonR/srlTS documentation built on Dec. 7, 2024, 12:39 a.m.