3

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?

Darius
  • 489
  • 2
  • 6
  • 22

2 Answers2

2

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
wici
  • 1,681
  • 1
  • 14
  • 21
1

For the record this works in version 2.2-1: the NEWS file suggests it was fixed in version 2.2-0.

revision 2.2-0 (25 February 2019)
...
added methods for objects of 'glm.nb' class

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453