自己回帰(AR)モデルを推定する
与えられた時系列 x に対して、arima() コマンドを使い、order を c(1, 0, 0) に設定すると自己回帰(AR)モデルを当てはめられます。参考までに、ARモデルは ARIMA(1, 0, 0) モデルに相当します。
この演習では、シミュレーションした時系列 x と AirPassengers データに対して arima() コマンドを使い、ARモデルの特性をさらに確認します。arima() は、推定された傾き(ar1)、平均(intercept)、およびイノベーション分散(sigma^2)を確認するのに役立ちます。
x と AirPassengers データはどちらも環境に読み込まれています。時系列 x は右側の図に表示されています。
この演習はコースの一部です
Rで学ぶ時系列分析
演習の手順
arima()を使って系列xに ARモデルを当てはめてください。出力結果をよく確認しましょう。- 直前のコマンドの出力から、傾き(
ar1)、平均(intercept)、イノベーション分散(sigma^2)の推定値は何ですか? それらをRワークスペースに入力してください。 - 次に、
AirPassengersに ARモデルを当てはめ、結果をARとして保存します。print()を使って当てはめたモデルARを表示してください。 - 最後に、用意されたコマンドを使って
AirPassengersをプロットし、当てはめ値を計算して、図に追加してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Fit the AR model to x
arima(___, order = ___)
# Copy and paste the slope (ar1) estimate
# Copy and paste the slope mean (intercept) estimate
# Copy and paste the innovation variance (sigma^2) estimate
# Fit the AR model to AirPassengers
AR <-
print(AR)
# Run the following commands to plot the series and fitted values
ts.plot(AirPassengers)
AR_fitted <- AirPassengers - residuals(AR)
points(AR_fitted, type = "l", col = 2, lty = 2)