3
$\begingroup$

I'd like to calculate AIC to compare two linear regression models in R, but am unsure as to whether I am currently inputting the number of model parameters, which is key to the AIC calculation. My models are of the following form:

M1 = lm(height ~ Age + num_veggies_per_week)

M2 = lm(height ~ Age)

M3 = lm(height ~ num_veggies_per_week)

Then I run the AIC() function from the stats package in R with default parameters. This returns:

AIC(M1) = 395.53

AIC(M2) = 150.48

AIC(M3) = 400.15

I’m wondering if this is the correct way to calculate AIC for these three models, since the number of parameters in M1 is different from M2 and M3?

In other words, do the default parameters of AIC() need to be changed (perhaps the value of k?), or does the function interpret the number of model parameters from the call to lm()?

Thanks for your help!

$\endgroup$
1
  • $\begingroup$ The documentation tells you that AIC is calculated as "-2*log-likelihood + k*npar". npar is derived from the model object automatically. The penalty k is set to 2 by default (and it's a very common default). You shouldn't need to change it. $\endgroup$
    – Roland
    Jan 27, 2020 at 10:29

1 Answer 1

2
$\begingroup$

Something doesn't smell right here. I don't see how you could get those AICs with those three models if they are all using the exact same data. Adding the veggies variable shouldn't increase it that much - even if the variable is useless in predicting height - because it's only adding 1 parameter.

What I suspect is happening is that there is missing data in the veggies variable, making the likelihoods on different scales. If you want to make the likelihoods comparable you need to be operating on the exact same data set, which means using only the complete cases that have all three variables (height, age, and veggies) in ALL of the models. Try that and see if you get something more reasonable.

$\endgroup$
2
  • $\begingroup$ Thanks very much- I'll definitely double check that. What I'm wondering though is if I need to change the call to the AIC() function to account for the higher number of model parameters in M1- does K need to be changed in AIC() to account for this? $\endgroup$
    – krc3004
    Jan 24, 2020 at 22:43
  • $\begingroup$ If you're using the built-in AIC function then I think it automatically figures out what K is so no you do not need to take any special measures. $\endgroup$ Jan 24, 2020 at 23:09

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.