# Residual covariance (brms mutlivariate model in long format)

**URL:** <https://discourse.mc-stan.org/t/residual-covariance-brms-mutlivariate-model-in-long-format/17381>\
**Category:** brms\
**Created:** [August 11, 2020, 8:37pm UTC](https://discourse.mc-stan.org/t/residual-covariance-brms-mutlivariate-model-in-long-format/17381 "2020-08-11T20:37:23Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Max\_Mantei](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/max_mantei/32/7912_2.png) [@Max\_Mantei](https://discourse.mc-stan.org/u/Max_Mantei)\
**Post date:** [August 18, 2020, 10:33am UTC](https://discourse.mc-stan.org/t/residual-covariance-brms-mutlivariate-model-in-long-format/17381/4 "2020-08-18T10:33:30Z")

</div>

Just skimmed through the other thread. I think you are already almost doing the correct thing. Keep in mind:

> [@Multivariate formula with different number of observations](https://discourse.mc-stan.org/t/multivariate-formula-with-different-number-of-observations/16401/19):
>
> You can only define a correlation between two variables when there is a one to one correspondence between values. This is not a brms limitation but how correlations work. So i am unsure how you would define this residual correlation in the first place.

So in your model above the residual correlations would be captured by doing something like `y ~ 0 + event + (1 + event | subject)` adding an intercept to the subject level. this would give you a varying intercept per subject, which is common across event types (if this number is higher, you predictions for both events types is higher, if it is lower your predictions for both event types is lower → residual correlation). If you think about the “random/mixed effect” as composite error, this might become more obvious. There is a cool chapter in _Data Analysis Using Regression and Multilevel/Hierarchical Models_ (Gelman/Hill) – I think it is chapter 12.5 – that further describes this “view” of hierarchical models.

Hope this helps!  
Cheers,  
Max

---

_[View the full topic](https://discourse.mc-stan.org/t/residual-covariance-brms-mutlivariate-model-in-long-format/17381)._
