[R] question about the difference of AIC()

Jinsong Zhao j@zh@o @end|ng |rom ye@h@net
Wed May 12 14:07:33 CEST 2021


On 2021/5/12 19:49, Jinsong Zhao wrote:
> Hi there,
> 
> I learned that AIC = 2 * npar - 2 * log(logLik(model)), where k is the 
> number of estimated parameters in the model.

k should be npar in the above sentence. Sorry for the mistake.

> 
> For examle:
>  > set.seed(123)
>  > 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:
>  > AIC(fm)
> [1] 40.49275
> 
> I also try another AIC extract function:
>  > extractAIC(fm)
> [1]  1.000000 -4.075406
> 
> Since extractAIC() does not include the constant: n + n * log(2 * pi), so:
>  > extractAIC(fm)[2] + 15 + 15 * log(2 * pi)
> [1] 38.49275
> 
> 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?
> 
> Best wishes,
> Jinsong



More information about the R-help mailing list