估計簡單移動平均模型
你已經模擬了一些 MA 模型並計算了這些模型的 ACF。接下來要用 arima() 指令,把簡單移動平均(MA)模型套用到實際資料上。對於給定的時間序列 x,可以用 arima(..., order = c(0, 0, 1)) 來擬合簡單移動平均(MA)模型。作為參考,MA 模型等同於 ARIMA(0, 0, 1) 模型。
在這個練習中,你會使用已預先載入的時間序列(x,見右側的圖)以及前面章節用過的 Nile 資料集。
本練習屬於課程
R 的時間序列分析
練習說明
- 使用
arima()對序列x擬合 MA 模型。 - 根據
arima()的輸出,填入斜率(ma1)、平均數(intercept)以及創新變異數(sigma^2)的估計值到你的工作區。 - 以類似的
arima()呼叫方式,對Nile資料擬合 MA 模型。將結果存為MA,並用print()顯示輸出。 - 最後,使用已寫好的指令繪製
Nile資料與你擬合的 MA 值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Fit the MA model to x
arima(___, order = ___)
# Paste the slope (ma1) estimate below
# Paste the slope mean (intercept) estimate below
# Paste the innovation variance (sigma^2) estimate below
# Fit the MA model to Nile
MA <- arima(___, order = ___)
print(MA)
# Plot Nile and MA_fit
ts.plot(Nile)
MA_fit <- Nile - resid(MA)
points(MA_fit, type = "l", col = 2, lty = 2)