tl;dr you loaded the lmerTest
package, so your models have a different class, which is confusing aictab()
. You could either make sure you have lme4
and not lmerTest
loaded when you fit the models, or use bbmle::AICctab()
, which seems slightly more robust. (It might be worth contacting the package maintainer of AICcmodavg
about this ...)
Set up with lme4
:
library(lme4)
library(AICcmodavg)
ss <- transform(sleepstudy, junk1=rnorm(nrow(sleepstudy)),
junk2=rnorm(nrow(sleepstudy)))
m1 <- lmer(Reaction ~ Days + (1|Subject), data=ss, REML=FALSE)
m2 <- update(m1, . ~ . - Days + junk1)
m3 <- update(m1, . ~ . - Days + junk2)
cand.set <- list(m1, m2, m3)
names <- c("Days", "junk1", "junk2") ## this should be a vector, not a list ...
This works fine:
aictab(cand.set, modnames=names, second.ord=TRUE, nobs=NULL, sort=TRUE)
## K AICc Delta_AICc AICcWt Cum.Wt LL
## Days 4 1802.31 0.00 1 1 -897.04
## junk2 4 1918.47 116.16 0 1 -955.12
## junk1 4 1918.71 116.40 0 1 -955.24
Now load lmerTest
and refit the models (we could just do e.g. m1 <- as(m1, "lmerModLmerTest")
but it's easy enough to refit).
library(lmerTest)
m1 <- lmer(Reaction ~ Days + (1|Subject), data=ss, REML=FALSE)
m2 <- update(m1, . ~ . - Days + junk1)
m3 <- update(m1, . ~ . - Days + junk2)
cand.set <- list(m1, m2, m3)
aictab(cand.set, modnames=names, second.ord=TRUE, nobs=NULL, sort=TRUE)
Error in aictab.default(cand.set, modnames = names, second.ord = TRUE, :
Function not yet defined for this object class
The bbmle::AICctab()
function is a little bit more robust because it relies only on the logLik
method being defined for a class (by default it gives a table with only the delta-AIC and df)
library(bbmle)
AICctab(m1, m2, m3, mnames=names, base=TRUE, weights=TRUE, logLik=TRUE)
## logLik AICc dLogLik dAICc df weight
## Days -897.0 1802.3 58.2 0.0 4 1
## junk2 -955.1 1918.5 0.1 116.2 4 <0.001
## junk1 -955.2 1918.7 0.0 116.4 4 <0.001