Hi Eliza, Then, "res" needs a slight modification
library(car) res<- lapply(colnames(h),function(x) {x1<- h[,x];dat1<- do.call(rbind,lapply(seq_len(ncol(mat1)),function(i){ x2<- m[,mat1[,i]];GG<- lm(x1~x2[,1]+x2[,2]+x2[,3]+x2[,4]);GGsum<- summary(GG); data.frame( Models=paste(colnames(x2),collapse=","), Multiple_Rsq= GGsum$r.squared, Adjusted_Rsq = GGsum$adj.r.squared, Pval = paste(GGsum$coef[-1,4],collapse=","),Vif=paste(vif(GG),collapse=","),stringsAsFactors=FALSE) })); dat1[rev(order(dat1[,3])),][1:10,]}) names(res)<- colnames(h) A.K. ________________________________ From: eliza botto <eliza_bo...@hotmail.com> To: "smartpink...@yahoo.com" <smartpink...@yahoo.com> Sent: Thursday, October 3, 2013 12:42 PM Subject: vif Dear Arun, There is one small question however. what if i also want in the table a column for "vif" values of each model. vif values can be generated for any model in the following way GG<-lm(h[,any column]~m[,any column]+m[,any other column] +m[,any other column] +m[,any other column]) library(car) vif(GG) Here will be get 4 "vif" values. I want to make a new column which could contain these values seperated by comma, very much similar to the way we did with Pr(>|t|) values. thanks in advance elisa > Date: Thu, 3 Oct 2013 09:01:53 -0700 > From: smartpink...@yahoo.com > To: r-help@r-project.org > Subject: Re: [R] a simple question > > Hi, > Try: > > > set.seed(494) > h<- matrix(sample(1:40,4*124,replace=TRUE),ncol=4) > > set.seed(39) > m<- matrix(sample(1:100,10*124,replace=TRUE),ncol=10) > colnames(h)<- paste0("h",1:4) > colnames(m)<- paste0("m",1:10) > mat1<-combn(colnames(m),4) > > res<- lapply(colnames(h),function(x) {x1<- h[,x];dat1<- > do.call(rbind,lapply(seq_len(ncol(mat1)),function(i){ x2<- m[,mat1[,i]];GG<- > lm(x1~x2[,1]+x2[,2]+x2[,3]+x2[,4]);GGsum<- summary(GG); data.frame( > Models=paste(colnames(x2),collapse=","), Multiple_Rsq= GGsum$r.squared, > Adjusted_Rsq = GGsum$adj.r.squared, Pval = > paste(GGsum$coef[-1,4],collapse=","),stringsAsFactors=FALSE) })); > dat1[rev(order(dat1[,3])),][1:10,]}) > > names(res)<- colnames(h) > > > A.K. > > > > > > ________________________________ > From: eliza botto <eliza_bo...@hotmail.com> > To: "smartpink...@yahoo.com" <smartpink...@yahoo.com> > Sent: Thursday, October 3, 2013 11:07 AM > Subject: a simple question > > > > > Dear Arun, > I hope you are fine. I actually > wanted to discuss the following problem. > I have a linear model of the > following form. > GG<-lm(h[,any column]~m[,any > column]+m[,any other column] +m[,any other column] +m[,any other column]) > where, > h is matrix with 4 columns and > 124 rows > m is matrix with 10 columns and > 124 rows > what I want is the following > make a loop command to run the > linear model of all the possible combinations of columns of “m” with each > column of “h”. > more precisely, if i take column > 1 of matrix “h”, it should be linear modeled with every combination of 10 (210 > combinations) columns of “m”. > All the columns of “h” & “m” > have certain names (you can suppose any). The summary(GG) will give Multiple > R-squared, Adjusted R-squared and 4 values of Pr(>|t|). > I want in the end a table in the > following format. > > Models > Multiple R-squared Adjusted R-squared Pr(>|t|) > Name of columns of m separated by > comma Multiple R-squared Adjusted R-squared Pr(>|t|) > separated by comma > > For Example > > Models > Multiple R-squared Adjusted R-squared Pr(>|t|) > eliza, allen, murphy, jack > 0.544 0.56 > 0.000114,0.000112,0.01114,0.002114 > > where, > eliza, allen, murphy, jack are column names. > > The models are to be enlisted in the order of their Adjusted R-squared > values. The models with highest Adjusted R-squared value should be on the top > and so on. i m only interested in top 10 models. so the remaining should be > ignored. > > I tried to put in my question everything but if there is anything wrong plz > inform me. > > Thankyou very much in advance, > > Eliza > > ______________________________________________ > R-help@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@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.