I'm getting an error message when trying to generate an aictab
table
CODE
library(MASS)
library(AICcmodavg)
set.seed(456)
d <- data.frame(ID = 1:20,
Ct = c(sample(x = 1:50, size = 12, replace = T), rep(x = 0, length.out = 8)),
V = as.factor(rep(x = c("Dry", "Wet"), each = 2)),
S = as.factor(rep(x = c("Sand", "Clay"), each = 2)))
m1 <- glm.nb(Ct ~ 1, data = d)
m2 <- glm.nb(Ct ~ V, data = d)
m3 <- glm.nb(Ct ~ S, data = d)
all_ms <- list(m1, m2, m3)
names(all_ms) <- c("null", "type", "soil")
aic_tb <- aictab(cand.set = all_ms, second.ord = TRUE)
OUTPUT
Error in aictab.default(cand.set = all_ms, second.ord = TRUE): Function not yet defined for this object class
Can anyone see why this is failing?
The issue is that aictab()
seems unable to handle objects of class negbin
(the result from glm.nb()
).
An easy workaround is to use glm.convert()
which modifies your output to look like one from glm()
with a negative binomial family:
all_ms_glm <- lapply(all_ms, glm.convert)
aictab(cand.set = all_ms_glm, second.ord = TRUE)
# Model selection based on AICc:
#
# K AICc Delta_AICc AICcWt Cum.Wt LL
# null 2 396.34 0.00 0.35 0.35 -195.82
# soil 3 396.46 0.13 0.33 0.67 -194.48
# type 3 396.46 0.13 0.33 1.00 -194.48