I am trying to use JAGS to deal with the following multivariate state space model.

$Y_t=X_ttheta_t+epsilon_t$

$theta_t=theta_{t-1}+nu_t$

JAGS code is neat but JAGS is running too slow when I am monitoring several hundred variables in the model. I decide to use forward filtering backward sampling algorithm (FFBS) to write my own code. I am wondering how JAGS deals with state space model and whether FFBS is more effcient than JAGS.

**Contents**hide

#### Best Answer

Section 6 of the Stan reference guide (https://github.com/stan-dev/stan/releases/download/v2.4.0/stan-reference-2.4.0.pdf) describes coding various time-series models. Stan is pretty similar to JAGS. I have used JAGS for Hidden Markov Models with mixed results–pretty slow and I'm not 100% sure of what is "going on under the hood" at times. Given I haven't really done any state space modeling in Stan I can't vouch for it. But they've got some incredible people working on it (Gelman, Carpenter, etc.) so I'm hopeful. Anyways, hope this helps.

Depending on the complexity of your model, you could use the `dlm`

package in `R`

. It's pretty user-friendly for standard linear Gaussian state space models (i.e., dynamic linear models). It also allows for both MLE and Bayesian MCMC, which is nice.

### Similar Posts:

- Solved – Doing MCMC: use jags/stan or implement it theself
- Solved – Methods of fitting a dynamic linear model
- Solved – Modeling multivariate Time Series Count Data in R
- Solved – How would you convert an $ARIMA(0,1,1)(0,1,1)_{12}$ model to equation form
- Solved – rjags does not seem to use initial values specified