2
$\begingroup$

I want to calculate the AIC without calculating the loglikelihood-function (which seems complicated). If the residuals are normally distributed, this can be done, according to wikipedia, as follows:

$AIC_{\sigma} = n log(\sigma^2_Z) + 2k $,

where $\sigma^2_Z$ is the variance of the residuals, $n$ the number of samples and $k$ the number of parameters.

In order to test this I wrote a simple R-script:

library(MASS)
data(cats)
l<-lm(Hwt ~ Bwt,data=cats)

l.resi <- resid(l)
qqnorm(l.resi)
qqline(l.resi)
shapiro.test(l.resi)

n<-nrow(cats)
k<-2 # one cefficient + intercept
aic_s<- n*log(mean(l.resi^2) ) + 2*k 

print(paste("aic: ",AIC(l))) 
print(paste("aic_s: ",aic_self))

The script returns:

Shapiro-Wilk normality test

data:  l.resi
W = 0.9845, p-value = 0.1046

[1] "aic:  520.121593704369"
[1] "aic_s:  109.467296141423"

So, the residuals seem to be normally distributed. However, the AICs differ. Why is that?

$\endgroup$
8
  • $\begingroup$ What kind of model are you fitting that doesn't have an AIC or logLik method in R? $\endgroup$ Sep 12, 2014 at 16:46
  • $\begingroup$ I a couple of issues, but it's possible that these don't explain all of the differences in your example: One is that you didn't count all the parameters. The second is that likelihood is only defined up to an additive constant (so you can add or drop constants as you see fit, it's all still AIC), but to compare AICs you must use the same constants. $\endgroup$
    – Glen_b
    Sep 12, 2014 at 22:31
  • $\begingroup$ @Glen_b Thanks for your comment, but in the above example the number of parameters is clearly 2, isn't it? Second, let's say I have another model which has 3 instead of 2 parameters. Is it ok to compare their aic_s's using the formula above (no constant whatsoever)? $\endgroup$
    – Funkwecker
    Sep 15, 2014 at 9:57
  • $\begingroup$ The model has 3 parameters - intercept, slope, and $\sigma^2$. As long as the constants being left out by using that formula are the same, you can leave constants out. $\endgroup$
    – Glen_b
    Sep 15, 2014 at 12:16
  • $\begingroup$ @Glen_b Thank you for your comment again. Can you please clarify what you mean by $\sigma^2$ and whys this is a model parameter? Thank you. $\endgroup$
    – Funkwecker
    Sep 15, 2014 at 17:49

1 Answer 1

3
$\begingroup$

That formula will only equal the true AIC up to a constant. So if $AIC_1$ is the actual AIC and $AIC_s$ is the self-computed AIC you have, then $AIC_1 = AIC_s+c$ for some constant $c$.

The formula you have is useful for model comparisons when you can't compute the log likelihood, since when you are doing model comparisons, you only need to know if the AIC for one model is higher than the AIC for another model (so the actual AIC isn't needed).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.