Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
556 views
in Technique[技术] by (71.8m points)

arima - Interpreting arimax forecast in R fable

I have a lagged ind. variable x which I believe can predict y.

First I fitted a tslm-model and saw that the residuals might be modelled as an arima-process. -> So I modelled the residuals as ARIMAX (1,1,0). My trouble is understanding why the forecast (fitted to the validation data) doesn't behave like an arima-model. The AR(1) process is doing its thing on the fitted values. But it looks very close to a simple tslm-model in the validation data.

Is it because the AR-process is extrapolated from the first calculated value at y_fc_1 and that value is multiplied with the AR-coefficient going forwards? Instead of feeding it fresh y_t-1 data like on the fitted line?

Example and plot below!

library(tsibble)
library(fable)
library(tidyverse)
library(gridExtra)

# Example dataset. I transformed x to x_lag here, instead of in the model, for transparency.
tibble <- tibble(
  index = 1:46,
  x_lag = c(NA, 9, 32, 43, 46, 50, 48, 51, 46, 44, 40, 42, 40, 38, 
               38, 43, 50 ,49, 42, 39, 36, 32, 33, 34, 34, 33, 36, 39, 
               38, 34, 36, 39, 43, 47, 53, 69, 87, 100, 93, 67, 71, 74,
               92, 79, 73, 73),
  y = c(99, 101, 89, 76.1, 78, 75.9, 77.7, 77.1, 86.7, 80.7, 85, 82.7, 
        88.4, 98.7, 95, 99.9, 88.8, 101, 102, 102, 102, 106, 106, 100,
        97.3, 96, 99.4, 95.3, 92.4, 93.6, 95.7, 93.7, 90.6, 89.4, 92,
        92.7, 81.4, 77, 74.4, 83.1, 79.7, 77.4, 79.6, 67.1, 66.1, 67.1)
)

# Nr of validation weeks to test the model with
val_weeks <- 15

# Classify for training and validation and convert to Tsibble for Fable
tibble <- tibble %>%
  mutate(type = if_else(index > max(index) - val_weeks,
                        "validation", "training")) %>%
  as_tsibble(., index = index)

# Save the training data
tibble_train <- tibble %>%
  filter(type == "training")

# Save the validation data
tibble_val <- tibble %>%
  filter(type == "validation")

# Fit the 2 models, and forecast.
fit_tslm <- tibble_train %>%
  model(TSLM(y ~ x_lag))
fc_tslm <- fit_tslm %>%
  forecast(new_data = tibble_val)

fit_arimax <- tibble_train %>%
  model(ARIMA(y ~ x_lag + pdq(1, 1, 0)))
fc_arimax <- fit_arimax %>%
  forecast(new_data = tibble_val)

tslm_plot <- 
  tibble %>%
  ggplot(aes(x = index, y = y)) +
  autolayer(fc_tslm, alpha = 0.2) +
  geom_line(aes(color = type), alpha = 0.8) +
  geom_line(aes(y = .fitted, color = "Fitted"), data = augment(fit_tslm))

arimax_plot <- 
  tibble %>%
  ggplot(aes(x = index, y = y)) +
  autolayer(fc_arimax, alpha = 0.2) + 
  geom_line(aes(color = type), alpha = 0.8) +
  geom_line(aes(y = .fitted, color = "Fitted"), data = augment(fit_arimax))

grid.arrange(tslm_plot, arimax_plot, nrow = 2)

tslm vs arimax

question from:https://stackoverflow.com/questions/65907616/interpreting-arimax-forecast-in-r-fable

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...