Issue with MICE package and subsequent generation of logistic regression #665
Replies: 6 comments
-
It seems that you are doing more than needed. The
If you want to track what |
Beta Was this translation helpful? Give feedback.
-
Thanks for commenting back so quickly! I tried the revised code, but I still receive an error message: "Error in model.frame.default(formula = HeartDisease_Binary2 ~ AgeCat + Sex2 + : |
Beta Was this translation helpful? Give feedback.
-
Also, as a side note, I cannot find the object "with". I tried to track what with() does, but I received the error: "Error: 'with.mids' is not an exported object from 'namespace:mice'" |
Beta Was this translation helpful? Give feedback.
-
Two suggestions:
|
Beta Was this translation helpful? Give feedback.
-
I got it to work by using fit <-with(imp2, glm(HeartDisease_Binary2 ~ AgeCat + ..., family=binomial, weights = NULL)). I originally had an issue in my GLM statement that, when corrected, allowed this function to work properly. |
Beta Was this translation helpful? Give feedback.
-
Glad you could sort it out. |
Beta Was this translation helpful? Give feedback.
-
I am using a publicly available dataset (National Health Interview Survey). I am studying heart disease as the outcome variable and examining the impact of several clinicodemographic factors on prevalence and odds of heart disease.
I did multiple imputation with the MICE package in R (v 4.4.0) and had no issues with multiple imputation. After the multiple imputation, I extracted the first imputed complete dataset and used the head function to look at the first few rows to double check that, in fact, the multiple imputation procedure had worked. Everything was fine. Afterwards, I proceeded to try to complete a logistic regression analysis using the multiply imputed data. Please refer to the code below. In my first step, I turned the datasets into long format. Second, I converted I back to MIDS type data since MICE can work with this type of data. Third, I generate the logistic regression. However, whenever I try to do the logistic regression, I obtain an error that states: "Error in as.data.frame.default(merge8imp_long_mids) : cannot coerce class '"mids"' to a data.frame" I tried removing the pool() function in the multivariate model, but that did not help. I even tried to use the merge8_imp_long (the complete imputed dataset in long format), but that required me to specify weights = NULL and it never loaded (I waited for over half an hour and the logistic regression procedure never completed).
Here is all my code starting with the multiple imputation:
`imp2 <- mice(merge8, maxit = 2,
predictorMatrix = predM,
method = meth, print = TRUE)
merge8complete <- mice::complete(imp2, 1)
head(merge8complete)
merge8imp_long <- mice::complete(imp2, action="long", include = TRUE)
merge8imp_long_mids <-as.mids(merge8imp_long)
model_fitimp <- pool(with(merge8imp_long_mids,
glm(HeartDisease_Binary2~ AgeCat + Sex2 + RaceEthnicity + SexualOrientation + Education + IncomePovertyRatio + BMICategory, HealthInsurance2,
data = merge8imp_long_mids,
family = "binomial",
weights = NULL)))
model_fitimp2 <- with(merge8imp_long_mids,
glm(Psoriasis_Binary2 ~ AgeCat + Sex2 + RaceEthnicity + SexualOrientation + Education + IncomePovertyRatio + BMICategory, HealthInsurance2,
data = merge8imp_long_mids,
family = "binomial"))
`
Neither model_fitimp nor model_fitimp2 worked. I receive the error: "Error in as.data.frame.default(merge8imp_long_mids) : cannot coerce class '"mids"' to a data.frame"
Any help would be greatly appreciated! Thanks so much!
Beta Was this translation helpful? Give feedback.
All reactions