Compare autoregression between groups


Currently I am trying to see if the autoregression is greater in one group compared to another. In the data I have a time series of people (id) rating their positivity (y), we would hypothesise that in a patient group (p) the correlation of positivity at t with t-1 is lower than it is in controls.

I was trying with cor_arr() but couldnt understand how to extract a correlation coefficient for each group (I also noticed that cor_arr() it is to be deprecated).

The dirty hack way I came up with I just modelled the patients and controls separately then got the posterior draws (using posterior_samples()) for arr[1] to compare between groups.

fit.arr.true <- brm(y ~ 1|id,  autocor = cor_arr(~ t|id), data = filter(dat, p==TRUE))

fit.arr.false <- brm(y ~ 1|id,  autocor = cor_arr(~ t|id), data = filter(dat, p==FALSE))

Is there a more ideal way of doing this ?

Also if we were to do this with lagged variables as predictors (as suggested in documentation) then how would we go about this ?

The way I figured was just to add a variable to the data which is y_{t-1} meaning the model would look something as follows with x = y_{t-1}

fit.basic.neg <- brm(y ~ x*p + (x|gr(id, by=p)), data = dat)

Any advice appreciated, it seems like something reasonably common.

Thanks heaps.

  • Operating System: Win 10
  • brms Version: 2.4


First of all, if you use a correlation structure such as cor_ar() or cor_arr() it will assume the autocorrelation to be the same across IDs, so this approach won’t work to get what you want.

The last model you posted seems reasonable to me. To get the auto-correlation for each group, instead of contrasts, you may want to try out 0 + p + p:x instead of x * p.


Sorry for the delay, have been playing around with this and setting the intercept to zero is a great tip !