估計自我迴歸(AR)模型
對於時間序列 x,可以使用 arima() 指令並將 order 設為 c(1, 0, 0) 來配適自我迴歸(AR)模型。供你參考,AR 模型等同於 ARIMA(1, 0, 0) 模型。
在本練習中,你將透過在模擬時間序列 x 以及 AirPassengers 資料上練習 arima() 指令,來探索 AR 模型的更多特性。這個指令可讓你找出模型的估計斜率(ar1)、平均數(intercept),以及創新變異數(sigma^2)。
x 與 AirPassengers 資料都已預先載入你的環境。右側圖中顯示的是時間序列 x。
本練習屬於課程
R 的時間序列分析
練習說明
- 使用
arima()對序列x配適 AR 模型。仔細檢視此指令的輸出。 - 從上一個指令的結果中,斜率(
ar1)、平均數(intercept),以及創新變異數(sigma^2)的估計值分別為何?請將它們輸入到你的 R 工作區中。 - 接著,對
AirPassengers配適 AR 模型,並將結果儲存為AR。使用print()顯示配適後的模型AR。 - 最後,使用提供的指令繪製
AirPassengers、計算配適值,並將配適值加入圖中。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Fit the AR model to x
arima(___, order = ___)
# Copy and paste the slope (ar1) estimate
# Copy and paste the slope mean (intercept) estimate
# Copy and paste the innovation variance (sigma^2) estimate
# Fit the AR model to AirPassengers
AR <-
print(AR)
# Run the following commands to plot the series and fitted values
ts.plot(AirPassengers)
AR_fitted <- AirPassengers - residuals(AR)
points(AR_fitted, type = "l", col = 2, lty = 2)