调用 aictab 时未定义函数
Function not defined when calling aictab
我在尝试生成 aictab
table
时收到错误消息
代码
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)
输出
Error in aictab.default(cand.set = all_ms, second.ord = TRUE): Function not yet defined for this object class
谁能看出为什么会失败?
问题是 aictab()
似乎无法处理 class negbin
的对象(glm.nb()
的结果)。
一个简单的解决方法是使用 glm.convert()
将您的输出修改为看起来像来自 glm()
的具有负二项式族的输出:
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
请注意,这在 2.2-1 版中有效:NEWS file 表明它已在 2.2-0 版中修复。
revision 2.2-0 (25 February 2019)
...
added methods for objects of 'glm.nb' class
我在尝试生成 aictab
table
代码
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)
输出
Error in aictab.default(cand.set = all_ms, second.ord = TRUE): Function not yet defined for this object class
谁能看出为什么会失败?
问题是 aictab()
似乎无法处理 class negbin
的对象(glm.nb()
的结果)。
一个简单的解决方法是使用 glm.convert()
将您的输出修改为看起来像来自 glm()
的具有负二项式族的输出:
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
请注意,这在 2.2-1 版中有效:NEWS file 表明它已在 2.2-0 版中修复。
revision 2.2-0 (25 February 2019)
...
added methods for objects of 'glm.nb' class