amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
424 stars 106 forks source link

Exception needed for multicollinearity error "`No predictors were left`..." for mean imputation? #588

Closed hanneoberman closed 9 months ago

hanneoberman commented 9 months ago

Since mean imputation doesn't rely on other variables in the data, the following error should not occur, I believe.

library(mice, warn.conflicts = FALSE)
#> Warning: package 'mice' was built under R version 4.3.1
pred <- make.predictorMatrix(nhanes)
pred[pred == 1] <- 0 # set all imputation model predictors to 0
imp <- mice(nhanes, meth = "mean", pred = pred, print = FALSE)
#> Error in edit.setup(data, setup, ...): `mice` detected constant and/or collinear variables. No predictors were left after their removal.
imp <- mice(nhanes, meth = "mean", print = FALSE) # error does not occur when ignoring the predictor matrix

Created on 2023-10-03 with reprex v2.0.2

stefvanbuuren commented 9 months ago

Thanks. Fixed in mice 3.16.8