Skip to content

how to run linear regression models at once

6 messages · Dennis Murphy, wangwallace, David Winsemius

#
hey, folks,

I have two very simple questions. I am not quite sure if I can do this using
R. 

so, I am analyzing a large data frame with thousands of variables. For
example:

Dependent variables: d1, d2, d3 (i.e., there are three dependent variables)

Independent variables: s1, s2, s3, ......s1000 (i.e., there are 1000
independent variables)

now I want to run simple linear regression analyses of dependent variables
on independent variables. A laborious way to do this is running 1000 linear
regression models for each dependent variable separately. This would take a
lot of time. My question is: 

1) is there a easy way to run all 1000 linear regression analyses for each
dependent variable at once?  
2) after running all 1000 linear regression analyses at once, how can I
write 3000 regression weights (1000 regression weights for each dependent
variable)  and its significance level in to a file (e.g., csv, excel, ect).

Many thanks in advance!!
2 days later
#
hey, Dennis,

I applied your syntax into my data frame with different variable names.
Specifically, I replaced y1 and y2, with ocbi and ocbo. I got the following
error message. Could you please explain why would this happen? Again,
thanks!
+ fm2<-as.formula(paste('ocbo',ms[i],sep'~'))

Error: unexpected string constant in:
"for(i in 1:5){fm1<-as.formula(paste('ocbi',ms[i],sep='~'))
fm2<-as.formula(paste('ocbo',ms[i],sep'~'"
#
On Jan 10, 2011, at 1:29 PM, wangwallace wrote:

            
for(i in 1:5){fm1<-as.formula(paste('ocbi',ms[i],sep='~'))  fm2<- 
as.formula(paste('ocbo',ms[i],sep'~'))
When you get a message like that it is going to be a missing  
<something>, usually right near the end of the presented string in the  
error message,
  ,,, and in your case it is a missing "=" sign,
David Winsemius, MD
West Hartford, CT