[R] Multiple linear regression with for loop

From: Markus Mühlbacher <muehliman_at_yahoo.com>
Date: Tue, 26 Feb 2008 14:00:51 -0800 (PST)

Hi everyone!

 I have an array containing the following fields for over hundred compounds: cpd, activity, fixterm, energy1, energy2, energy3, ...

I want to run a multiple linear regression on all entries of an array. Therefore I tried to do this with a for loop. (Maybe there is a direct way of calculating it using apply, but I don't know that either.)  

 Actually i tried the following code:  

> attach(data)
> for(i in 1:length(cpd)) {
> fitted.model <- lm(activity ~ fixterm + i)
> coef(fitted.model)
> }


 Unfortunatly this loop doesn't give the intended correlation coefficients of each regression. If I insert a line "print(i)" into the loop the desired values for i are printed correctly. Only the coefficient outputs are missing.  Probably the solution is very near, but I just can't see it.  

 Many thanks in advance,

        [[alternative HTML version deleted]]

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. Received on Tue 26 Feb 2008 - 23:57:38 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 27 Feb 2008 - 12:30:16 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive