Re: [R] Calculation of AIC BIC from mle

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Mon 05 Jun 2006 - 20:39:13 EST

>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch>
>>>>> on Mon, 5 Jun 2006 12:04:32 +0200 writes:

>>>>> "Rainer" == Rainer M KRug <RMK@krugs.de>
>>>>> on Mon, 05 Jun 2006 10:22:02 +0200 writes:

    Rainer> R 2.3.0, all packages up to date     Rainer> Linux, SuSE 10.0

    Rainer> Hi

    Rainer> I want to calculate AIC or BIC from several results from mle calculation.

    Rainer> I found the AIC function, but it does not seem to work with objects of
    Rainer> class mle -
    Rainer> If I execute the following:
    Rainer> ml1 <- mle(...)
    Rainer> AIC(ml1)

    Rainer> I get the following error messale:     Rainer> Error in logLik(object) : no applicable method for "logLik"

    MM> which is really not helpful as error message, since it is *wrong*:
    MM> There is a logLik(.) method for "mle" objects, and it even
    MM> works.

Hence -- as I forgot to mention in my last e-mail -- for now, you can just use

    AIC(logLik(ml1)) ## AIC
or AIC(logLik(ml1), k = log(<nobs>) ## BIC

where you have to fill in <nobs> yourself. Martin

    MM> There's some embarassing bug here, since if you quickly look at
    MM> the 'stats4' package source, it's very clear that it was designed
    MM> to have AIC(), BIC(), logLik() all working, but only the last
    MM> one does.


    Rainer> Therefore I am using the following to calculate the AIC:

    Rainer> #AICmle calculate AIC from mle object
    Rainer> AICmle <- function( m, k=2)
    Rainer> {
    Rainer> lL <- logLik(m)
    Rainer> edf <- attr(lL, "df")
    Rainer> LL <- lL[1]
    Rainer> - 2 * LL + k * edf
    Rainer> }

    Rainer> 1) Why is AIC not working with objects of class mle - am I doing     Rainer> something wrong, is it a bug or by design?

    MM> a bug.

    Rainer> 2) Just for confirmation - is my calculation of AIC correct?

    MM> it looks so, but I didn't check.     MM> Martin

    MM> ______________________________________________
    MM> R-help@stat.math.ethz.ch mailing list
    MM> https://stat.ethz.ch/mailman/listinfo/r-help     MM> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

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 Tue Jun 06 00:07:04 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 Tue 06 Jun 2006 - 02:10:30 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.