[R] RE : multiple regressions on columns

markleeds at verizon.net markleeds at verizon.net
Wed Feb 25 10:03:18 CET 2009


  Hi David: If your variables are in a dataframe  called DF and the 
dependent variable is in the first column , you can do below but you 
probably are well aware of this anyway.

lmresults<-lapply(names(DF[,-1],function(.name) {
   lm(DF[,1] ~ DF[,.name], data=DF)
})

This will run through each of the variables in the dataframe and regress 
the first column on each variable individually.




On Wed, Feb 25, 2009 at  3:56 AM, GOUACHE David wrote:

> Hello and thanks for your reply, but as you said, this is not really 
> what I'm trying to do.
> My purpose is not one of variable selection within a model with 
> multiple predictors, but simply fitting a large number of models with 
> only one predictor.
> I was just hoping there would be a solution as simple as the one given 
> in my example which gives the results of many regression models of the 
> type Yi~x where i spans all the colums in a matrix and x is one 
> predictor. My objective being the fitting of many regression models of 
> the type y~Xi where i spans all the columns in a matrix and y is one 
> dependent variable.
>
> Best regards,
>
> David Gouache
> ARVALIS - Institut du végétal
> Station de La Minière
> 78280 Guyancourt
> Tel: 01.30.12.96.22 / Port: 06.86.08.94.32
>
>
> -----Message d'origine-----
> De : Greg Snow [mailto:Greg.Snow at imail.org] Envoyé : mardi 24 février 
> 2009 18:22
> À : GOUACHE David; r-help at stat.math.ethz.ch
> Objet : RE: multiple regressions on columns
>
> The add1 function might be what you want, there is also addterm in the 
> MASS package and the leaps package can do some things along this line 
> (plus more).
>
> But before doing this, you may want to ask yourself what question you 
> are really trying to answer, then explore if this answers that 
> question or not.
>
> -- 
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at imail.org
> 801.408.8111
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of GOUACHE David
>> Sent: Tuesday, February 24, 2009 10:13 AM
>> To: r-help at stat.math.ethz.ch
>> Subject: [R] multiple regressions on columns
>>
>> R-helpers,
>>
>> A quick question regarding my wanting to run multiple regressions
>> without writing a loop.
>> Looking at a previous discussion :
>> http://tolstoy.newcastle.edu.au/R/e2/help/07/02/9740.html
>>
>> my objective is to do the "opposite", i.e. instead of having the same
>> independent variable and testing it against multiple dependent
>> variables, my goal is to test multiple independent variables against
>> the same dependent variable.
>>
>> Using the iris dataset:
>>
>> iris4 <- as.matrix(iris[,-c(1,5)])
>> summary(lm(iris4 ~ Sepal.Length, iris))
>>
>> what I would have liked is to do the following :
>>
>> summary(lm(Sepal.Length ~ iris4, iris))
>>
>> and obtain the results from 3 separate regressions, as above, instead
>> of one multiple regression...
>>
>> Any clues ?
>>
>> Tanks in advance
>>
>> David Gouache
>> ARVALIS - Institut du végétal
>> Station de La Minière
>> 78280 Guyancourt
>> Tel: 01.30.12.96.22 / Port: 06.86.08.94.32
>>
>> ______________________________________________
>> 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.




More information about the R-help mailing list