# AICc and K for categorical factors and interactions

I am new to multimodel inference. I am trying to create a model that has multiple categorical factors and possible interactions. For example say that my model is...

Y ~ X1 + factor(X2) + factor(X3)

say each factor has two possible categories. R is only giving me AIC in my summary output. When calculating AICc would K be 3 or 5?

also, if I have a potential interaction as in...

Y ~ X1 * X2 + X3

would K be 3 or 4? Also what do I do if there is an interaction? Do I just stop there or can I continue with analysis leaving the interaction term in the model.

-

Strictly, "none of the above".

I assume that in your question, $K$ is defined the same as $k$ here.

Every parameter that is in the model counts. So for every level of a factor (above the first), add one. For every factor-level-by-factor-level interaction term that has a parameter estimate, add one. And add one for the intercept and another one for the estimate of $\sigma^2\,$!

When comparing raw AICs it doesn't matter if some parameters are omitted from every model (so if two models both fail to count $\sigma^2$ it wouldn't matter, since it won't change the difference in AIC), but it does matter for AICc; you have to count properly there.

As is explained in the help on R's AIC function, that function will give you the df (i.e. $K$) if you supply it with more than one model:

carsfit=lm(dist~speed,cars)
carsfitf=lm(dist~cut(speed,seq(0,max(speed),5)),cars)
AIC(carsfit,carsfitf)
df      AIC
carsfit   3 419.1569
carsfitf  6 428.5270

Note 3 df for a linear regression (intercept, slope, variance).

-
Thanks for the help! So in my above example are you saying that (excluding interactions) in the above example with factors (2 levels each) k would be 5 + 1 for the intercept + 1 for the error. So k=7? –  user14241 Sep 1 '14 at 0:15
No, it should be 5. 1 for intercept + 1 for X1 +1 for levels of factor(X2) above the first, + 1 for levels of factor(X3) above the first + 1 for $\sigma^2$. Supply the models with and without interactions to a single call to AIC() to check them both. –  Glen_b Sep 1 '14 at 0:16
Sorry. Now I'm confused. :P I'm talking about the very top example. Let me ask you this. If each categorical variable had 3 levels, would it be 7 then? Are you basically saying that a 2 factor variable only "costs" me k=1? –  user14241 Sep 1 '14 at 0:22
correct - for a factor with $g$ levels, there's $g-1$ parameters; the base (or reference) level is taken up by the intercept. Look at the output from summary on your fitted model. –  Glen_b Sep 1 '14 at 0:23
OK. I think I follow now. Thanks for the help! –  user14241 Sep 1 '14 at 0:23