我建立了很多 GLM。通常在具有许多模型参数的大型数据集上。这意味着 base R 的glm()
函数并不是真正有用,因为它无法处理大小/复杂性,所以我通常使用它revoScaleR::rxGlm()
。
但是,我希望能够对嵌套模型对进行 ANOVA 测试,但我还没有找到一种方法来对rxGlm()
创建的模型对象执行此操作,因为 R 的anova()
函数不适用于它们。revoScaleR
提供了一个将对象as.glm()
转换为rxGlm()
对象的glm()
函数 - 有点 - 但它在这里不起作用。
例如:
library(dplyr)
data(mtcars)
# don't like having named rows
mtcars <- mtcars %>%
mutate(veh_name = rownames(.)) %>%
select(veh_name, everything())
# fit a GLM: mpg ~ everything else
glm_a1 <- glm(mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb,
data = mtcars,
family = gaussian(link = "identity"),
trace = TRUE)
summary(glm_a1)
# fit another GLM where gear is removed
glm_a2 <- glm(mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + carb,
data = mtcars,
family = gaussian(link = "identity"),
trace = TRUE)
summary(glm_a2)
# F test on difference
anova(glm_a1, glm_a2, test = "F")
工作正常,但如果我这样做:
library(dplyr)
data(mtcars)
# don't like having named rows
mtcars <- mtcars %>%
mutate(veh_name = rownames(.)) %>%
select(veh_name, everything())
glm_b1 <- rxGlm(mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + gear + carb,
data = mtcars,
family = gaussian(link = "identity"),
verbose = 1)
summary(glm_b1)
# fit another GLM where gear is removed
glm_b2 <- rxGlm(mpg ~ cyl + disp + hp + drat + wt + qsec + vs + am + carb,
data = mtcars,
family = gaussian(link = "identity"),
verbose = 1)
summary(glm_b2)
# F test on difference
anova(as.glm(glm_b1), as.glm(glm_b2), test = "F")
我看到错误消息:
Error in qr.lm(object) : lm object does not have a proper 'qr'
component. Rank zero or should not have used lm(.., qr=FALSE)
同样的问题出现在之前的 SO 帖子中:Error convert rxGlm to GLM but not似乎已经解决了。
有人可以帮忙吗?如果as.glm()
在这里没有帮助,还有其他方法吗?我可以编写一个自定义函数来执行此操作(将我的编码能力扩展到我怀疑的极限!)?
此外,SO 是最好的论坛,还是其他 StackExchange 论坛之一是寻求指导的更好地方?
谢谢你。