Re: [R] Extract summary stats to table

2010-10-06 Thread nathan pellegrin
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]]

__
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.


Re: [R] Extract summary stats to table

2010-10-05 Thread Greg Snow
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.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Chris Mcowen
 Sent: Tuesday, October 05, 2010 5:47 AM
 To: r-help@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@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.