[R] Calculation of AIC BIC from mle

Martin Maechler maechler at stat.math.ethz.ch
Mon Jun 5 12:04:32 CEST 2006

>>>>> "Rainer" == Rainer M KRug <RMK at 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"

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

There's some embarassing bug here, since if you quickly look at
the 'stats4' package source, it's very clear that it was designed
to have AIC(), BIC(), logLik() all working, but only the last
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?

a bug.

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

it looks so, but I didn't check.

More information about the R-help mailing list