10.3 Parameter Estimation in State-Space Models


{Estmu,EstF,EstQ,EstR} = 20357 kem (ar2,x0,Sig,H,F,Q,R,Limit)
provides estimations of $ \mu$, $ F$, $ Q$ and $ R$ in a state-space model using the EM-algorithm

As stated in the previous paragraphs, some of the matrices may be unknown. In a usual application, the matrix $ H$ and the covariance matrix $ \Sigma$ of the initial state may be assumed known. Shumway and Stoffer (1982) have proposed an EM-algorithm for the iterative estimation of the unknown parameters $ \mu$, $ F$, $ Q$ and $ R$.

The algorithm is derived under the assumption of Gaussian error terms. Then the logarithm of the likelihood function is expressed as

$\displaystyle \ \log L$ $\displaystyle =$ $\displaystyle -\frac{1}{2} \log \mid \Sigma \mid
\ - \frac{1}{2} (x_0 - \mu)^T \Sigma^{-1} (x_0 - \mu)$  
$\displaystyle \ $   $\displaystyle -\frac{T}{2} \log \mid R \mid
- \frac{1}{2} \sum_{t=1}^T (x_t - F x_{t-1})^T R^{-1} (x_t - F x_{t-1})$  
    $\displaystyle -\frac{T}{2} \log \mid Q \mid
- \frac{1}{2} \sum_{t=1}^T (y_t - H_t x_t)^T Q^{-1} (y_t - H_t x_t).$  

In the $ r$th E-step of the algorithm, the conditional expectation

$\displaystyle \ G_r(\mu,F,R,Q) = E (\log L \mid Y_T)
$

is derived using $ \widehat{x}_{t \mid T}$ and $ P_{t \mid T}$ taken from Kalman recursions for smoothing used with parameters estimated in the previous step of the algorithm. In the $ r$th M-step of the algorithm, the parameter estimates that maximize the function $ G_r(\mu,F,R,Q)$ are taken. These values are used in the next E-step. The EM-algorithm provides estimates that converge to stable solutions. However, depending on initial values used in the first step of the algorithm, this solution may be a local maximum of the likelihood function. It is therefore recommended to try to run the algorithm with several different initial values. Please note that the algorithm sometimes converges to the stable solution quite slowly.

This algorithm is implemented in XploRe by the quantlet 20364 kem . The input parameters are almost the same as in the functions for Kalman filtering and smoothing, although the values of $ \mu$, $ F$, $ Q$ and $ R$ are used as initial values for the first step of the EM-algorithm. The last parameter of the quantlet is the maximum number of iterations allowed. This quantlet returns estimated parameters $ \mu$, $ F$, $ Q$ and $ R$ (in this order).

To run this quantlet on the ar2 series and view the estimates, you can use the following sample code. Please note that depending on your system the processing may take a while.

  x0 = #(0,0)
  Sig = #(0,0)~#(0,0)
  H = 1~0
  F = #(5,1)~#(1,5)
  Q = 10
  R = #(1,0)~#(0,1)
  {Estmu, EstF, EstQ, EstR} = kem(ar2,x0,Sig,H,F,Q,R,20)
  Estmu
  EstF
  EstQ
  EstR
20368 XLGkalm04.xpl

The state-space model proposed by the EM-algorithm should be similar to the following one (the numbers may differ for your particular ar2 series).

  Contents of Estmu
  [1,] -0.049532 
  [2,]  0.011073 
 
  Contents of EstF
  [1,]  0.59788  0.060844 
  [2,]  0.73477   3.7628 
 
  Contents of EstQ
  [1,]   3.7002 
 
  Contents of EstR
  [1,]  0.20202 -0.031133 
  [2,] -0.031133  0.76948


20374

Note that not knowing the particular shape of the system matrices (i.e. the zero element in $ F$, for example) the quantlet proposed its own state-space model. There are several works that generalize the EM-algorithm so that it allows us to have some elements of the unknown matrices fixed or to apply some linear constraints on them. You may, for example, refer to the article Hosking, Pai and Wu (1996). The implementation of these modifications in XploRe , based on the quantlet 20380 kem , should be straightforward.