I know the Kalman filter recursions and can derive these but what I don't really get is how to estimate the hyper parameters using maximum likelihood.

I understand that when running the Kalman filter we get the prediction error and its variance which can be used the construct the likelihood function.

What I don't really get is the order these steps are done in. Am I supposed to:

Method 1

1) Run the Kalman filter given arbitrary starting values and obtain the likelihood function.

2) Maximize the likelihood function wrt to the hyper parameters of the model.


Method 2

1) Estimate the hyper-parameters of the state space model using maximum likelihood.

2) Run the Kalman filter with the hyper-parameters set at these estimates.

I found this question which answers what I need: LogLikelihood Parameter Estimation for Linear Gaussian Kalman Filter. Here the hyper parameters are estimated from the likelihood function and that is the same as the algorithm on p. 8 top in these lecture notes specifies. However, in the same notes it is written (p. 10 mid): "Given a set of optimal parameter values, $\theta_{ML}$, it is now worth to explore the paths of unobserved components...".

Is the correct way to conduct the analysis the following?

Method 3

1) Run the Kalman filter given arbitrary starting values and obtain the likelihood function.

2) Maximize the likelihood function wrt to the hyper parameters of the model.

3) Run the Kalman filter again using the ML estimates obtained in step 2). Use these state estimates in the following analysis?

  • $\begingroup$ Method 2 seems the most reasonable to me: first estimate the parameters of the model by maximum likelihood (as explained in the post that you linked); then, given the optimal set of parameters found by the optimization algorithm, run the Kalman filter or smoother to get an estimate of the state vector. $\endgroup$
    – javlacalle
    Commented Jun 7, 2016 at 6:58
  • $\begingroup$ I'm not sure what you are referring with hyper-parameters. In the context of the model defined in section 2.1 of the document that you link, I would distinguish two elements: 1) the parameters to be estimated by ML, i.e., the variances ($\sigma^2_v$, $\sigma^2_w$, $\sigma^2_e$), and 2) the state vector (latent variables or unobserved components), which are the trend $n_t$, the stochastic drift $g_t$ and the cycle $x_t$. The estimates of the latter should be obtained after having estimated the variances by ML. $\endgroup$
    – javlacalle
    Commented Jun 7, 2016 at 6:59
  • $\begingroup$ Thanks for the comment. By hyper-parameters I mean the parameters determining the stochastic properties of the state vector and the variance parameter. I think method 3 is right (correct me if I am wrong). One sets initial values. Runs the Kalman filter and obtains a likelihood function. Uses these parameter estimates instead of the initial values and runs the Kalman filter again. This process is then continued until convergence. Is this correct? $\endgroup$
    – Plissken
    Commented Jun 15, 2016 at 20:00
  • 2
    $\begingroup$ I assume you are updating the parameters at each stage by means of an optimization algorithm, in that case the process seems reasonable to me. $\endgroup$
    – javlacalle
    Commented Jun 17, 2016 at 20:20

2 Answers 2


We need to first clarify things here. The original derivation of Kalman filter is optimal for causal predictions. That means you predict at time $t$ given observations until time $t$.

Now for the maximum likelihood (ML) inference of parameters, assuming that these parameters are shared across time, during inference of hidden state variables you need to use the non-causal version of Kalman filter, that is the forward-backward Kalman filter (RTS smoothing).

After that you carry out ML estimation as usual. This is an instance of the well-known Expectation-Maximization algorithm, applied within the context of Kalman Filtering as early as 1982! Therefore it is iterative, and you do not necessarily arrive at a global optimum. As typical with these models, starting from a sensible values of hyperparameters first and running the forward-backward algorithm thereon will give better results. This is the case with most Bayesian models that result in non-convex objective functions (EM, Variational Inference, ...).

For further reference, check Appendix A.3 of the review paper by Roweis and Ghahramani: https://authors.library.caltech.edu/13697/1/ROWnc99.pdf


I could be wrong, but what makes sense to me is this:

  1. define a function for the kalman filtering and prediction. Make that output the log likelihood (using v and the covariance matrix of v). The log likelihood in this case is described in the stack exchange post you refer to. Make sure Q, R, mu_0 and A are free parameters
  2. Optimize the function with respect to those parameters by maximizing the log likelihood.

Essentially yes, the underlying optimization procedure will start with random parameter values but from there it will optimize the parameters to fit the observables. I don't see how you can estimate these parameters first and then do the kalman filter.

Source: https://faculty.washington.edu/eeholmes/Files/Intro_to_kalman.pdf


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.