開始使用免費開始

使用 ARIMA 模型進行預測

前一題的自動方法為 austa 資料選出了帶有 drift 的 ARIMA(0,1,1) 模型,也就是: \(y_t = c + y_{t-1} + \theta e_{t-1} + e_t.\) 現在你將針對此資料嘗試不同的 ARIMA 模型,看看對預測有什麼影響。

Arima() 函式可用來指定特定的 ARIMA 模型。它的第一個引數 order 設為一個向量,用來指定 $p$、$d$、\(q\) 的數值。第二個引數 include.constant 是布林值,用來決定是否納入常數 $c$(也稱為 drift)。以下是透過管線運算繪製來自帶有 drift 的 ARIMA(2,1,2) 模型之 usnetelec 預測的範例:

> usnetelec %>%
    Arima(order = c(2,1,2), include.constant = TRUE) %>%
    forecast() %>%
    autoplot()

在以下範例中,請留意不同模型如何影響預測與信賴區間。austa 資料已在你的工作環境中就緒,可直接使用。

本練習屬於課程

R 的時間序列預測

檢視課程

練習說明

  • 繪製不含 drift 的 ARIMA(0,1,1) 模型預測。
  • 繪製含有 drift 的 ARIMA(2,1,3) 模型預測。
  • 繪製含有常數的 ARIMA(0,0,1) 模型預測。
  • 繪製不含常數的 ARIMA(0,2,1) 模型預測。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Plot forecasts from an ARIMA(0,1,1) model with no drift
austa %>% Arima(order = c(___, ___, ___), include.constant = ___) %>% ___ %>% ___

# Plot forecasts from an ARIMA(2,1,3) model with drift
austa %>% Arima(___, ___) %>% ___ %>% ___

# Plot forecasts from an ARIMA(0,0,1) model with a constant
austa %>% Arima(___, ___) %>% ___ %>% ___

# Plot forecasts from an ARIMA(0,2,1) model with no constant
austa %>% Arima(___, ___) %>% ___ %>% ___
編輯並執行程式碼