amices / mice

Multivariate Imputation by Chained Equations
https://amices.org/mice/
GNU General Public License v2.0
447 stars 108 forks source link

FIX: resolve issue of element-wise comparison introduced in 4.3.0 #599

Closed vkhodygo closed 1 year ago

vkhodygo commented 1 year ago

Running code

library("mice")
expr <- expression((wgt - 40) * (hc - 50))
boys$wgt.hc <- with(boys,  eval(expr))
meth <- make.method(boys)
meth["wgt.hc"] <- paste("~I(",  expr,  ")",  sep = "")
meth["bmi"] <- ""
pred <- make.predictorMatrix(boys)
pred[c("wgt",  "hc"),  "wgt.hc"] <- 0
imp.int <- mice(boys,  m = 1,  meth = meth,  pred = pred,  print = FALSE,  seed = 62587,  maxit = 10)

vis <- c("hgt",  "wgt",  "hc", "wgt.hc",  "gen",  "phb",  "tv",  "reg")
expr <- expression((wgt - 40) * (hc - 50))
boys$wgt.hc <- with(boys,  eval(expr))

imp.int2 <- mice(boys,  m = 1,  maxit = 1,  visitSequence = vis,
                 meth = imp.int$meth,  pred = imp.int$pred,
                 seed = 23390)

from Section 6.5.1 of the book results in the following error:

Error in maxit == 1L && !is.null(user.visitSequence) && user.visitSequence ==  : 
  'length = 8' in coercion to 'logical(1)'

This is caused by changes introduced in R4.3.0. The PR should resolve this.

vkhodygo commented 1 year ago

@hanneoberman If you're happy with the code could you please merge it?