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?

5
  • This seems to be happening because first & second are perfectly correlated. You can use mice(sample_data, remove.collinear=FALSE) but that's probably not good advice. Or ad a bit of random noise to first or second (second = second + rnorm(length(second))) Commented Nov 1, 2019 at 21:41
  • And for example how can I fill Na values if I had 9 columns and half of variables has corellation coeficient about 0,7? Commented Nov 1, 2019 at 22:07
  • I have added an example below. Please check Commented Nov 1, 2019 at 22:12
  • @ВладимирКузовкин; I'd of thought that mice would perform with that level of correlation. Commented Nov 1, 2019 at 22:12
  • Accept the below answer, if it resolved the problem Commented Nov 24, 2019 at 21:54

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.