4
$\begingroup$

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

$\endgroup$
4
$\begingroup$

This is a bug in mice 2.15 and before. mice.impute.2l.norm() and mice.impute.2l.pan() will fail if the cluster variable is a factor. Use as.integer(dfr$group) as a temporary fix in your data. I will address the issue in a future release. Thanks for your persistence.

$\endgroup$
  • 1
    $\begingroup$ Now addressed in mice 2.16 (will stop with an error message). $\endgroup$ – Stef van Buuren Apr 27 '13 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.