s-news
[Top] [All Lists]

loop over a series regression models

To: s-news@lists.biostat.wustl.edu
Subject: loop over a series regression models
From: Peng Huang <huangp@musc.edu>
Date: Thu, 14 Apr 2005 23:27:28 -0400
In-reply-to: <B998A44C8986644EA8029CFE6396A9241B312F@exqld2-bne.qld.csiro.au>
References: <B998A44C8986644EA8029CFE6396A9241B312F@exqld2-bne.qld.csiro.au>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.1) Gecko/20040707
Dear All,

I have a data frame that contains several dependent variables and independent variables. I would like to save the regression coefficients after fitting each dependent variables (with the same independent variables). How to write a loop to do it automatically? For example, I have

mydata<- data.frame(x1=1:10, x2=(1:10)^2,
      y1=2*c(1:10) + c(1:10)^2 + rnorm(10),
      y2=10*c(1:10) + 3*c(1:10)^2 + rnorm(10))

# I want to perform the following
mod1<- summary(lm(y1~x1+x2, data=""> mod2<- summary(lm(y2~x1+x2, data="">
# then save the coefficients:
output <- rbind(mod1, mod2)

Question: how to write a loop to obtain the output?
Thank you for your help!

Peng Huang
<Prev in Thread] Current Thread [Next in Thread>