Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write R formula for multivariate response?

Tags:

r

regression

In R I want to do some regression on multivariate response on all predictors, for univariate response, I know the formula is like

y~., this is to use all predictors to regress y, what if now I face 100 response, I can not type 100 yi like y1+y2+y3...+y4~x, so how to use all predictors to regress multivariate response?

like image 735
user974270 Avatar asked May 29 '12 20:05

user974270


2 Answers

In R, the multivariate formula is to use cbind() for your Y variable. Thus, the formula would be:

model <- lm(cbind(y1, y2, y3, y4)~x)
like image 174
gung - Reinstate Monica Avatar answered Nov 17 '22 16:11

gung - Reinstate Monica


That's relatively easy if y is a matrix with 100 columns. In that case you do it the same way. For example:

lm(y ~ x)

will do a linear regression of y onto the columns of x.

like image 1
gui11aume Avatar answered Nov 17 '22 16:11

gui11aume