有没有办法计算R中GLM的估计值?
我正在尝试获得R中的GLM
模型的剩余系数估算。
这是我简单的循环版本实现:
data("mtcars")
res <- matrix(nrow = nrow(mtcars), ncol = 3L)
for (i in seq_len(nrow(mtcars))) {
loo.data <- mtcars[-i, ]
model <- glm(vs ~ mpg + disp, family = binomial, data = loo.data)
res[i, ] <- model$coefficients
}
循环后,我得到了一个系数的矩阵,每行都包含一对一的估算。 res
中的行数与观察总数相同。 res
不必是矩阵格式。
是否有更清洁,也许更快地获得相同结果的方法?它将在其他C ++代码中使用。我在启动软件包中找到了cv.glm
,但在我的情况下似乎不适用。使用RCPP 函数
类可能是一个选项吗?在C ++中编写Fisher评分算法似乎只是浪费时间和精力。谢谢。
I'm trying to get the leave-one-out coefficient estimates for glm
models in R. The context is not on cross validation, though.
Here's my simple loop version implementation:
data("mtcars")
res <- matrix(nrow = nrow(mtcars), ncol = 3L)
for (i in seq_len(nrow(mtcars))) {
loo.data <- mtcars[-i, ]
model <- glm(vs ~ mpg + disp, family = binomial, data = loo.data)
res[i, ] <- model$coefficients
}
After the loop, I get a matrix of coefficients where each row consists of leave-one-out estimates. The number of rows in res
is the same as the total number of observations. The res
does not have to be a matrix format.
Is there a cleaner and perhaps faster way to get the same result? It will be used in other C++ code. I found cv.glm
in boot package but it does not seem to be applicable in my case. Is using Rcpp Function
class could be an option? Writing the Fisher scoring algorithm in C++ seems just waste of time and effort. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论