[R] aic calculation

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Mar 9 16:42:58 CET 2004


AIC is calculated in many places in R, but I do not believe any use that 
formula.

Here is a guess as to your confusion: in linear models there are p
coefficients plus sigma^2 to be estimated and hence there is often an
extra 2 associated with the scale parameter.  For example, in

> gaussian()$aic
function (y, n, mu, wt, dev)
sum(wt) * (log(dev/sum(wt) * 2 * pi) + 1) + 2

Beyond that, additive constants do not matter in comparing AIC between 
models and the defn of log-likelihood is only up to an additive constant.  
So sometimes calculations omit constants common to all models: 
extractAIC.lm does, for example.

On Tue, 9 Mar 2004, Stephen Dicey wrote:

> could somebody refer me to the reason R uses
> 
> -2*loglik + 2*(#param)+2
> 
> to calculate AIC?

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list