[R] Is AIC in glm right?

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Aug 23 15:45:58 CEST 2001


On Thu, 23 Aug 2001, Hiroto Miyoshi wrote:

> Could anyone help me?
> I am doing a regression analysis using glm.
> and the glm function gives AIC at the end of
> the output.  However, the AIC value the function
> gives does not seem right.  The details of my
> analysis goes as follows.
>
>  > x
>      y  x z
> 1  325  2 1
> 2  275  4 0
> 3  350  4 1
> 4  400  6 1
> 5  325  7 0
> 6  425  8 1
> 7  375 10 0
> 8  475 10 1
> 9  400 12 0
> 10 575 12 1
> 11 425 14 0
> 12 450 16 0
> 13 700 17 1
> 14 525 18 0
> 15 600 20 0
> 16 750 20 1
> 17 650 22 0
> 18 775 23 1
> 19 675 24 0
> 20 825 26 1
>
> > glm(x$y~x$x+x$z)
>
> Call:  glm(formula = x$y ~ x$x + x$z)
>
> Coefficients:
> (Intercept)          x$x          x$z
>      148.82        21.85       131.51
>
> Degrees of Freedom: 19 Total (i.e. Null);  17 Residual
> Null Deviance:      533000
> Residual Deviance: 13350        AIC: 194.8
>
> > a<-residuals(glm(x$y~x$x+x$z))
> > sum(a*a)
> [1] 13347.96
> >
>
> Now, since sum of squares of residuals of the regression
> is 133347.96, should AIC be 136.068,
> i.e. 20*ln(13348/20)+2*3?

Why do you think so?  AIC is -2*loglik + 2*#pars.  The loglikelihood is
not - n*log(RSS/n).  Even though likelihoods are technically only defined
up to a constant factor, there is a conventional factor which R uses and
you have forgotten.

For the code itself:

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

(the 2*#pars gets added later).


-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list