AICc in MuMIn package

68 views Asked by At

I am trying to calculate AICc (corrected AIC) of a model manually and by using MuMIn package. Is AICc(model) in MuMIn package the same as the following aicc?

model <- lm(Y~., df) #df consists of input vectors and Y.
n <- nrow(model$model)
k <- length(model$coefficients)+1
aicc <- -2*stats::logLik(model)[1]+2*k+2*k*(k+1)/(n-k-1)

I tried to do this comparison because my code can be run by R 3.6.3, which is not be supported by MuMIn package anymore. It is difficult make my code compatible with MuMIn (R>4.2.0).

1

There are 1 answers

0
Ben Bolker On BEST ANSWER

Seems that way:

model <- lm(mpg ~ . , mtcars)
n <- nrow(model$model)
k <- length(model$coefficients)+1
aicc <- -2*stats::logLik(model)[1]+2*k+2*k*(k+1)/(n-k-1)
MuMIn::AICc(model)
[1] 180.1309
aicc
[1] 180.1309

Slightly more generally you could use n <- nobs(model); k <- length(coef(model))+1; most model types have these accessor methods.