Marginalization of latent states dynamic linear models

I’m trying to find information on how Stan goes about marginalizing over the latent states when using the gaussian_dlm_obs sampling statement. I’ve found some documentation on state space models in Stan by Jeffrey Arnold, and I’ve attached the link. Though it contains a lot of useful theory and information on functions that I assume are used by the gaussian_dlm_obs statement, I haven’t been able to find any sources detailing specifically how Stan deals with this integration. Any sources or explanations would be sincerely appreciated!

I think it is just the Kalman Filter

From what I understand, the Kalman filter (in a dynamic linear model context) gets you the distribution of the latent state at time t given the observed data up to and including time t and fixed system error and observation error covariance matrices. Does Stan just marginalize out the latent states through some big matrix calculations based on normal distribution theory?

Yes, you can also build up the (log) PDF.

Okay, thanks a ton for the help! You wouldn’t happen to know any sources that explicitly cite this do you?

There are almost 23,000

https://scholar.google.com/scholar?cites=5225957811069312144&as_sdt=5,33&sciodt=0,33&hl=en

Yeah, thanks. I’m familiar with sources describing the Kalman filter/DLMs/state-space models. I was hoping for a source that explicitly mentions how Stan does the marginalization. I didn’t know if there was more than one way, through simulation, to skin this cat because I know that some implementations of the Kalman filter suffer from stability issues, for example.

I remember the Stan implementation can fail if some matrix is only positive semi-definite rather than positive definite (and even in that case, it could be numerically indefinite). There are more general equations that handle the positive semi-definite case. @jrnold would know more.

1 Like

Jeffrey Arnold wrote a Kalman filter tutorial in Stan: