3

I tried to fill my NA data in data frame. I made simple data:

library(mice)
first <- c(1,2,3,4,5,NA,7,8,9,NA)
second<- c(1,2,NA,4,5,6,7,NA,9,10)
sample_data <- data.frame(first,second)
imp2 <- mice(sample_data)

I got this message

Error in edit.setup(data, setup, ...) : nothing left to impute

How can I solve this problem?

ashwin agrawal
  • 1,603
  • 8
  • 16

1 Answers1

2

This is because of the fact that data has high collinearity, and the mice function internally checks for a thresh-hold for collinearity, if it fails to pass then it says the above error.It uses the function mice:::find.collinear() internally.

to override this you can use the following, but it might give some weird result and it not recommended:

mice(sample_data, remove.collinear=FALSE)

Sample example:

library(mice)
data("nhanes")
nhanes

ouput:

   age  bmi hyp chl
1    1   NA  NA  NA
2    2 22.7   1 187
3    1   NA   1 187
4    3   NA  NA  NA
5    1 20.4   1 113
6    3   NA  NA 184
7    1 22.5   1 118
8    1 30.1   1 187
9    2 22.0   1 238
10   2   NA  NA  NA
11   1   NA  NA  NA
12   2   NA  NA  NA
13   3 21.7   1 206
14   2 28.7   2 204
15   1 29.6   1  NA
16   1   NA  NA  NA
17   3 27.2   2 284
18   2 26.3   2 199
19   1 35.3   1 218
20   3 25.5   2  NA
21   1   NA  NA  NA
22   1 33.2   1 229
23   1 27.5   1 131
24   3 24.9   1  NA
25   2 27.4   1 186
imp <- mice(nhanes)
imp

# list the actual imputations for BMI
imp$imp$bmi
# first completed data matrix
complete(imp)

output final imputed data:

   age  bmi hyp chl
1    1 26.3   1 187
2    2 22.7   1 187
3    1 28.7   1 187
4    3 24.9   2 206
5    1 20.4   1 113
6    3 22.5   2 184
7    1 22.5   1 118
8    1 30.1   1 187
9    2 22.0   1 238
10   2 20.4   1 131
11   1 22.7   1 187
12   2 22.0   1 238
13   3 21.7   1 206
14   2 28.7   2 204
15   1 29.6   1 187
16   1 26.3   1 187
17   3 27.2   2 284
18   2 26.3   2 199
19   1 35.3   1 218
20   3 25.5   2 204
21   1 22.0   1 118
22   1 33.2   1 229
23   1 27.5   1 131
24   3 24.9   1 204
25   2 27.4   1 186

Below is the documentation of function and a similar github issue related to yours.

Documentation: https://www.rdocumentation.org/packages/mice/versions/3.6.0/topics/mice

Github Issue: https://github.com/stefvanbuuren/mice/issues/194

ashwin agrawal
  • 1,603
  • 8
  • 16