Group random effects for two between-subject factors

Hello!

I’m aware of the usage of gr() to estimate seperate variance-covariance matrices for each level of a between-subject factor as per here. Using the third example there,

fit3 <- brm(count ~ Trt + (1|gr(patient, by = Trt)), data = epilepsy)

What if I have another between-subject variable (say, COND with 2 levels) that I want to include in the ‘by’ argument so that I can estimate four unique variance-covariance matrices (i.e., Trt0+COND1, Trt0+COND2, Trt1+COND1, and Trt1+COND2). Would it just be the below?

fit3 <- brm(count ~ Trt + (1|gr(patient, by = Trt + COND)), data = epilepsy)

Thank you!

I suggest you add a new variable with four levels to your dataset, combining the levels of Trt and COND, which you can then pass to the by argument.

Thanks Paul, was thinking along those lines so good to know that is what you’d suggest. Leading on from that, I was curious to know your thoughts on whether it would be fine to do the model call below,

fit3 <- brm(count ~ Trt * COND + (1|gr(patient, by = Trt_COND)), data = epilepsy)

Or does it need to be,

fit3 <- brm(count ~ Trt_COND + (1|gr(patient, by = Trt_COND)), data = epilepsy)