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!

# Marginalization of latent states dynamic linear models

**Nate_Garton**#3

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?

**Nate_Garton**#5

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

**bgoodri**#6

There are almost 23,000

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

**Nate_Garton**#7

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.