paul-buerkner / brms

brms R package for Bayesian generalized multivariate non-linear multilevel models using Stan
https://paul-buerkner.github.io/brms/
GNU General Public License v2.0
1.27k stars 182 forks source link

More complicated Bayesian structural time series models #148

Closed mrojala closed 6 years ago

mrojala commented 7 years ago

I really like the brms package as it has very nice set of models without a need to manual write the stan code. I'd like to use also bsts models as part of that but currently they are limited to simple forms like bsts(~ t | g). Having for example local linear trends and seasonalities would be great, like in the separate bsts package.

paul-buerkner commented 7 years ago

I agree. Seasonalities are "somehow" possible by adding seasons as factor to the predictor term. It is not the same as a seasonality term as implemented in most ts packages but it comes close in many situations.

How would a "local linear trend" look like in the framework of bsts structures?

mrojala commented 7 years ago

Below is how the bsts package defines the local linear trend in https://cran.r-project.org/web/packages/bsts/bsts.pdf:

2016-11-23_0933

paul-buerkner commented 7 years ago

Thanks! Seems doable. I hope to get this implemented within the next few releases.

paul-buerkner commented 6 years ago

I have been thinking about BSTS models for some time now and decided not to develop brms any further in this direction. Also, I have decided to deprecate the existing intercept only BSTS structure and will remove it from the package at some point.

The reasons for my decision are the following:

1) BSTS structures don't fit well into brms' general framework and code base. In fact they didn't even fit well when implementing them in the first place. Doing so was a mistake I made as an inexperienced software developer, who didn't think it through thoroughly enough. This is visible for instance by my inability to make forecasting work with these models (see #147), because it would have required too much special case coding.

2) These models tend to have serious convergence problems for many data sets at least in the current brms implementation).

3) brms now supports splines and Gaussian processes, which do a fairly good job in replacing (basic) BSTS terms but with much less convergence issues and the immediate ability to do forecasting if desired.

4) The prophet package, which is also based on Stan, seems to be an excellent option for use cases where one would consider applying BSTS structures.

joshualeond commented 6 years ago

First off, @paul-buerkner, thanks for your contribution to the open source world. I just had a comment about your last reason. I don't believe the forecast package has any Stan integration. It looks like almost every model in the forecast package is estimated in a non-bayesian manner.

I'm pretty new to time series analysis and even more so to bayesian modeling but I ran across the following site you may find interesting: https://github.com/nwfsc-timeseries

This group has a few R packages for time series analysis using Stan.

paul-buerkner commented 6 years ago

You are right, I mixed up the names and instead ment the prophet package.