Dear friends, If I use: model<-lm(y ~ x) and then extractAIC(model), the value that I obtain does not match (not even close): AIC=2*k-2*logLik(model) However, using AIC from the AICcmodavg(), the value matches exactly the above value. I read the help of extractAIC() and could not figure out what was wrong, other than what I call k (number of parameters) is edf in the help and k they use for the value 2 that multiplies my k, their edf, and which is implemeted as the default, thus not possibly being the cause of the missmatch. Does anybody know whether am I missing something or whether there may be a bug in extractAIC()? Best wishes, Jordi Moya-Lara??o Cantabrian Institute of Biodiversity (ICAB) Dpto. Biolog??a de Organismos y Sistemas Universidad de Oviedo Catedr??tico Rodrigo Ur??a s/n 33006-Oviedo Asturias Spain [1]http://www.uniovi.es/icab/jordi.html References 1. http://www.uniovi.es/icab/jordi.html
On 06.03.2010 15:58, Jordi Moya wrote:> > Dear friends, > If I use: > model<-lm(y ~ x) > and then extractAIC(model), the value that I obtain does not match (not even > close): > AIC=2*k-2*logLik(model) > However, using AIC from the AICcmodavg(), the value matches exactly the > above value. > I read the help of extractAIC() and could not figure out what was wrong, > other than what I call k (number of parameters) is edf in the help and k > they use for the value 2 that multiplies my k, their edf, and which is > implemeted as the default, thus not possibly being the cause of the > missmatch. > Does anybody know whether am I missing something or whether there may be a > bug in extractAIC()??extractAIC tells you For linear models with unknown scale (i.e., for lm and aov), -2\log L is computed from the deviance and uses a different additive constant to logLik and hence AIC. Hence you want to compare your formula above with AIC(model) To compare the code type stats:::extractAIC.lm and compare the logLik related devianbce part of it with the stats:::logLik.lm as used in AIC(). Best, Uwe Ligges> Best wishes, > Jordi Moya-Lara??o > Cantabrian Institute of Biodiversity (ICAB) > Dpto. Biolog??a de Organismos y Sistemas > Universidad de Oviedo > Catedr??tico Rodrigo Ur??a s/n > 33006-Oviedo > Asturias > Spain > [1]http://www.uniovi.es/icab/jordi.html > > References > > 1. http://www.uniovi.es/icab/jordi.html > ______________________________________________ > 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.
Yes, you are missing something vital.
The log-likelihood is only defined up to an additive constant. extractAIC and
logLik use log-likelihoods with different additive constants, in general. (AIC
my look uniquely defined, but since log-likelihood itself is not uniquely
defined, nor is AIC.)
Try fitting two models and check if the difference in AIC values is the same
whether you use extractAIC or if you do it by hand with logLik. This is the
only real test.
Bill Venables.
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On
Behalf Of Jordi Moya [jordi at eeza.csic.es]
Sent: 07 March 2010 00:58
To: r-help at R-project.org
Subject: [R] problem with extractAIC()
Dear friends,
If I use:
model<-lm(y ~ x)
and then extractAIC(model), the value that I obtain does not match (not even
close):
AIC=2*k-2*logLik(model)
However, using AIC from the AICcmodavg(), the value matches exactly the
above value.
I read the help of extractAIC() and could not figure out what was wrong,
other than what I call k (number of parameters) is edf in the help and k
they use for the value 2 that multiplies my k, their edf, and which is
implemeted as the default, thus not possibly being the cause of the
missmatch.
Does anybody know whether am I missing something or whether there may be a
bug in extractAIC()?
Best wishes,
Jordi Moya-Lara??o
Cantabrian Institute of Biodiversity (ICAB)
Dpto. Biolog??a de Organismos y Sistemas
Universidad de Oviedo
Catedr??tico Rodrigo Ur??a s/n
33006-Oviedo
Asturias
Spain
[1]http://www.uniovi.es/icab/jordi.html
References
1. http://www.uniovi.es/icab/jordi.html
______________________________________________
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.