開始使用免費開始

估計簡單移動平均模型

你已經模擬了一些 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)
編輯並執行程式碼