[R] Function to Sort and test AIC for mixed model lme?

Dieter Menne dieter.menne at menne-biomed.de
Thu May 24 09:22:23 CEST 2007


Ken Nussear <knussear <at> mac.com> writes:

> I'm running a series of mixed models using lme, and I wonder if there  
> is a way to sort them by AIC prior to testing using anova 
> (lme1,lme2,lme3,....lme7) other than by hand.

You can try something like the following. However, also consider using 
dropterm or stepAIC in MASS.

Dieter


#---------------------
library(nlme)
fmlist = vector("list",2)
fmlist[[1]] = lme(distance ~ age, data = Orthodont,method="ML") 
fmlist[[2]] = lme(distance ~ age + Sex, data = Orthodont, 
  random = ~ 1,method="ML")
aic0 = unlist(lapply(fmlist,AIC))
aic0 # larger first
fmlist1 = fmlist[order(aic0)]
unlist(lapply(fmlist1,AIC)) # smaller first



More information about the R-help mailing list