Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefvanbuuren opened this issue Apr 2, 2021 · 1 comment

Comments

@stefvanbuuren
Copy link
Member

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.

@prockenschaub
Copy link
Contributor

prockenschaub commented Aug 18, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants