Hello, I am setting up a multivariate model in brms. The data consists of subjects who received treatment at 4 different time points. Due to the nature of the data, the resp_subset function was used to subset out the different time periods resulting in 4 response variables (Group1_response_value, Group2_response_value, etc), two predictor variables (our time variable, TimeVar and another, var2) and a group level effect for the subject intercept (1|p|study_participant).
The generic model code used was:
bf(Group1_response_value | resp_subset(sub1) ~ TimeVar_group1 + var2 + (1|p|study participant)) +
bf(Group2_response_value | resp_subset(sub2) ~ TimeVar_group2 + var2 + (1|p|study participant)) +
bf(Group3_response_value | resp_subset(sub3) ~ TimeVar_group3 + var2 + (1|p|study participant)) +
bf(Group4_response_value | resp_subset(sub4) ~ TimeVar_group4 + var2 + (1|p|study participant)))
Model <- brm(bform_1, df)
This code produced an expected outcome but -due to the nature of our data, we would like to model the parameters on each TimeVar (between each univariate model, so TimeVar_group1, TimeVar_group2, etc) as correlated. I’ve read through the vignettes and the updated documentation from Nov 2020 and can’t find a function that will do this. I’ve seen in the brms formula vignette that we can indicate correlation between group level terms by “using || instead of |. All group-level terms sharing the same ID will be modeled as correlated”. Is there a way to do something similar to this for our population level regression parameter- and also indicate it would be for just one of the predictor terms?
Operating System: Windows 10, 64-bit
R version 4.0.3, brms version 2.14.4
Multivariate correlations can be challenging. There are actually many ways to build them which are not equivalent - and I admit to not understand their different implications very well.
If you have a normal response, you can use
+ set_rescor(TRUE) which model the residuals as correlated.
You could also introduce a dummy variable as in Model both response and between group correlations - multivariate brms
Also, maybe it would be easier to move your data to a long format and then have:
bf(response ~ TimeVar * group + var2 * group + (group | study participant))
Which should give you (almost) identical model but one that is easier to work with… You could then simply add some correlation structure by replacing
TimeVar * group with
(TimeVar | group)
Hope that helps at least a bit!
@martinmodrak thank you very much for your response/advice! Apologies it took me a few days to respond- I wanted to try out all your solutions before responding (and I’m pretty new to Bayesian methods/brms). Turning my df from wide to long and using your syntax below appears to be giving the proper output:
brm(response ~ TimeVar * group + var2 * group + (group | study participant))
It didn’t work when I used
bf for some reason.
The initial reasoning for making the df wide and using a multivariate syntax is because the goal is to add on a nonlinear component to the model to modify the way the decay rate (our coefficient on the TimeVar) is handled. We are hoping to add on NL Weibull decay curve (that will resemeble 1- a Weibull culmulative distribution function). The issue is our grouping variable is a 4-level factor and I know that this is not allowed in a nonlinear formula. I have read through the forums and github issues (particularly 46 and 47 . The now closed issue stated this can be bypassed using
Give a name to the linear part of a nonlinear model in the
formula argument of
brm and to define it in the
I’ve read through the most recent guide I can find for brms (Nov 2020) but can’t seem to find any examples of how this can be done. Are you aware of somewhere I can find more resources on using this syntax correctly?
Thank you again very much!
Honestly not sure, I’ve never done this myself. I would recommend you post this as a new topic to get more eyes on it (as this is marked as solved, most people providing help here would skip it).
Best of luck with your model!
@martinmodrak thank you for your time regardless! Much appreciated.