[R] question about the difference of AIC()
j@zh@o @end|ng |rom ye@h@net
Wed May 12 13:49:28 CEST 2021
I learned that AIC = 2 * npar - 2 * log(logLik(model)), where k is the
number of estimated parameters in the model.
> y <- rnorm(15)
> fm <- lm(y ~ 1)
In this example, npar should be 1, so, AIC is:
> 2*1 - 2 * logLik(fm)
'log Lik.' 38.49275 (df=2)
However, AIC() give:
I also try another AIC extract function:
 1.000000 -4.075406
Since extractAIC() does not include the constant: n + n * log(2 * pi), so:
> extractAIC(fm) + 15 + 15 * log(2 * pi)
It equals to the AIC calculated by 2*1 - 2 * logLik(fm), but different
with the return of AIC().
It seems that AIC use 2 * (npar + 1) instead of 2 * npar.
In the help page of logLik, it said:
'"df"' (*d*egrees of *f*reedom), giving the number of (estimated)
parameters in the model.
The "df" is used by AIC() as npar, however, "df" is not number of
estimated parameters in the model, df - 1 is. Am I correct?
More information about the R-help