I hope you are well. I am having some trouble with mice in R with a code that had previously ran without a problem and is now not running. I am trying to use 2-level imputation and I am defining my predictor matrix as:
pred["sbp_adult",]<-c(0,0,0,0,2,
2,2,2,2,2,
2,2,2,2,2,
2,2,2,0,0,
0,0,0,0,0,
0,0,0,0,0,
-2,0,0)
imp2 <- mice(data_imp, meth=c('','', '','2l.norm','2l.norm',
'','','','2l.norm','2l.norm',
'2l.norm','2l.norm','','','2l.norm',
'2l.norm','','','2l.norm','2l.norm',
'2l.norm','2l.norm','2l.norm','2l.norm','2l.norm',
'2l.norm','2l.norm','','','', '', '', ''),
pred=pred, maxit=1, m=numimp, seed=seeds)
The error message that I get is :
1 1 sbp_adult Error in mice.impute.2l.norm(c(127, 103.25, 120.5, 103, 108.25, 112, 116, : No class variable
But there is clearly a class variable in the pred matrix as -2. What am I doing wrong? Thank you! m
I think the problem is that the class variable must be an integer, so if it's (e.g.) a character, you will get this error. (It would be nice if the error was more informative!)
By the way, people would probably have been able to help you quicker if you'd provided a sample dataset.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With