[R] extracting AIC scores from lmer and other objects

From: Jarrett Byrnes <jebyrnes_at_ucdavis.edu>
Date: Mon, 4 Feb 2008 15:34:00 -0800

I have a slight conundrum. I'm attempting to write a scrip that will take a number of objects (lm, glm, and lmer) and return AIC scores and weights. I've run into 3 problems, and was wondering if anyone had any pointers.

  1. is there any convenient way to extract the name of the objects? Simply, if I have a vector of objects c(my.lm, my.lmer) and I want to get a character vector c("my.lm", "my.lmer"), how would one do this? I see this as far simpler than jumping into the ugly details of each object type and extracting coefficient lists and such - not to mention tidier.
  2. I'm repeatedly getting the error

Error in UseMethod("logLik") : no applicable method for "logLik"

        in a variety of different contexts. The first is if I have to get an AIC for an lmer object. AIC(my.lmer) give me the error above. However, I can circumvent this with a very silly solution -

myAIC<-function(object) {a<-logLik(object)

        return(-2*a[1] +2*attr(a, 'df'))}

I use this, and I do not get an error.

3) I do, however, get the above error if I have a vector of model objects. So, again, if I have something like model.list<-c(my.lm, my.lmer) or even just c(my.lm, my.lm2) and then call the following on the vector of models

for(index in 1:length(model.list)){

			aiclist<-c(aiclist, myAIC(model.list[index]))

it again yields the Error in UseMethod("logLik"). Given that this is true either for lm, glm, or lmer objects, I'm guessing there's a more general issue here that I'm missing. Any pointers?



Jarrett Byrnes
Population Biology Graduate Group, UC Davis Bodega Marine Lab

        [[alternative HTML version deleted]]

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. Received on Tue 05 Feb 2008 - 00:12:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 05 Feb 2008 - 21:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive