i encountered an error when using futuremice() with blocks:
library(mice, warn.conflicts = FALSE)
x <- futuremice(
nhanes, m=5, n.core=5, maxiter=2, parallelseed=1,
blocks=list(c('age'), c('bmi', 'hyp', 'chl')),
predictorMatrix=matrix(rep(1, 8), nr=2)
)
Error in `colnames<-`(`*tmp*`, value = 1:imp$m) : attempt to set 'colnames' on an object with less than two dimensions
Digging a little deeper i found the imp object that were combined using ibind() function did not contain valid imputed values for variables in blocks. An example:
Looking at ibind(), it seems the problem is all the separately imputed data had a visitSequence using block names, e.g. "age" "B1". The visitSequence has a lower length (2 in this example) than the actual number of variables (4 in this example) being imputed so the for loop in Line 68 couldn't combine all imputed variables.
Replacing
Line 65 with visitSequence <- colnames(x$predictorMatrix),
Line 75 with chainMean <- chainVar <- initialize.chain(colnames(x$predictorMatrix), iteration, m), and
Line 91 with visitSequence = x$visitSequence,
seems to get my codes work.
Edit: it seems that the latest version on Github has already fixed this issue except when some included variables were not in the block. i've made a comment on the commit.
Hi all,
i encountered an error when using futuremice() with blocks:
Digging a little deeper i found the
imp
object that were combined usingibind()
function did not contain valid imputed values for variables in blocks. An example:One mids object from a future:
Combined mids object:
Looking at
ibind()
, it seems the problem is all the separately imputed data had avisitSequence
using block names, e.g."age" "B1"
. ThevisitSequence
has a lower length (2 in this example) than the actual number of variables (4 in this example) being imputed so the for loop in Line 68 couldn't combine all imputed variables.Replacing
Line 65 with
visitSequence <- colnames(x$predictorMatrix)
, Line 75 withchainMean <- chainVar <- initialize.chain(colnames(x$predictorMatrix), iteration, m)
, and Line 91 withvisitSequence = x$visitSequence,
seems to get my codes work.
Edit: it seems that the latest version on Github has already fixed this issue except when some included variables were not in the block. i've made a comment on the commit.
Fred