Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "No class variable" in mice.2l.norm

Tags:

r

r-mice

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

like image 337
user2917283 Avatar asked Aug 16 '26 01:08

user2917283


1 Answers

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.

like image 113
samc Avatar answered Aug 19 '26 21:08

samc