I am having a problem using MICE, where it generates the following warning:
Warning message: In var(data[, j], na.rm = TRUE) : NAs introduced by coercion
This seems to be related to the presence of a unique alphanumeric ID variable in the data. For example:
require(mice) imp <- mice(nhanes,maxit=0) # no problem nhanes$id <- 1:25 imp <- mice(nhanes,exclude="id",maxit=0) # no problem nhanes$id <- LETTERS[1:25] imp <- mice(nhanes,exclude="id",maxit=0)
The latter generates the warning:
In var(data[, j], na.rm = TRUE) : NAs introduced by coercion
The predictor matrix is
age bmi hyp chl id age 0 0 0 0 0 bmi 1 0 1 1 0 hyp 1 1 0 1 0 chl 1 1 1 0 0 id 0 0 0 0 0
Note that here
id is not used to impute anything. So it seems strange that a warning would be generated at all, in this simple case. Even this generates the same warning:
pred <- imp$pred imp <- mice( data=nhanes, m = 5, maxit=5, imputationMethod = c( "norm", # age "norm", # bmi "norm", # hyp "norm", # chl "") , # id predictorMatrix = pred )
where id is not specified to be imputed or to be used for imputation in the predictor matrix, and the imputation method is ""
So my questions are:
- Why is this warning generated ?
- How can I prevent this warning, without removing the ID variable from the data. Of course I don't use the ID variable for imputing other variables - it's just a bit inconvenient to remove it.
- If it can't be prevented, can I safely ignore the warning and use the predictor matrix for imputing my data (after setting the id column to zeros) ?