brms icon indicating copy to clipboard operation
brms copied to clipboard

Feature Request: AR correlation structure for random effects

Open davibf11 opened this issue 2 years ago • 3 comments

Hello,

First and foremost, thank you for all of the excellent work that's done here! brms is an excellent package and really helps decrease dependence on working in base stan, which is helpful when working with others (as fun as it is to pick through thousands of lines of a complicated model...).

One feature that I think would be really helpful for brms to be able to implement would be to allow for AR correlation structures within random effects. This is something that I do frequently in base stan when working with data that has groups that are ideal to pool information over, and which also has multiple observations over multiple time periods.

I've put together an example script (and stan code) together here to give an idea about what I'm talking about. This is different from the stan models that I usually use - I modified it to try to use a lot of similar code to what brms usually outputs. Essentially, we'd be fitting the following model:

y ~ 1 + (ar(time, p = 1) | group)

The correlation structure is achieved using a pretty straightforward spectral decomposition. This allows for each group to have a separate random effect for each time period with the specific correlation structure. I'm sure there's a more intuitive way to set this up in brms to allow for users to set different p values, but I figured I would put something together to give an idea of what I'm talking about. Let me know if this doesn't make sense, or if there's anything else I can do to clarify!

davibf11 avatar Mar 03 '22 18:03 davibf11

This would be a very welcome addition. glmTMBB has a natural implementation of many of these structures which seem to work (exclusively?) at the group level, and anything from the lme4 group is usually a good start. https://cran.r-project.org/web/packages/glmmTMB/vignettes/covstruct.html

bachlaw avatar Mar 14 '22 12:03 bachlaw

Possibly related to this issue https://github.com/paul-buerkner/brms/issues/1025

jackobailey avatar Jun 06 '22 09:06 jackobailey

As a Bayesian example would probably be more helpful, INLA accommodates this through their notation: y ~ 1 + f(time, replicate=group_idx, model='ar', order = 1). However, it is possible this is simply more straightforward to do through a latent Gaussian model.

bachlaw avatar Jul 17 '22 18:07 bachlaw