0

I am trying to running a multinomial logistic regression and am getting the error:

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

My code is fairly simple and the model appears to build correctly if I just give the model a small subset of the data. The complete df has 743 obs of 908 variables. Is this just too much for the nnet program to handle?

xray <- read.csv("xray.csv", header = T, colClasses = "factor")

xray$out <- relevel(xray$Experiment, ref = "Hafted Axe")

yanke <- multinom(out ~., data = xray)

Many thanks

  • https://stackoverflow.com/questions/17105979/i-get-error-error-in-nnet-defaultx-y-w-too-many-77031-weights-whi – user20650 Sep 05 '22 at 20:05
  • @user20650, this may be a different problem. Increasing the number of weights would help, but ?? I'm not sure that `multinom` can handle overparameterized models (number of vars > number of obs) ? – Ben Bolker Sep 05 '22 at 20:32
  • 1
    @BenBolker ; possibly, although quick test using `?multinom` example : `set.seed(15); (bwt.mu <- multinom(low ~ ., droplevels(bwt[sample(nrow(bwt), 6),])))` (you can guess the other seeds I tried to make sure each factor had > 1 levels) – user20650 Sep 05 '22 at 21:16
  • Thanks for the replies. I am totally out of my depth with this stuff. I have tried increasing the weights to 9000 but now get this error command back:> yanke <- multinom(out ~., data = xray, maxit =9000, weights = 9000) Error in model.frame.default(formula = out ~ ., data = xray, weights = 9000) : variable lengths differ (found for '(weights)'). – C.Iiverpool.arch Sep 06 '22 at 08:09
  • According to link given above, the parameter to change is `MaxNWts` not `weights` – user20650 Sep 06 '22 at 09:55
  • 1
    Thanks everyone, the MaxNWts thing worked. I really appreciate all of your time! – C.Iiverpool.arch Sep 06 '22 at 11:04

0 Answers0