Re: [R] Calculation of AIC BIC from mle

From: Rainer M Krug <rkrug_at_sun.ac.za>
Date: Mon 05 Jun 2006 - 21:37:19 EST

Thanks a lot for your and Martin's help - I understand now why it is not working and am using AIC(logLik(ml1)).

Thanks

Rainer

Prof Brian Ripley wrote:
> You are mixing S3 and S4 classes and generics here. AIC(logLik(ml1))
> will work.
>
> This a namespace issue: stats4 contains a version of logLik, but the
> default method for AIC is from stats, and so dispatches on stats::logLik
> and not stats4::logLik. There is something fundamentally unsatisfactory
> about converting S3 generics to S4 generics where namespaces are involved.
>
> I have put a workaround in R-devel.
>
> On Mon, 5 Jun 2006, Rainer M KRug wrote:
>

>> R 2.3.0, all packages up to date
>> Linux, SuSE 10.0
>>
>> Hi
>>
>> I want to calculate AIC or BIC from several results from mle calculation.
>>
>> I found the AIC function, but it does not seem to work with objects of
>> class mle -
>> If I execute the following:
>> ml1 <- mle(...)
>> AIC(ml1)
>>
>> I get the following error messale:
>> Error in logLik(object) : no applicable method for "logLik"
>>
>> Therefore I am using the following to calculate the AIC:
>>
>> #AICmle calculate AIC from mle object
>> AICmle <- function( m, k=2)
>> {
>>     lL <- logLik(m)
>>     edf <- attr(lL, "df")
>>     LL <- lL[1]
>>     - 2 * LL + k * edf
>> }
>>
>> 1) Why is AIC not working with objects of class mle - am I doing
>> something wrong, is it a bug or by design?
>>
>> 2) Just for confirmation - is my calculation of AIC correct?

>
> Not quite. The correct function is
>
>> stats:::AIC.logLik

> function (object, ..., k = 2)
> -2 * c(object) + k * attr(object, "df")
> <environment: namespace:stats>
>
-- 
Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation
Biology (UCT)

Department of Conservation Ecology and Entomology
University of Stellenbosch
Matieland 7602
South Africa

Tel:		+27 - (0)72 808 2975 (w)
Fax:		+27 - (0)21 808 3304
Cell:		+27 - (0)83 9479 042

email:	RKrug@sun.ac.za
      	Rainer@krugs.de

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Mon Jun 05 21:44:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 05 Jun 2006 - 22:10:29 EST.

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