# Multivariate modelling using brms

**URL:** <https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588>\
**Category:** brms\
**Tags:** specification\
**Created:** [April 24, 2020, 9:29pm UTC](https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588 "2020-04-24T21:29:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bharat\_Parthasarathy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bharat_parthasarathy/32/7828_2.png) [@Bharat\_Parthasarathy](https://discourse.mc-stan.org/u/Bharat_Parthasarathy)\
**Post date:** [April 24, 2020, 9:29pm UTC](https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588/1 "2020-04-24T21:29:49Z")

</div>

I’m trying to find the correlation between “boldness” and “aggression” - what is known as a behavioural syndrome. One of the methods is to fit a multivariate mixed model with boldness and aggression as response variables, and see how much of correlation is partitioned among “between-individuals” vs. “within-individuals”. Boldness (continuous response variable) and aggression (ordinal ranks) were repeatedly assayed on 320 animals (ID) from 12 colonies (colonyID). As individual animals are not independent from their colonies, ID has to be nested within colonyID.

The question is if I can fit a multivariate model with two different response distributions? If I understand correctly, the vignette says different families can be specified as a list. However, when I tried the following formula,

mod\<-brm(mvbind(Boldness,Aggression)~Trial+(1|ID/colony),family = c(gaussian,sratio),data=mydata,chains=2,cores=2)

I get the following error message " Error: Argument ‘family’ is invalid".

I’m unable to find an example in the internet where two different response variables with different error structures are used. Or maybe I’m missing something, so I might need a fool’s guide…

My second question is if I can use the brms package to partition the co-variances into between-individual and among-individual variances and co-variances? This has often been done using MCMCglmm, but I would like to use brms because I feel this package is easier to use and easier to diagnose the model. Any help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![torkar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/torkar/32/1355_2.png) [@torkar](https://discourse.mc-stan.org/u/torkar)\
**Post date:** [April 25, 2020, 8:36am UTC](https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588/2 "2020-04-25T08:36:52Z")

</div>

Hi

```
> ?brmsformula

```

And here’s the example :)

```
# specify a multivariate model using the '+' operator
bf(y1 ~ x + (1|g)) + 
  gaussian() + cor_ar(~1|g) +
  bf(y2 ~ z) + poisson()
``
```

---

<div class="post-metadata">

**Author:** ![Bharat\_Parthasarathy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bharat_parthasarathy/32/7828_2.png) [@Bharat\_Parthasarathy](https://discourse.mc-stan.org/u/Bharat_Parthasarathy)\
**Post date:** [April 25, 2020, 5:54pm UTC](https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588/3 "2020-04-25T17:54:23Z")

</div>

Hi @torkar

Thanks for the pointer. I tried running the model as you suggested:

“mod\<-brm(bf(Boldness~Trial+(1|uniqueID))+gaussian()+cor\_ar(~1|uniqueID)+bf(Aggression~Trial+(1|uniqueID))+categorical(),data=mydata)”

But got the following error message: “Error: ARMA models are not implemented for family ‘categorical’”

My second response variable, namely “Aggression” is in the ordinal scale…

---

<div class="post-metadata">

**Author:** ![paul.buerkner](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/paul.buerkner/32/3303_2.png) [@paul.buerkner](https://discourse.mc-stan.org/u/paul.buerkner)\
**Post date:** [May 11, 2020, 1:01pm UTC](https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588/4 "2020-05-11T13:01:30Z")

</div>

In the github version of brms, you can now specify AR terms inside the formula, that is `Boldness~Trial+(1|uniqueID) + ar(gr = uniqueID, p = 1)` in your case. Then, the error should no longer appear.

---

<div class="post-metadata">

**Author:** ![Bharat\_Parthasarathy](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bharat_parthasarathy/32/7828_2.png) [@Bharat\_Parthasarathy](https://discourse.mc-stan.org/u/Bharat_Parthasarathy)\
**Post date:** [May 14, 2020, 6:42pm UTC](https://discourse.mc-stan.org/t/multivariate-modelling-using-brms/14588/5 "2020-05-14T18:42:06Z")

</div>

Thanks Paul. This solves the problem.
