[R] AIC and numbers of parameters
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Apr 22 11:04:39 CEST 2006
'R' does not determine AIC: individual functions do (and the documentation
of several of them, including ?AIC, makes clear that they do not all do so
on the same basis).
In this case the question is whether the error variance is known or not,
and the fitting functions lm() and nls() do not need to know and so do not
ask. But in this case there clearly is a bug in logLik.nls, which uses a
formula that assumes the error variance was estimated and does not count
The functions AIC and logLik were imported from a contributed package and
it has subsequently quite a few errors have been found (especially with
On Fri, 21 Apr 2006, Philip Stephens wrote:
> Hi. I'm fairly new to R and have a quick question regarding AIC, logLik
> and numbers of parameters. I see that there has been some correspondence
> on this in the past but none of the threads seem to have been
> satisfactorily resolved.
That sort of comment is really not fair: please supply URLs of the threads
concerned. (Very often when people make remarks like that, the thread
does contain a definitive answer that has been missed.) The only relevant
message I could find was
No one filed a bug report on that occasion (or any other that I can find).
> I have been trying to use R to obtain AIC for fitted models and then to
> extrapolate to AICc.
> For example, using simple x-y regression data, I fitted a linear regression
> [lm(y~x)] and an exponential curve [nls(y~A*exp(B*x))]. AICs reported for
> these models are based on degrees of freedom of 3 and 2, respectively. It
> seems clear to me that the number of parameters in both cases is 3 (two
> coefficients plus the error term). Consequently, I'm dubious about the
> values of AIC provided by R. Equally, however, I'm reluctant to base my
> own calculations on logLik and my own estimates of K, without first
> determining why R uses the degrees of freedom it does.
> If anyone can explain why R gives different dfs for two models each with
> two parameters, I should be very grateful.
> R-help at stat.math.ethz.ch mailing list
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
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