State space modelling in brms time series

Dear Stan users,

Me and my supervisor currently have a project that involves forecasting of time series. The process is quite simple, it’s a univariate time series of interest spread, which the noise follows ARMA(1,2) model.

I have a very quick question regarding the technical details behind brms time series. We have gone through a paper from Chib & Greenberg about the time series and state-space model for ARMA(p,q) model, and derived mathematically the whole error/noise to follow a state specification of ARMA(1,2).

The current model we have for simple one is:
y_t = mu_0 + e_t
e_t = ar1 + ma1 + ma2 + u_t

where both e_t and u_t follow normal/gaussian process. In other words, this is just a LGSSM model.

Hence, I tried to seek some packages that might help in modeling my time series, and apparently, your package brms allow time series ARMA modeling in a very clean and easy way! However, to clarify, my analysis requires to use of state-space specification that follows ARMA(1,2). I am putting these on the forum to clarify whether brms package follows Kalman Filter smoothing, filtering, etc in time series to fit the ARMA(1,2) model?

I had a quick read about the CRAN pdf, and I cannot find anything about state-space specifications or Kalman Filter. Hence, I just wanted to clarify this!



Hello there, you can check

A package special for univariate time series models and forecasting, in there I use Kalman filters for estimate residuals, likelihood and predictive values.

Sadly I still don’t have an interface for DLM that could perform what you need to estimate the equivalent model, for that you can use:

That fits the DLMs using a Metropolis sampler. Also you can try to build the model in Stan, is not that hard I can help u with that. But also check the equations, there is something in the DLM that bothers me.


1 Like

Hi Asael!
Thanks for your reply.

I did gave a try in bsts, and contacted the author regarding my specific model and unfortunately bsts model doesn’t allow MA (moving average) to be modelled yet.

I might… try to code myself (however I’m no stan wizard… hence I’ve been looking for another packages to run and fit my model)

Would it be okay if I seek for your advice through your email next time? I’ll email you or I’ll post another question on Stan :)



1 Like


For state-space models I like the dynr package, but it does not do Bayesian
The other one i recommend is the ctsem package. This one does not do state space modelling, but applies stochastic differencial equations for continues time models. It estimates frequentist models with OpenMx and Byesian with Stan. Havent tried the ARMA models, but I think you should be able to estimate them here

A state space model is (as far as I’ve ever been aware!) just the combination of a latent / hidden / not directly observed process model, and a measurement model for this. ctsem does discrete and continuous time versions of this, linear / nonlinear, with frequentist, ‘full Bayes’, and some options in the middle available. In the hierarchical (multiple subjects with varying parameters) setting, HMC is in many cases just too slow (given the current stan code).

The use of a stochastic measurement layer changes the nature of the ARMA models quite a bit – an AR1 process without measurement error is only conditionally dependent on the previous observation (and parameters), but once measurement error is included it is dependent on all preceding observations.

1 Like

Yes please feel free to contact :)


Yes, you’re right. The MA part is a bit tricky, especially the initial errors (epsilon_0, etc) being dependent across parameters. I’m actually currently doing my analysis using dlm package, have a look and it might interest you too!