MAモデルの推定
前の演習で生成したシミュレーション系列のうち1つについて、MA(1) のパラメータ \(\small \theta\) を推定します。シミュレーション系列は真のパラメータが分かっているため、実データに適用する前に推定手順を理解するのに最適です。
真の \(\small \theta\) が -0.9 の simulated_data_1 について、\(\small \theta\) の推定値を出力します。さらに、時系列モデルを推定した際に得られる出力全体も表示し、statsmodels で利用できる各種の検定や要約統計量のイメージをつかみます。
この演習はコースの一部です
Pythonで学ぶ時系列解析
演習の手順
- モジュール
statsmodels.tsa.arima.modelからクラスARIMAをインポートします。 - シミュレーションデータ
simulated_data_1と、このモデルの次数 (p,d,q)(この場合は MA(1))としてorder=(0,0,1)を用いて、ARIMAクラスのインスタンスmodを作成します。 - モデル
modをメソッド.fit()で推定し、結果オブジェクトをresという名前で保存します。 - メソッド
.summary()を使って、結果のサマリー全体を出力します。 - 属性
.params[1]を使って、theta パラメータの推定値だけを出力します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# 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.___)