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