Extract AIC from a Fitted Model (original) (raw)
extractAIC {stats} | R Documentation |
---|
Description
Computes the (generalized) Akaike An InformationCriterion for a fitted parametric model.
Usage
extractAIC(fit, scale, k = 2, ...)
Arguments
fit | fitted model, usually the result of a fitter likelm. |
---|---|
scale | optional numeric specifying the scale parameter of the model, see scale in step. Currently only used in the "lm" method, where scale specifies the estimate of the error variance, and scale = 0 indicates that it is to be estimated by maximum likelihood. |
k | numeric specifying the ‘weight’ of the_equivalent degrees of freedom_ (\equiv edf) part in the AIC formula. |
... | further arguments (currently unused in base R). |
Details
This is a generic function, with methods in base R for classes"aov"
, "glm"
and "lm"
as well as for"negbin"
(package MASS) and "coxph"
and"survreg"
(package survival).
The criterion used is
AIC = - 2\log L + k \times \mbox{edf},
where L
is the likelihood and edf
the equivalent degrees of freedom (i.e., the number of free parameters for usual parametric models) of fit
.
For linear models with unknown scale (i.e., for [lm](../../stats/help/lm.html)
and[aov](../../stats/help/aov.html)
), -2\log L
is computed from the_deviance_ and uses a different additive constant to[logLik](../../stats/help/logLik.html)
and hence [AIC](../../stats/help/AIC.html)
. If RSS
denotes the (weighted) residual sum of squares then extractAIC
uses for - 2\log L
the formulae RSS/s - n
(corresponding to Mallows' C_p
) in the case of known scale s
andn \log (RSS/n)
for unknown scale.[AIC](../../stats/help/AIC.html)
only handles unknown scale and uses the formulan \log (RSS/n) + n + n \log 2\pi - \sum \log w
where w
are the weights. Further AIC
counts the scale estimation as a parameter in the edf
and extractAIC
does not.
For glm
fits the family's aic()
function is used to compute the AIC: see the note under logLik
about the assumptions this makes.
k = 2
corresponds to the traditional AIC, using k = log(n)
provides the BIC (Bayesian IC) instead.
Note that the methods for this function may differ in their assumptions from those of methods for [AIC](../../stats/help/AIC.html)
(usually_via_ a method for [logLik](../../stats/help/logLik.html)
). We have already mentioned the case of "lm"
models with estimated scale, and there are similar issues in the "glm"
and "negbin"
methods where the dispersion parameter may or may not be taken as ‘free’. This is immaterial as extractAIC
is only used to compare models of the same class (where only differences in AIC values are considered).
Value
A numeric vector of length 2, with first and second elements giving
edf | the ‘equivalent degrees of freedom’ for the fitted model fit. |
---|---|
AIC | the (generalized) Akaike Information Criterion for fit. |
Note
This function is used in [add1](../../stats/help/add1.html)
, [drop1](../../stats/help/drop1.html)
and [step](../../stats/help/step.html)
and the similar functions in packageMASS from which it was adopted.
Author(s)
B. D. Ripley
References
See Also
[AIC](../../stats/help/AIC.html)
, [deviance](../../stats/help/deviance.html)
, [add1](../../stats/help/add1.html)
,[step](../../stats/help/step.html)
Examples
utils::example(glm)
extractAIC(glm.D93) #>> 5 15.129
[Package _stats_ version 4.6.0 Index]