老鼠:glm.fit:算法没有收敛 [英] mice: glm.fit: algorithm did not converge
问题描述
我有一个包含大约 12 个类别变量的数据集,级别范围为 2 - 10,以及其他数值变量.约 280 条记录.我正在使用 r
中的 mice
包来使用所有默认设置对缺失的数据进行插补.但是,当我尝试进行这样的插补时:
I have a dataset with about 12 categorical variables with levels ranging from 2 - 10, as well as other numerical variables. About 280 records. I'm using the mice
package in r
to perform imputation on the missing data with all default settings.
However, when I try to do the imputation like this:
imp <- mice(df)
我继续收到此警告:
glm.fit: algorithm did not converge
我在网上找到的解决方案 这里 和这里只关注直接使用 glm
函数,但就我而言,它是从 mice
内部调用的函数.我试过设置 maxit = 50
,就像这样
The solutions I found online here and here only focus on using the glm
function directly, but in my case, it's a function that's called from within mice
. I've tried setting maxit = 50
, like this
imp <- mice(df, maxit = 50)
但最终只会收到更多相同警告的实例.知道是什么原因造成的吗?
but only ended up getting many more instances of the same warning. Any idea what could be causing this?
推荐答案
我决定发布我的问题的答案,只是为了展示我是如何解决它的,这有点不寻常,并且鉴于没有任何解决方案我可以在我的情况下找到在线工作.
I have decided to post the answer to my question just to show how I solved it, which is a bit unusual, and given that none of the solutions I could find online worked in my case.
我意识到警告实际上来自 logreg
函数(对于只有 2 个级别的分类变量),而不是来自 polyreg
.因此,鉴于 glm.fit()
函数不仅从 mice
内部调用,而且从 logreg
内部调用,我最终找到了mice
代码在 Github,复制logreg
函数,使用 maxit
的控制参数编辑 glm.fit()
调用,将其重命名为 ?mice代码>详细信息"部分,并使用它.工作正常(经过更多调试,哈哈),算法现在收敛了.
I realized that the warning actually comes from the logreg
function (for categorical variables with only 2 levels), rather than from polyreg
. So, given that the glm.fit()
function is called not just from within mice
, but from within logreg
, I ended up finding the mice
code on Github, copying the logreg
function, editing the glm.fit()
call with the control parameter for maxit
, renaming it as specified in the ?mice
'Details' section, and using that. Worked fine (after some more debugging, lol), and the algorithm now converges.
这篇关于老鼠:glm.fit:算法没有收敛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!