i have a series of regressions i need to run where everything is the same except for the dependent variable, e.g.: lm(y1 ~ x1+x2+x3+x4+x5, data=data) lm(y2 ~ x1+x2+x3+x4+x5, data=data) lm(y3 ~ x1+x2+x3+x4+x5, data=data) is it possible to run all these regs with a single command? given that the bulk of the work for linear regressions is inverting a matrix that depends only on the independent variables, it seems like a waste to do it over and over for each new dependent variable. thanks, Rnewb -- View this message in context: http://www.nabble.com/regression-with-multiple-dependent-variables--tp26088025p26088025.html Sent from the R help mailing list archive at Nabble.com.
Rnewb wrote:> > i have a series of regressions i need to run where everything is the same > except for the dependent variable, e.g.: > > lm(y1 ~ x1+x2+x3+x4+x5, data=data) > lm(y2 ~ x1+x2+x3+x4+x5, data=data) > lm(y3 ~ x1+x2+x3+x4+x5, data=data) > > is it possible to run all these regs with a single command? given that > the bulk of the work for linear regressions is inverting a matrix that > depends only on the independent variables, it seems like a waste to do it > over and over for each new dependent variable. > > thanks, > Rnewb >It's right there in TFM ... (?lm) If 'response' is a matrix a linear model is fitted separately by least-squares to each column of the matrix. Y <- cbind(y1,y2,y3) lm(Y~...) -- View this message in context: http://www.nabble.com/regression-with-multiple-dependent-variables--tp26088025p26088139.html Sent from the R help mailing list archive at Nabble.com.
Hi, cbind the dependent variables such as in: x=rnorm(100) e1=rnorm(100) e2=rnorm(100) e3=rnorm(100) y1=2*x+e1 y2=-1*x+e2 y3=0.7*x+e3 reg=lm(cbind(y1,y2,y3)~x) summary(reg) Cheers, Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Rnewb Gesendet: Tuesday, October 27, 2009 9:44 PM An: r-help at r-project.org Betreff: [R] re gression with multiple dependent variables? i have a series of regressions i need to run where everything is the same except for the dependent variable, e.g.: lm(y1 ~ x1+x2+x3+x4+x5, data=data) lm(y2 ~ x1+x2+x3+x4+x5, data=data) lm(y3 ~ x1+x2+x3+x4+x5, data=data) is it possible to run all these regs with a single command? given that the bulk of the work for linear regressions is inverting a matrix that depends only on the independent variables, it seems like a waste to do it over and over for each new dependent variable. thanks, Rnewb -- View this message in context: http://www.nabble.com/regression-with-multiple-dependent-variables--tp260880 25p26088025.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Rnewb > Sent: Tuesday, October 27, 2009 6:44 PM > To: r-help at r-project.org > Subject: [R] re gression with multiple dependent variables? > > > i have a series of regressions i need to run where everything > is the same > except for the dependent variable, e.g.: > > lm(y1 ~ x1+x2+x3+x4+x5, data=data) > lm(y2 ~ x1+x2+x3+x4+x5, data=data) > lm(y3 ~ x1+x2+x3+x4+x5, data=data)You can do with(data, lm.fit(x=cbind(Intercept=1,x1,x2,x3), y=cbind(y1,y2,y3))) lm.fit is the numerical code behind lm(). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> > is it possible to run all these regs with a single command? > given that the > bulk of the work for linear regressions is inverting a matrix > that depends > only on the independent variables, it seems like a waste to > do it over and > over for each new dependent variable. > > thanks, > Rnewb > -- > View this message in context: > http://www.nabble.com/regression-with-multiple-dependent-variables--tp26088025p26088025.html> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
thanks for the quick and accurate responses! cheers, Rnewb -- View this message in context: http://www.nabble.com/regression-with-multiple-dependent-variables--tp26088025p26088943.html Sent from the R help mailing list archive at Nabble.com.
Rnewb, Have you given any thought to multivariate linear regression (i.e. MAOVA in which there are multiple dependent variables )? This type of regression makes a number of assumptions beyond the "usual" regression model including multivariate normality of the outcome variables, but can be very useful in the situation you describe. John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> "Daniel Malter" <daniel at umd.edu> 10/27/2009 11:17 PM >>>Hi, cbind the dependent variables such as in: x=rnorm(100) e1=rnorm(100) e2=rnorm(100) e3=rnorm(100) y1=2*x+e1 y2=-1*x+e2 y3=0.7*x+e3 reg=lm(cbind(y1,y2,y3)~x) summary(reg) Cheers, Daniel ------------------------- cuncta stricte discussurus ------------------------- -----Urspr?ngliche Nachricht----- Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im Auftrag von Rnewb Gesendet: Tuesday, October 27, 2009 9:44 PM An: r-help at r-project.org Betreff: [R] re gression with multiple dependent variables? i have a series of regressions i need to run where everything is the same except for the dependent variable, e.g.: lm(y1 ~ x1+x2+x3+x4+x5, data=data) lm(y2 ~ x1+x2+x3+x4+x5, data=data) lm(y3 ~ x1+x2+x3+x4+x5, data=data) is it possible to run all these regs with a single command? given that the bulk of the work for linear regressions is inverting a matrix that depends only on the independent variables, it seems like a waste to do it over and over for each new dependent variable. thanks, Rnewb -- View this message in context: http://www.nabble.com/regression-with-multiple-dependent-variables--tp260880 25p26088025.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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. ______________________________________________ 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. Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}}