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.

Reply via email to