Error in R (mice package), too many weights

I get the following error while imputing missing cases with the mice function from the library "mice"

 Error in nnet.default(X, Y, w, mask = mask, size = 0, skip = TRUE, softmax = TRUE,  :
too many (1104) weights

The problem is generated by the function mice.impute.polr and mice.impute.polyreg because of the default maximum number of weights. I can not solved it by using the command substitute and neither by copying the functions' code and writing the new functions mice.impute.polr and mice.impute.polyreg (because of a function I cannot find call augment). I've told that I should go to the source code to modify it.

How can I do it? Are there any other solution?

Upvotes: 9

Views: 8834

Answers (3)

Gordon Li
Gordon Li

Reputation: 81

Increase the MaxNWts in mice through nnet.MaxNWts argument

mice(data = df_with_nas, nnet.MaxNWts = 2000)

This is described in the documentation of the mice imputation functions, e.g. mice.impute.polr

Upvotes: 5

CcMango
CcMango

Reputation: 427

I had the same problem. I found one factor variable has more than 10 levels. After I delete this var, the error is gone.

Upvotes: -1

Graham Parsons
Graham Parsons

Reputation: 506

The neural net function called by mice() is stopping because the "maximum allowable number of weights" has been exceeded. The MaxNWts argument to nnet is there to prevent running code that will take a very long time to complete.

If you don't mind waiting then you can increase the MaxNWts parameter by passing it directly to mice(), which will be picked up by nnet():

mice(data = df_with_nas, MaxNWts = 2000)

Upvotes: 11

Related Questions