開始使用免費開始

估計 MA 模型

你將估計先前練習中所產生之其中一組模擬序列的 MA(1) 參數 $\small \theta$。由於模擬序列的參數是已知的,在套用到真實資料之前,這是了解估計流程的好方法。

對於 simulated_data_1,其真實 \(\small \theta\) 為 -0.9,你將印出 \(\small \theta\) 的估計值。此外,當你對時間序列進行擬合時,還會印出整個輸出的內容,讓你了解在 statsmodels 中還有哪些檢定與摘要統計可用。

本練習屬於課程

Python 中的時間序列分析

檢視課程

練習說明

  • 從模組 statsmodels.tsa.arima.model 匯入類別 ARIMA
  • 使用模擬資料 simulated_data_1 建立名為 modARIMA 實例,並指定模型的 (p,d,q) 次數(本題為 MA(1)),也就是 order=(0,0,1)
  • 使用 .fit() 方法擬合模型 mod,並將結果儲存為名為 res 的結果物件。
  • 使用 .summary() 方法列印完整的結果摘要。
  • 僅列印 theta 參數的估計值,使用 .params[1] 屬性。

動手互動練習

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

# Import the ARIMA module from statsmodels
from statsmodels.tsa.arima.model import ARIMA

# Fit an MA(1) model to the first simulated data
mod = ARIMA(___, order=___)
res = mod.___

# Print out summary information on the fit
print(res.___)

# Print out the estimate for the constant and for theta
print("When the true theta=-0.9, the estimate of theta is:")
print(res.___)
編輯並執行程式碼