Skip to content
Prev 8903 / 20628 Next

calculating number of parameters for AICc

In reply to Jude Phillips, Ben Bolker wrote the information below. This is a very thorough answer to Jude's question but also a good example of how to tease information out of R.

Ben, do you think this would be a good addition to the Wiki? (I do.)

Murray Jorgensen

=====================================
Well, you can just look in the AICc.mer() function:

K <- attr(logLik(mod), "df")

this leads you (obscurely, I admit) to getMethods("logLik",sig="mer"):

   attr(val, "df") <- dims[["p"]] + dims[["np"]] +
          as.logical(dims[["useSc"]])

To get past here, you would have to dig quite a bit deeper, but
basically the answer is that dims[["p"]] is the same as
length(fixef(model)) -- i.e., the number of fixed-effect coefficients --
and dims[["np"]] is the same as length(getME(model,"theta")) -- the
number of variance parameters.  For each random term in the model with
q components, it has q*(q+1)/2 parameters -- for example, a term of
the form (slope|group) has 3 parameters (intercept variance, slope
variance, correlation between intercept and slope).  The last term
says whether the model uses a scale parameter or not (yes for
linear mixed models, no for typical GLMMs like binomial or Poisson).

Your statement of "number of fixed effects + number of random effects + 2"
doesn't seem correct, but perhaps if you gave an example ...

Whether to add nuisance parameters or not, such as the residual
variance parameter that is estimated based on the residual variance,
is as far as I know an open question.  In the classic AIC context
it doesn't matter as long as one is consistent.  In the AICc context,
I don't think anyone really knows the answer ... adding +1 for
the residual variance parameter (as lme4 does) would make the
model selection process slightly more conservative.