Hi, I have multiple responses y1, y2, .., yn, and would like to do linear regression for each of them with x1, x2, ..., xm. Instead of doing regression n times, it it possible to do it all at once? I tried lm(y1+y2 ~ x1 + x2 + x3) and lm added y1 y2 and then did the regression. thanks Jeff
Jorge Ivan Velez
2009-Dec-24 17:40 UTC
[R] how to do multiple responses in a linear regression
Dear Jeff, Take a look at the following example. It may get you started. # Some data set.seed(123) x1 <- rnorm(100) x2 <- runif(100) x3 <- rpois(100, 2) er <- rnorm(100) y1 <- 3 + 2*x1 + .5*x2 + x3 + er y2 <- 1 + .5*x1 + 3*x2 + .2*x3 + er # model m <- lm(cbind(y1, y2) ~ x1 + x2 + x3) summary(m) Best regards, Jorge On Thu, Dec 24, 2009 at 12:33 PM, Hao Cen <> wrote:> Hi, > > I have multiple responses y1, y2, .., yn, and would like to do linear > regression for each of them with x1, x2, ..., xm. Instead of doing > regression n times, it it possible to do it all at once? > > I tried lm(y1+y2 ~ x1 + x2 + x3) and lm added y1 y2 and then did the > regression. > > thanks > > Jeff > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
Benilton Carvalho
2009-Dec-24 17:40 UTC
[R] how to do multiple responses in a linear regression
you need to be more clear on your question... what is it (exactly) that you want? Is it the following? y1 ~ x1 + ... + xm y2 ~ x1 + ... + xm ... yn ~ x1 + ... + xm ? if so: lm(cbind(y1, y2, ..., yn) ~ x1+x2+...+xm) b On Dec 24, 2009, at 3:33 PM, Hao Cen wrote:> Hi, > > I have multiple responses y1, y2, .., yn, and would like to do linear > regression for each of them with x1, x2, ..., xm. Instead of doing > regression n times, it it possible to do it all at once? > > I tried lm(y1+y2 ~ x1 + x2 + x3) and lm added y1 y2 and then did the > regression. > > thanks > > Jeff > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.