将 rxGlm 转换为 GLM 时出错

Error converting rxGlm to GLM

我在将 rxGlm 模型转换为普通 glm 模型时遇到问题。每次我尝试隐藏我的模型时,我都会遇到同样的错误:

Error in qr.lm(object) : lm object does not have a proper 'qr' component.
Rank zero or should not have used lm(.., qr=FALSE).

这是一个简单的例子:

cols <- colnames(iris)
vars <- cols[!cols %in% "Sepal.Length"]
form1 <- as.formula(paste("Sepal.Length ~", paste(vars, collapse = "+")))

rx_version <- rxGlm(formula = form1,
                    data = iris,
                    family = gaussian(link = 'log'),
                    computeAIC = TRUE)

# here is the equivalent model with base R
R_version <- glm(formula = form1,
                 data = iris,
                 family = gaussian(link = 'log'))


summary(as.glm(rx_version)) #this always gives the above error

我似乎无法在 rxGlm 公式中找到这个 "qr" 组件(我假设这与矩阵分解有关)。

还有其他人处理过这个问题吗?

rxGlm 对象没有 qr 组件,转换为 glm 对象不会创建组件。这是有意为之,因为计算模型矩阵的 QR 分解需要将完整的数据集存储在内存中,这会破坏使用 rx* 函数的目的。

as.glm 实际上更意味着通过 PMML 支持模型 import/export。大多数您想做的事情都可以使用 rxGlm 对象完成,无需转换。例如,rxGlm 计算系数标准误差作为拟合的一部分,之后不需要 qr 分量。