A short mice
-related question as follows: when running simple mice imputation the function goes through well. But complete()
function does not substitute my NA
's at all. I guess it must be something wrong with my dataset but I can't see what. It is just a matrix as any other although with roughly equal number of rows and columns. Maybe this is the source of the problem. What should I look into?
-
1$\begingroup$ As Nick said, posting some sample data and code for what you're doing is necessary. As a wild guess, you're sure you didn't end up with "NA" as a string value instead of an actual NA? $\endgroup$– WayneJul 4, 2012 at 20:10
1 Answer
My guess is that this arises from including the original dataset. You can specify that by either choosing the 0
dataset or complete(..., action="long", include=TRUE)
, see below example:
# Generate data
dat=data.frame(x1=c(21, 20, 31, 50),
x2=c(0, NA, 18, 3),
x3=c(0, 0, 54, 10))
library(mice)
# Do imputation
imp <- mice(dat, m=2)
Now this gives:
> # Look at the original dataset
> complete(imp, 0)
x1 x2 x3
1 21 0 0
2 20 NA 0
3 31 18 54
4 50 3 10
>
> # Get all the datasets
> complete(imp, action = "long", include = TRUE)
.imp .id x1 x2 x3
1 0 1 21 0 0
2 0 2 20 NA 0
3 0 3 31 18 54
4 0 4 50 3 10
5 1 1 21 0 0
6 1 2 20 0 0
7 1 3 31 18 54
8 1 4 50 3 10
9 2 1 21 0 0
10 2 2 20 18 0
11 2 3 31 18 54
12 2 4 50 3 10