0

I'm building an mlogit model in R. The model works fine but when I add one-hot encoded variables it gives me the "system is computationally singular" which usually comes when correlation is high but my variables are one-hot encoded So Idk how that can be an issue

This is the model definition:

#Multinomial Logistic Regression
Model1 <- mlogit(choice ~ 0 | Sex + Age.1+ Household.Income +Area+JobA+JobB+JobC+JobD+JobE , data = DFIDX)
summary(Model1)

If I remove the job columns then it works fine but adding them gives me error:

enter image description here

This is sample of my dataset (I'm not using all the columns):

enter image description here

EDITED:

The initial model works when I remove one column of one-hot-encoded variables. But this one doesn't work and shows another error:


#Mixed logit Model with random parameters
Model2 <- mlogit(choice ~ 0 | Sex + Age.1+ Household.Income +JobA+JobB , data = DFIDX,  


                 rpar=c("Sex:2" = 'n', "Sex:3" = 'n',
                        "Age.1:2" = 'n', "Age.1:3" = 'n',
                        "Household.Income:2" = 'n', "Household.Income:3" = 'n' ,
                        "JobA:2" = 'n', "JobA:3" = 'n',
                        "JobB:2" = 'n', "JobB:3" = 'n'                       ) ,
                 R = 100  , panel = TRUE) 
summary(Model2)

Note: JobC was removed as there was 3 categories for this model and 1 was removed as suggested.

Error: enter image description here

  • 2
    This is a statically issue. See https://stats.stackexchange.com/questions/231285/dropping-one-of-the-columns-when-using-one-hot-encoding. You can't include all the job columns. You need to choose one as a reference and leave it out. – MrFlick Jun 17 '22 at 15:27
  • Thanks for the info! What you're saying is that I should remove JobE as the other 4 are conveying the information for it. Like if all other are 0 then it means its JobE right? – Wahab Aftab Jun 17 '22 at 15:30
  • Yes, exactly .... – Ben Bolker Jun 17 '22 at 15:51
  • see also https://stackoverflow.com/questions/71850169/multicollinearity-test-with-carvif (is this close enough to count as a duplicate?) – Ben Bolker Jun 17 '22 at 15:58
  • @BenBolker the initial model ran successfully after removing 1 column but getting the error when I change parameters. Kindly check edit – Wahab Aftab Jun 17 '22 at 16:14
  • @MrFlick you can check too! – Wahab Aftab Jun 17 '22 at 16:14
  • 1
    (1) Please edit your question to include error messages, data examples, etc., in a text format (rather than as images, which are inaccessible to screen readers and unsearchable). (2) We probably need a [mcve]. (3) take a look at the linked question, and [this one](https://stackoverflow.com/questions/71270248/error-warning-on-running-glm-in-r-coefficients-1-not-defined-because-of-sing/71270467#71270467), to see how to identify collinear predictors in your model. – Ben Bolker Jun 17 '22 at 17:19

0 Answers0