I have written some code that can do Kalman filtering (using a number of different Kalman-type filters [Information Filter et al.]) for Linear Gaussian State Space Analysis for an n-dimensional state vector. The filters work great and I am getting some nice output. However, the parameter estimation via loglikelihood estimation is confusing me. I am not a statistician but a physicist, so please be kind.

Let us consider the linear Gaussian State Space model

yt=Ztαt+ϵt,

αt+1=Ttαt+Rtηt,where yt is our observation vector, αt our state vector at time step t. The quantities in bold are the transformation matrices of the state space model which are set according to the characteristics of the system under consideration. We also have

ϵt∼NID(0,Ht),

ηt∼NID(0,Qt),

α1∼NID(a1,P1).where t=1,…,n. Now, I have derived and implemented the recursion for the Kalman Filter for this generic state space model by guessing the initial parameters and variance matrices H1 and Q1 I can produce plots like

where the points are the Nile River water levels for Jan over 100 years, the line is the Kalamn Estimated state, and the dashed lines are the 90% confidence levels.

Now, for this 1D data set the matrices Ht and Qt are just scalars σϵ and ση respectively. So now I want to get the correct parameters for these scalars using the output from the Kalman Filter and the loglikelihood function

logL(Yn)=−np2log(2π)−12n∑t=1(log|Ft|+vTtF−1tvt)

Where vt is the state error and Ft is the state error variance. Now, here’s where I am confused. From the Kalman filter, I have all the information I need to work out L, but this seems to get me no closer to being able to calculate the maximum likelihood of σϵ and ση.

My question is how can I calculate the maximum likelihood of σϵ and ση using the loglikelihood approach and the equation above?An algorithmic break down would be like a cold beer to me right now…Thanks for your time.

Note. For the 1D case Ht=σ2ϵ and Ht=σ2η. This is the univariate local level model.

**Answer**

When you run the Kalman filter as you have, with given values of

σ2ϵ and σ2η, you get a sequence of innovations

νt and their covariances \boldsymbol{F_t}, hence you can calculate the value of \log L(Y_n) using the formula you give.

In other words, you can regard the Kalman filter as a way to compute an implicit function of \sigma_\epsilon^2 and \sigma^2_\eta. The only thing that you need to do then is to package this computation into a function or subroutine and handle that function to an optimization routine –like `optim`

in R. That function should accept as inputs \sigma_\epsilon^2 and \sigma^2_\eta and return \log L(Y_n).

Some packages in R (e.g. `dlm`

) do this for you (see for instance function `dlmMLE`

).

**Attribution***Source : Link , Question Author : MoonKnight , Answer Author : F. Tusell*