How to incorporate cluster-specific autocorrelation terms in brms?

Hi all! I am wondering how to get cluster-specific autocorrelation terms in brms?

I am interested in conducting time series analyses of data where multiple individuals were measured over time, but don’t know how to specify varying autocorrelation parameters (fixed or random [I know…]) for the individuals. Currently, I find it easy to do an AR(1) model for a single individual:

brm(y ~ 1 + ar(), ...)

But my data consists of multiple individuals (id), and I want them to have their own intercepts and autocorrelation terms. I can specify

brm(y ~ 1 + (1 | id) + ar(gr = id), ...)

but that assumes that the autocorrelation term is identical for all individuals. I can also manually construct a lagged response variable y_lag, and specify

brm(y ~ 1 + y_lag + (1 + y_lag | id), ...)

but unfortunately this would lead to missing data in y_lag.

Presumably I could do something about the missingness in y_lag with mi(), but that doesn’t seem like the best solution either. Alternatively, I could dive into the Stan code of the second model above, and make the ar term a varying effect manually, but it has now been about 3 years since I wrote any Stan and I might have forgotten anything beyond “Hello, one beer please.”

I’d appreciate any thoughts or comments!

PS. Just to see what would happen, I also tried

brm(y ~ 1 + (1 + ar(gr = id) | id) + ar(gr = id), ...)

but this just returned a varying intercepts model, ignoring the ar() call inside the varying effects specification. It might be useful to just fail with an error in this case.

3 Likes

Unfortunately, I don’t think what you need is currently supported in brms, so I think you’d need to go the Stan way…

Best of luck with your model!

1 Like

Thanks @martinmodrak, I thought so as well. I will reluctantly accept your answer as the solution :-)

1 Like