davidaarmstrong / factorplot

R software for visualizing pairwise comparisons
5 stars 0 forks source link

Error using "factorplot" on results of multinomial regression #1

Closed fefrey closed 2 years ago

fefrey commented 2 years ago

Calling the function "factorplot" for one categorial predictor variable (= multiple regressors in the model) in a multinomial model as shown in the second example (variable="education") results in an error. I encountered this using my own dataset but replicated the error using your example.

This is the error:

Error in names(b) <- obj$lev : 
  'names' attribute [4] must be the same length as the vector [1]
In addition: Warning message:
In cbind(0, v) :
  number of rows of result is not a multiple of vector length (arg 1) 

Code leading to error:

data("Chile", package="carData")
View(Chile)

library(nnet)
mod <- multinom(vote ~ age + sex + education, data=Chile)

f <- factorplot(mod, variable="education")
plot(f)

Thank you!

davidaarmstrong commented 2 years ago

I have fixed this problem. It should work now:

data("Chile", package="carData")
library(nnet)
mod <- multinom(vote ~ age + sex + education, data=Chile)

f <- factorplot(mod, variable="education")
plot(f)

image