Why does MICE fail to impute multilevel data with 2l.norm and 2l.pan in this situation ?
Here is a reproducible example:
require(foreign)
require(mice)
require(pan)
dt.fail <- read.csv("http://goo.gl/pg8um")
dt.fail$X <- NULL
dt.fail$out <- as.factor(dt.fail$out )
dt.fail$grp<- as.factor(dt.fail$grp)
dt.fail$v1<- as.factor(dt.fail$v1)
dt.fail$v2<- as.factor(dt.fail$v2)
dt.fail$v3 <- as.factor(dt.fail$v3)
dt.fail$v7<- as.factor(dt.fail$v7)
dt.fail$v8 <- as.factor(dt.fail$v8)
dt.fail$v9 <- as.factor(dt.fail$v9)
dt.fail$v11 <- as.factor(dt.fail$v11)
dt.fail$v12 <- as.factor(dt.fail$v12)
dt.fail <- dt.fail[!is.na(dt.fail$grp),]
PredMatrix <- quickpred(dt.fail)
PredMatrix['CTP',] <- c(1,-2,0,0,0,0,0,0,0,0,1,0,1,1,0,2)
impute = mice(
data=dt.fail,
m = 1,
maxit = 1,
imputationMethod = c(
"logreg", # out
"", # grp ----> cluster grouping factor
"pmm", # v1
"polyreg", # v2
"logreg", # v3
"pmm", # v4
"logreg", # v5
"logreg", # v6
"polyreg", # v7
"polyreg", # v8
"polyreg", # v9
"polyreg", # v10
"", # v11 ----> complete
"", # v12 ----> complete
"2l.pan", # CTP ----> multilevel imputation
""), # const ----> needed for multilevel impuitation
predictorMatrix = PredMatrix, seed = 101
)
This produces the following error:
Error in order(dfr$group) : argument 1 is not a vector
Using the 2l.norm
method, it produces the following error:
Error in factor(x[, type == (-2)], labels = 1:n.class) : invalid labels; length 20592 should be 1 or 2
Using pmm
there is no error