Is there a way to model autocorrelated residuals with non-integer covariates with brms?
Something like autocor = cor_??(~ time | subject), where time is an irregularly spaced continuous covariate. The grouping variable subject also has random intercepts and slopes with respect to the time variable.
Thanks for your time!
One option are continuous autoregressive models, but they are rather complex and not implemented in brms. You can find those in the ctsem package.
How many time values per subject do you have? Any how irregularily spaced are they?
Thanks for the advice regarding ctsem. I am not familiar with it and will check it out.
The data are quite messy, with 14 the median number of measurements per subject (a little over 500 subjects), ranging from 2 to 56. The median amount of time between measurements is 107 days, ranging all the way from 1 to 4500 days.
To make things even more messy, the treatments (4 kinds of anti-diabetes medication) are probably not independent of the response variable (blood glucose level), since the physicians prescribing them must have taken the current glucose level into account.
That’s all manageable with ctsem, for the treatment effect dependency you’d have to use the (new and not well documented) nonlinear estimator, which will slow things down, but if you’ve only one dependent variable then it should still be reasonable. The paper here: https://www.researchgate.net/publication/323457904_Understanding_the_time_course_of_interventions_with_continuous_time_dynamic_models
might give some ideas, and the model spec can be seen in one of the vignettes on CRAN:
The attached script includes an example with an intervention effect, and also conveniently (way down the bottom) includes a state dependent intervention. There’s a few things still in flux at the moment, the github version with rstan 2.18.1 is recommended.
ctsem_script.R (10.3 KB)
Thank you very much, Charles! That sounds very promising and I will check it out.