# Multivariate mixed models in brms

Question1.
May I ask you a question on how to fit multivariate multilevel models with brms? Since this is my first time working with multivariate mixed models, the question might be a little silly.

So, I want to estimate the two equations:

model {
y1~-1+x1+x2+(-1+x1+x2|Id)
y2~-1+x3+x4+(-1+x3+x4|Id)
}


but I also want to allow correlations between all random effects (not only between random effects associated with x1 and x2 or x3 and x4, but also those between (x1,x3), (x1,x4), (x2,x3) and (x2,x4)). I haven’t found how to implement this using brm.

I’ve tried to do this:

model {
bf1<-bf(y1~-1+x1+x2+(-1+x1+x2|Id))
bf2<-bf(y2~-1+x3+x4+(-1+x3+x4|Id))
mvbf(bf1,bf2),
fit1<-brm(mvbf(bf1,bf2), data=.., family=..., iter=...)
}


Question2.
Assume that I want to estimate the following univariate mixed model:
y= \begin{cases} \epsilon, \text{ with probability }\delta\\ -1+x_1+x_2+(-1+x_1+x_2|Id), \text{ otherwise} \end{cases}
i.e., with probability \delta y is only defined by an error term \epsilon; with probability 1-\delta we have a standard linear model:

model {
y~-1+x1+x2+(-1+x1+x2|Id)
}


How this can be implemented using brms?
Moreover, I want to allow \delta varies among groups:

model {
$\delta$~1+(1|Id)
}


Thanks a lot!

1 Like

Sorry for not getting to you earlier, your question is relevant and well written.

If I understand your question 1 correctly, a partial solution would be to use this syntax:

y1 ~ ... (-1 + x1 + x2 | q | Id)
y2 ~ ... (-1 + x3 + x4 | q | Id)


The q is an arbitrary string that indicates that the two terms share a correlation structure (i.e. it doesn’t matter what you put between the pipes, just that it is the same in both cases).

For question 2 - this looks like a mixture model which are supported by brms and you can put different predictors for both components and for the mixing probability. Check out the docs for more details, but feel free toask clarifying questions here if you have trouble using it.

Best of luck with your model!