0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AR(2)モデル

Last updated at Posted at 2023-11-18

AR(2)モデルの基本

AR(2)モデルは以下のように表される。

$$
X_t = \phi_1 X_{t-1} + \phi_2 X_{t-2} + \epsilon_t
$$

ここで、$X_t$は時刻$t$での時系列の値、$\phi_i$は自己回帰係数、$\epsilon_t$は平均がゼ$0$で分散が $\sigma^2$ のホワイトノイズ誤差である。

$X_t$という表記法が一般的であるが、人によっては$X(t)$と書いた方がピンとくるかもしれない。

定常性の条件

AR(2)モデルが定常であることは、特性方程式$t^2 - \phi_1 t - \phi_2 =0$のすべての解の絶対値が$1$より小さいことと同値である。

ユール・ウォーカー方程式

期待値0のAR(p)において自己相関係数とモデルの係数の関係を表した式。以下の$p=2$の場合がよく文献では紹介されている。

時系列モデルでは
$$\gamma_t=Cov[X_0,X_{t}], \enspace \gamma_{|t-s|}=Cov[X_t,X_{s}]$$という様に表し、自己共分散関数と呼ぶことが一般的である。
また、
$$\rho_k=\frac{\gamma_k}{\gamma_0}$$をラグ$k$の自己相関関数と呼ぶ。
このとき、$p=2$の場合のユール・ウォーカー方程式は以下のようになる。

\begin{pmatrix} \phi _{1} \\ \phi _{2}\end{pmatrix}=\begin{pmatrix} 1 & \rho _{1} \\ \rho _{1} & 1 \end{pmatrix}^{-1}\begin{pmatrix} \rho _{1} \\ \rho _{2} \end{pmatrix}

AR(2)モデルのコードの例

import numpy as np
import statsmodels.api as sm
import japanize_matplotlib
import matplotlib.pyplot as plt

# AR(2)モデルのパラメータ。
phi1 = 0.5
phi2 = -0.2
np.random.seed(42)

# 時系列データ生成。
n = 100  # データ点の数。
ar2_data = [0, 0]  # 最初の2つの点は初期値として0を設定。
for i in range(2, n):
    # AR(2)モデルの式に従ってデータ生成。
    x = phi1 * ar2_data[i-1] + phi2 * ar2_data[i-2] + np.random.normal(scale=0.5)
    ar2_data.append(x)

# 時系列データを可視化。
plt.plot(ar2_data)
plt.title('AR(2)モデルの時系列データ')
plt.xlabel('時間')
plt.ylabel('')
plt.show()

# AR(2)モデルのフィッティング
model = sm.tsa.AR(ar2_data)
result = model.fit(maxlag=2)  # AR(2)モデルなので、maxlagは2
print(result.summary())

image.png

線形・ガウス型状態空間モデル

上述の式は以下の様に書くことができる。

\begin{bmatrix} X_{t+1} \\ X_{t} \end{bmatrix}=\begin{bmatrix} \phi _{1} & \phi _{2} \\ 1 & 0 \end{bmatrix}\begin{bmatrix} X_{t} \\ X_{t-1} \end{bmatrix}+\begin{bmatrix} 1 \\ 0 \end{bmatrix}\varepsilon _{t}

よって

Z_t=\begin{bmatrix} X_{t} \\ X_{t - 1} \end{bmatrix}, ~F=\begin{bmatrix} \phi _{1} & \phi _{2} \\ 1 & 0 \end{bmatrix},~G=\begin{bmatrix} 1 \\ 0 \end{bmatrix}

とおけば

$$Z_t=FZ_{t-1}+G\varepsilon _{t}$$

と表すことができる。これは線形・ガウス型状態空間モデルのシステムモデルの特別な場合の式である。
また、

X_{t}=\begin{bmatrix} 1 & 0 \end{bmatrix}\begin{bmatrix} X_{t} \\ X_{t-1} \end{bmatrix}+0

という自明な式は、線形・ガウス状態空間モデルの観測モデルの特別な場合となっており、この2つの式から、AR(2)モデルは線形・ガウス状態空間モデルの特別な場合であることがわかる。

通常、AR(2)モデルのパラメータ推定には頻度主義的手法が一般的に使われるが、状態空間モデルの一例としてAR(2)モデルを考え、その状態空間モデルにベイズ統計学の手法を適用することも可能である。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?