I am trying to use the mice package to run multiple imputation for many variables in my dataset. This data is multi-level, as each observation has a person and a team attached to it. Some variables should vary within a person and by team, while others should stay the same within all responses from a person. A sample of my code is below:
predmatrix<-quickpred(starts)
predmatrix[personlevel, 'PERNER'] <- -2 #designate PersonID as cluster variable for person-level characteristics
predmatrix[teamlevel, 'team_id'] <- -2 # designates teamID as cluster variable for team level characteristics
imputation_specs<-is.na(starts)
imputation_specs[,onlypred]<-FALSE # this matrix will tell mice where to impute or not, so I'm setting all of the solely predictor variables to "FALSE"
# Determine imputation methods
# Create imputation with 0 iterations to generate a process-control object
mi1 <- mice(starts, maxit = 0)
mi_methods <- mi1$method
# Set imputation methods
mi_methods<-ifelse(colnames(starts) %in% personlevel, "2lonly.pmm",
ifelse(colnames(starts) %in% teamlevel, "2l.pmm", "")) # this sets predictor only columns to no method, person-level columns to 2lonly.pmm, and team-level columns to 2l.pmm
# Run imputations
test_MI_2<-mice(starts, pred=predmatrix,
where=imputation_specs,method=mi_methods, m=2, print=FALSE)
When I run the mice function, I am receiving an error that says Error in .imputation.level2(y = y, ry = ry, x = x, type = type, wy = wy, : Method 2lonly.pmm found the following clusters with partially missing level-2 data: 70024886 Method 2lonly.mean can fix such inconsistencies.
70024886 is a person ID (cluster). I've looked at this person's data and I can't figure out why this cluster of data is causing issues within the imputation while other observations wouldn't. Does anyone understand more about what this error is signifying as the problem? I can't find anything online about this specific error, and I'd rather stick to .pmm as my method for imputation. Thank you!
The error was occurring in my code because some variables were incorrectly listed as "person-level" when really they varied by team. So, mice was seeing variation within a person where there shouldn't be and this caused the code to be unable to run. Fixing the categorization of these variables removed the error immediately.