# [R-sig-ME] Multivariate Regression with Crossed Random Effects

Viechtbauer, Wolfgang (SP) wolfgang.viechtbauer at maastrichtuniversity.nl
Sat Apr 21 20:14:09 CEST 2018

```Hi David,

This is possible. Structure your dataset so it has all outcomes in a single column and have a second variable indicate the outcome. Let's say 3 outcomes have been measured 4 times in a bunch of subjects. Then:

subject  time  outcome   y
1        1     1         .
1        1     2         .
1        1     3         .
1        2     1         .
1        2     2         .
1        2     3         .
1        3     1         .
1        3     2         .
1        3     3         .
1        4     1         .
1        4     2         .
1        4     3         .
2        1     1         .
...

Then one could use for example this model:

lmer(y ~ factor(time)*factor(outcome) + (factor(outcome) - 1 | subject), data=dat)

This is a model with a saturated mean structure and random effects for all outcome levels with an 'unstructured' var-cov matrix.

One could go even one step further and allow an unstructured var-cov matrix for the errors among the outcomes at each time point. That's possible with lme() from the nlme package with:

lme(y ~ factor(time)*factor(outcome), random = ~ factor(outcome) - 1 | subject, correlation = corSymm(form = ~ 1 | subject/time), weights = varIdent(form = ~ 1 | outcome), data=dat)

If you do this with 25 outcomes, then the var-cov matrix for the outcome random effects will have 325 parameters. And the same number of parameters for the var-cov matrix for the errors. Fitting such a model would require (a) tons of data and (b) a lot of patience.

Best,
Wolfgang

-----Original Message-----
From: R-sig-mixed-models [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of David Sidhu
Sent: Friday, 20 April, 2018 19:14
To: r-sig-mixed-models at r-project.org
Subject: [R-sig-ME] Multivariate Regression with Crossed Random Effects

Hi All!

Am I correct that it isn’t currently possible to run a mixed effects linear regression with multiple outcome variables (i.e., multivariate regression) in R? I am talking on the order of 25 outcome variables.

It seems that there may be some ways to “cheat” lme4 into this, but the examples I’ve come across have all been with a pair of outcomes. Is there any way to do this with 25?

Thanks!
Dave

---
David M. Sidhu, MSc<http://davidmsidhu.com/>
PhD Candidate
Department of Psychology
University of Calgary
```