# Rewriting AR model in State-Space form

How can I rewrite an AR(p) model in state-space form? Max(p)=5 and I want to use Kalman Predictor.

• May I ask what kind of data do you want to model and for what usage you want to do it? – RockScience Nov 24 '10 at 6:35
• Turbulent velocity components (3D) collected by an HR Acoustic Doppler Current Profiler (HRCP) in an estuary. – K-1 Nov 26 '10 at 0:41

I suggest you buy the excellent book by G. Petris, S. Petrone and P. Campagnoli Dynamic Linear Models with R.

You will learn that any ARMA model

$Y_t = \sum_{j=1}^{r}\phi_jY_{t-j} + \sum_{j=1}^{r-1}\psi_{j}\epsilon_t$

can be expressed in the following form:

$\begin{matrix} Y_t & = & F\theta_t\\ \theta_{t+1} & = & G\theta_{t}+R\epsilon_t \end{matrix}$

with $F=\begin{bmatrix} 1 & 0 & ... & 0 \end{bmatrix}$

$G=\begin{bmatrix} \phi_1 & 1 & 0 & ... & 0\\ \phi_2 & 0 & 1 & ... & 0\\ ... & ... & ... & ... & ...\\ \phi_{r-1} & 0 & ... & 0 & 1\\ \phi_r & 0 & ... & 0 & 0 \end{bmatrix}$

$R={\begin{bmatrix} 1 & \psi_1 & ... & \psi_{r-2} & \psi_{r-1} \end{bmatrix}}'$

In your specific case, just set $r=5$ and $\psi_{j=1..5}=0$.
You can use the package dlm to use the Kalman filter on this model.
fRed

• Where can I find help to display the latex formulae! – RockScience Nov 24 '10 at 2:12
• Surround latex with $..$ – user28 Nov 24 '10 at 2:16
• Thanks fRed, first part is quite useful, but as this calculation is a part of much larger code, I cannot use dlm unless it can be linked with Mathematica Kernel. – K-1 Nov 26 '10 at 0:43
• You can use scienceops.com/Rlink2.asp But too bad you have to pay to use R! – RockScience Nov 26 '10 at 2:21

Another good book that covers this is Time Series Analysis by State Space Methods by Durbin and Koopman (pp 46-49.)