Re: [R] extracting AIC scores from lmer and other objects

From: jebyrnes <jebyrnes_at_ucdavis.edu>
Date: Tue, 5 Feb 2008 23:14:51 -0800 (PST)

Working with lists of models gets stranger. I've actually found that, with lmer objects in a list, as long as I use them such as in the following example

all.models<-c(my.lmer, my.lmer2)
summary(all.models[[1]])

Everything is fine. However, if, instead, I had lm objects or glm objects, the same summary command would merely give me the summary of a list of coefficients, not a lm or glm summary.

I'm guessing this is an S3 versus S4 problem, and, honestly, I haven't had to deal with such issues before. If you have any advice, it would be much appreciated, as this could be quite a useful function.

Also, I see your issue on the AIC for multilevel models. Indeed, effective number of parameters is rather vexing. I'm guessing that this measure could be computer for lmer objects fairly easily (he says with the anticipation of egg on his face) - perhaps checking for the object type and then selectively using one AIC or the other might be the way to go.

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

  This may (?) be related to the NEWS item for R 2.6.2 RC:

 o	The AIC() S4 generic in package stats4 no longer disables
	dispatch of S3 methods for AIC().

> 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
>
> aiclist<-vector
> 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?
>

-- 
View this message in context: http://www.nabble.com/extracting-AIC-scores-from-lmer-and-other-objects-tp15280858p15306183.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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 Wed 06 Feb 2008 - 07:20:14 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 Wed 06 Feb 2008 - 07:30:12 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