開始使用免費開始

估計 AR 模型

你將估計先前練習中所產生的某個模擬序列的 AR(1) 參數 $\small \phi$。由於模擬序列的參數是已知的,這是在套用到真實資料前,先理解估計流程的好方法。

對於 simulated_data_1,其真實的 \(\small \phi\) 為 0.9,你將列印出 \(\small \phi\) 的估計值。此外,你也會列印出在擬合時間序列時所產生的完整輸出,讓你了解 statsmodels 中還有哪些檢定與摘要統計可用。

本練習屬於課程

Python 中的時間序列分析

檢視課程

練習說明

  • 從模組 statsmodels.tsa.arima.model 匯入 ARIMA 類別。
  • 使用模擬資料 simulated_data_1 建立名為 modARIMA 類別實例,並將模型的 (p,d,q) 順序(此處為 AR(1))設為 order=(1,0,0)
  • .fit() 擬合模型 mod,並將結果儲存到名為 res 的結果物件。
  • 使用 .summary() 方法列印完整的結果摘要。
  • 只列印 \(\small \phi\) 的估計值:使用 .params[1] 屬性(不加括號)。

動手互動練習

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

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

# Fit an AR(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 phi
print("When the true phi=0.9, the estimate of phi is:")
print(res.___)
編輯並執行程式碼