MICE not imputing all variables with missing values

Viewed 22

I'm struggling to get mice to impute all the variables with missing values in my dataset. It's working perfectly for 4 of the variables, but not 3 others (and I'm getting the 3 logged events, which I suspect correspond to the 3 in question: GCSPupils, Hypoxia, Hypotension), but I can't figure out the issue. There seems to be variability in those variables (not constants), so mice should work. I want to do single imputation of 7 variables (the other variables have complete data).

# We run the mice code with 0 iterations
imp <- mice(TXAIMPACT_final, maxit = 0)
# Extract predictor Matrix and methods of imputation 
predM <- imp$predictorMatrix
meth <- imp$method
#Setting values of variables I'd like to leave out to 0 in the predictor matrix
predM[,c("subjectId")] <- 0 

# Specify a separate imputation model for variables of interest 

# Dichotomous variable
log <- c("Hypotension", "Hypoxia")

# Unordered categorical variable 
poly2 <- c("GCSPupils", "GCSMotor")

# Turn their methods matrix into the specified imputation models
meth[log] <- "logreg"
meth[poly2] <- "polyreg"

Here, I check to make sure "meth" is correct, and it is:

meth
subjectId         Age         GCS    GCSMotor   GCSPupils     Glucose  Hemoglobin 
    ""          ""          ""       "polyreg"   "polyreg"       "pmm"       "pmm"    
Hypotension     Hypoxia  MarshallCT     SAH         EDH         GOS        GFAP
"logreg"    "logreg"       "pmm"        ""          ""          ""          "" 

The methods are all correct as I specified. I do notice something funny about the Predictor Matrix, which is that the 3 variables not imputing only show "0" for their columns:

 predM
            subjectId Age GCS GCSMotor GCSPupils Glucose Hemoglobin Hypotension Hypoxia MarshallCT SAH EDH GOS GFAP
subjectId           0   1   1        1         0       1          1           0       0          1   1   1   1    1
Age                 0   0   1        1         0       1          1           0       0          1   1   1   1    1
GCS                 0   1   0        1         0       1          1           0       0          1   1   1   1    1
GCSMotor            0   1   1        0         0       1          1           0       0          1   1   1   1    1
GCSPupils           0   0   0        0         0       0          0           0       0          0   0   0   0    0
Glucose             0   1   1        1         0       0          1           0       0          1   1   1   1    1
Hemoglobin          0   1   1        1         0       1          0           0       0          1   1   1   1    1
Hypotension         0   0   0        0         0       0          0           0       0          0   0   0   0    0
Hypoxia             0   0   0        0         0       0          0           0       0          0   0   0   0    0
MarshallCT          0   1   1        1         0       1          1           0       0          0   1   1   1    1
SAH                 0   1   1        1         0       1          1           0       0          1   0   1   1    1
EDH                 0   1   1        1         0       1          1           0       0          1   1   0   1    1
GOS                 0   1   1        1         0       1          1           0       0          1   1   1   0    1
GFAP                0   1   1        1         0       1          1           0       0          1   1   1   1    0    

I think this is the problem, but I'm not sure how to solve. Finally, here is my single imputation:

imp2 <- complete(mice(TXAIMPACT_final, maxit = 1, 
+              predictorMatrix = predM, 
+              method = meth, print = TRUE))

 iter imp variable
  1   1  GCSMotor  Glucose  Hemoglobin  MarshallCT
  1   2  GCSMotor  Glucose  Hemoglobin  MarshallCT
  1   3  GCSMotor  Glucose  Hemoglobin  MarshallCT
  1   4  GCSMotor  Glucose  Hemoglobin  MarshallCT
  1   5  GCSMotor  Glucose  Hemoglobin  MarshallCT
Warning: Number of logged events: 3

Thanks in advance!

1 Answers

Figured it out--posting here in case someone else has this issue. My variables that were not imputing were stored as character classes, which blocked imputation. As soon as I switched them to numeric, my issues disappeared.

Related