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)
I continue to get this warning:
glm.fit: algorithm did not converge
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With