[R] question about the difference of AIC()
@orenh @end|ng |rom m@th@@@u@dk
Wed May 12 14:10:31 CEST 2021
In the first model, I believe you estimate two parameters: the mean and
> fm <- lm(y ~ 1)
> 2*2 - 2 * logLik(fm)
'log Lik.' 40.49275 (df=2)
A zero mean model:
fm0 <- lm(y ~ -1)
> 2*1 - 2 * logLik(fm0)
'log Lik.' 39.00611 (df=1)
On Wed, 2021-05-12 at 19:49 +0800, Jinsong Zhao wrote:
> Hi there,
> I learned that AIC = 2 * npar - 2 * log(logLik(model)), where k is
> number of estimated parameters in the model.
> 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)
>  40.49275
> I also try another AIC extract function:
> > extractAIC(fm)
>  1.000000 -4.075406
> Since extractAIC() does not include the constant: n + n * log(2 *
> pi), so:
> > extractAIC(fm) + 15 + 15 * log(2 * pi)
>  38.49275
> It equals to the AIC calculated by 2*1 - 2 * logLik(fm), but
> 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,
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help