This is related to bugs/errors discussed in #341. It is also mentioned in this Posit forum post.
I get an error when trying to use the 2l.pmm method to do multilevel imputation. The error appears to be related to the lmer formula having an empty string in the random term. But the error only occurs when the variable to be imputed is of a small magnitude. I have no idea why this is happening. In my particular use case I solved this by multiplying the variable by a constant before doing the imputation. (By the way, the variables in my dataset all had reasonable units, with values ranging from 0.001 to 20, so this was not a case of a value being close to .Machine$double.eps or anything like that.) I think this indicates some kind of bug and it could be worth looking into.
Reproducible example
First we do a simple multilevel imputation on the brandsma example dataset. It works as expected.
library(mice)
library(miceadds)
data(brandsma, package='mice')
predmat <- make.predictorMatrix(brandsma)
predmat[, 'sch'] <- -2
mice(brandsma, m = 1, maxit = 1, method = '2l.pmm', predictorMatrix = predmat)
Next we multiply the ses variable by 1e-4 so that it has a smaller magnitude. It is now between -0.002 and 0.002, which still seems reasonable to me. When we try to repeat the multilevel imputation, we get an error.
brandsma$ses <- brandsma$ses * 1e-4
mice(brandsma, m = 1, maxit = 1, method = '2l.pmm', predictorMatrix = predmat)
This is the error:
iter imp variable
1 1 iqv iqp sex ses
Error in str2lang(x) : <text>:1:17: unexpected ')'
1: dv._lmer ~ 1+(1|)
^
Thank you for taking a look!
This is related to bugs/errors discussed in #341. It is also mentioned in this Posit forum post.
I get an error when trying to use the
2l.pmmmethod to do multilevel imputation. The error appears to be related to the lmer formula having an empty string in the random term. But the error only occurs when the variable to be imputed is of a small magnitude. I have no idea why this is happening. In my particular use case I solved this by multiplying the variable by a constant before doing the imputation. (By the way, the variables in my dataset all had reasonable units, with values ranging from 0.001 to 20, so this was not a case of a value being close to.Machine$double.epsor anything like that.) I think this indicates some kind of bug and it could be worth looking into.Reproducible example
First we do a simple multilevel imputation on the brandsma example dataset. It works as expected.
Next we multiply the
sesvariable by1e-4so that it has a smaller magnitude. It is now between -0.002 and 0.002, which still seems reasonable to me. When we try to repeat the multilevel imputation, we get an error.This is the error:
Thank you for taking a look!