AIC(object, ..., k = 2)BIC(object, ...)
logLik
method to extract the corresponding log-likelihood, or
an object inheriting from class logLik
.k = 2
is the classical AIC.k
). If multiple objects are provided, a data.frame
with rows
corresponding to the objects and columns representing the number of
parameters in the model (df
) and the AIC or BIC.
Examples of models not logLik
rather than these
functions: the action of their default methods is to call logLik
on all the supplied objects and assemble the results. Note that in
several common cases logLik
does not return the value at
the MLE: see its help page.
The log-likelihood and hence the AIC/BIC is only defined up to an
additive constant. Different constants have conventionally been used
for different purposes and so extractAIC
and AIC
may give different values (and do for models of class "lm"
: see
the help for extractAIC
). Particular care is needed
when comparing fits of different classes (with, for example, a
comparison of a Poisson and gamma GLM being meaningless since one has
a discrete response, the other continuous).
BIC
is defined as
AIC(object, ..., k = log(nobs(object)))
.
This needs the number of observations to be known: the default method
looks first for a "nobs"
attribute on the return value from the
logLik
method, then tries the nobs
generic, and if neither succeed returns BIC as NA
.
extractAIC
, logLik
, nobs
.lm1 <- lm(Fertility ~ . , data = swiss)
AIC(lm1)
stopifnot(all.equal(AIC(lm1),
AIC(logLik(lm1))))
BIC(lm1)
lm2 <- update(lm1, . ~ . -Examination)
AIC(lm1, lm2)
BIC(lm1, lm2)
Run the code above in your browser using DataLab