mice icon indicating copy to clipboard operation
mice copied to clipboard

Error in mitml::jomoImpute: Target variables do not contain any missing data.

Open stefvanbuuren opened this issue 3 years ago • 1 comments

In connection to #378 I came across the following error

suppressPackageStartupMessages(library(mice))
mice(nhanes, 
     blocks = list(c("bmi", "hyp"), "chl"), 
     defaultMethod = c("jomoImpute", "logreg", "polyreg", "polr"))
#> 
#>  iter imp variable
#>   1   1  bmi hyp  chl
#> Error in mitml::jomoImpute(data = data, formula = formula, type = type, : 
Target variables do not contain any missing data.

Created on 2021-04-02 by the reprex package (v1.0.0)

The error occurs when imputing chl. It is not quite clear why jomoImpute() says that this variable has no missing data.

stefvanbuuren avatar Apr 02 '21 09:04 stefvanbuuren

I just stumbled across this in one of my projects. The problem appears to be the type argument passed to mitml::jomoImpute. In mice::sampler line 47 type is set to the row of the predictor matrix corresponding to the block (and therefore a vector of 0/1).

However, ?mitml::jomoImpute states the following

The type interface is designed to provide quick-and-easy imputations using jomo. 
The type argument must be an integer vector denoting the role of each variable in 
the imputation model:

1: target variables containing missing data

2: predictors with fixed effect on all targets (completely observed)

3: predictors with random effect on all targets (completely observed)

-1: grouping variable within which the imputation is run separately

-2: cluster indicator variable

0: variables not featured in the model

A quick and hacky fix that avoids that problem is therefore running

type <- 2 * type
type[blocks[[h]]] <- 1

within the mice:::sampler before the call to mice.impute.jomoImpute but ideally this could be addressed within mice.impute.jomoImpute itself.

prockenschaub avatar Aug 18 '21 13:08 prockenschaub