# Multivariate linear regression in R

I an trying to perform a multivariate linear regression in R.

I have two dependent variables (outcomes) and one independent variable (predictor). The model would be something like:

y1,y2~x


I did not find any way to implement this in R. Any help?

• You can have a look at Multivariate multiple regression in R for a walkthrough including multivariate tests. Commented Nov 25, 2012 at 19:27
• Cristina, could you please explain exactly how your model would differ from two independent regressions y1~x and y2~x?
– whuber
Commented Nov 25, 2012 at 21:11
• My dependent variables are highly correlated that's why I want to account for both of them together in the same model. Commented Nov 26, 2012 at 13:31
• @Cristina: do you mean a PLS 'regression'? Commented Nov 26, 2012 at 19:30
• When both $y_1$ and $y_2$ are linearly dependent on $x$, of course they will be correlated to each other by virtue of those relationships. What do you want to get out of your proposed model that isn't already produced by the two separate regressions?
– whuber
Commented Apr 17, 2013 at 22:06

I'm pretty sure you can do:

lm(cbind(y1,y2)~x,data=yourdata)

• That does two separate regressions. (Although the OP states she wants something more, I'm fine with it--she has never explained what she wants to get out of the model that isn't already in these regressions.)
– whuber
Commented Apr 17, 2013 at 22:05

lm can do that:

> y<-matrix(rnorm(100*2),100,2)
> x<-rnorm(100)
> lm(y~x)

Call:
lm(formula = y ~ x)

Coefficients:
[,1]      [,2]
(Intercept)  -0.18837   0.01386
x             0.25135   0.04769

• It seems to me that your code performs a regression for each dependent variable separately. What I want to run it's a model that account for both outcomes. Commented Nov 25, 2012 at 19:11
• User603's answer is correct. Given a model $Y = XB+E$ and assuming $E \sim N(0,\Sigma)$ (so you don't have a strictly diagonal covariance matrix) the maximum likelihood estimator for $B$ is simply $B_{OLS} = (X^T X)^{-1} X^T Y$, which amounts in performing separate ordinary least squares estimates for each of the q response variables and does not depend on $\Sigma$. ($\Sigma$ appears as $\Omega^{-1}$ in the literature sometimes, $\Omega$ being the precision matrix) Commented Apr 18, 2013 at 2:16

A Multivariate Response model could be more accurate and powerful than 2 Univariate response model because it will use the correlation between the 2 or more dependent variables to improve the prediction on each of the dependent variable. A complete description of existing methods and a new approach are described in this paper by Breiman and Friedman (2002). However I haven't tried them with R yet. I found the article available for free download here http://onlinelibrary.wiley.com/doi/10.1111/1467-9868.00054/pdf

• I can't download that article, care to upload it somewhere else? Anyway, how would such a model be constructed? The OP is curiously silent on what she actually wants to do with the variables
– IMA
Commented Apr 23, 2013 at 13:42
• This is not an answer to the question. Also link is to the paid website. Commented Apr 23, 2013 at 13:45