Dear List, I am looking to run a host of models (60) with three methods - lmer,glm and lrm. Is there a way to output the key stats into a table that i can copy to excel? I.e for lmer i would want AIC,BIC etc for lrm i would want Brier score, r2, c-value etc At present i am running the models from a script and then copying across the values into a excel spreadsheet however this is time consuming and i imagine their must be a trick? Thanks Chris
Dear List, I am looking to run a host of models (60) with three methods - lmer,glm and lrm. Is there a way to output the key stats into a table that i can copy to excel? I.e for lmer i would want AIC,BIC etc for lrm i would want Brier score, r2, c-value etc At present i am running the models from a script and then copying across the values into a excel spreadsheet however this is time consuming and i imagine their must be a trick? I had thought of setting up a data frame and populating it with the scores but i am not very experienced and am unsure of how to do it? Thanks Chris
Hi r-help-bounces at r-project.org napsal dne 05.10.2010 13:46:49:> > Dear List, > > I am looking to run a host of models (60) with three methods - lmer,glmand lrm.> > Is there a way to output the key stats into a table that i can copy toexcel?> > I.e for lmer i would want AIC,BIC etc > for lrm i would want Brier score, r2, c-value etc > > At present i am running the models from a script and then copying acrossthe> values into a excel spreadsheet however this is time consuming and iimagine> their must be a trick? > > I had thought of setting up a data frame and populating it with thescores but> i am not very experienced and am unsure of how to do it?If you do not wont set up data frame you can use write table to already existing file with append=TRUE option write.table(some.data, "result.xls", sep = "\t", row.names = F, append=T) where some.data is matrix with one row and desired number of columns. I presume the output is numeric. Regards Petr> > Thanks > > Chris > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Write a function that does your analysis and returns the values of interest in a vector. Then run the function multiple times using replicate or sapply and the results will be put into a matrix for you. -- 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 Chris Mcowen > Sent: Tuesday, October 05, 2010 5:47 AM > To: r-help at r-project.org > Subject: [R] Extract summary stats to table > > > Dear List, > > I am looking to run a host of models (60) with three methods - lmer,glm > and lrm. > > Is there a way to output the key stats into a table that i can copy to > excel? > > I.e for lmer i would want AIC,BIC etc > for lrm i would want Brier score, r2, c-value etc > > At present i am running the models from a script and then copying > across the values into a excel spreadsheet however this is time > consuming and i imagine their must be a trick? > > I had thought of setting up a data frame and populating it with the > scores but i am not very experienced and am unsure of how to do it? > > Thanks > > Chris > > ______________________________________________ > 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.
Chris, Here is an example. Please ignore the particulars of the models - they were built only to demonstrate sapply(): library(lme4) statedata <- data.frame(state.x77, state.region) #create empty list object mods <- list() #run the models, adding each one to the list mods$m1 <- glm(Income ~ Life.Exp, data=statedata, family gaussian(link="log")) mods$m2 <- update(mods$m1, . ~ . + HS.Grad) mods$m3 <- update(mods$m2, . ~ . + Population) mods$m4 <- lmer(Income ~ Life.Exp + (1|state.region), data=statedata) #collect the model fit info with sapply() and store as data frame dfmi <- data.frame( Formula=sapply(mods, FUN=function(x){ paste(formula(x)[2], formula(x)[1], formula(x)[-c(1,2)], collapse=" ") } ), AIC=sapply(mods, FUN="AIC") ) #write the data frame to a comma-separated file write.table(dfmi, file="dfmi.txt", col.names=TRUE, sep=",") Nathan Pellegrin [[alternative HTML version deleted]]