# Why do I get exact singularity when I add a dummy variable to a multinomial logistic using R mlogit?

I am using the mlogit package in R to run a multinomial logistic regression on pooled discrete choice data collected using two different questionnaire formats. I want to test whether the format had a significant effect on choices. When I run the basic model I get a result. But when I run the same model with a dummy variable indicating which format the respondents saw, I get an error: "Error in solve.default(H, g[!fixed]) : Lapack routine dgesv: system is exactly singular"

I was able to replicate the error using Train's Electricity dataset in the mlogit package, setting a dummy based on whether the respondent ID was odd or even:

library(mlogit)
data("Electricity", package = "mlogit")
Electr <- mlogit.data(Electricity, id = "id", choice = "choice",
varying = 3:26, shape = "wide", sep = "")
Electr$odd.dummy <- ifelse(Electr$id %% 2 == 0, 0, 1) # As example, set dummy if ID is odd
summary(mlogit(choice ~ pf + cl + loc + wk + tod + seas | 0, data=Electr)) # Basic model
summary(mlogit(choice ~ pf + cl + loc + wk + tod + seas + odd.dummy | 0, data=Electr)) # Basic + dummy
summary(mlogit(choice ~ odd.dummy | 0, data=Electr)) # Only dummy


As with my data, the first model runs, but the second two are singular.

I understand that a result will be singular if there is perfect colinearity between variables, but I don't see how this is the case here. Respondents were randomly assigned to one format or the other, and the underlying experimental design was the same in both formats, so there shouldn't be any colinearity between the dummy and the other variables.

I would be grateful if someone could explain why adding the dummy leads to a singular result, and even more grateful if they could suggest a solution to avoid it.

• Check whether odd.dummy (or the relevant variable in your data set) perfectly predicts membership or non-membership in any of the outcome categories. If it does, you have perfect separation and the mlogit command is choking when it tries to estimate the standard errors. – Ben Lauderdale Mar 9 '12 at 10:57
• Thanks for the suggestion. I checked, and there is variability in choices within each dummy group, so I don't think that's the issue. – DartPrivateer Mar 9 '12 at 16:00

I think I have discovered the source of the error. In my model, as well as in the example above, the dummy is an individual specific attribute, but I had included it in the model statement as an alternative specific attribute.

Properly specifying the dummy as an individual-specific attribute (i.e. after the '|') produces a sensible result:

summary(mlogit(choice ~ pf + cl + loc + wk + tod + seas | odd.dummy-1 , data=Electr)) # Dummy as individual-specific attribute

Coefficients :
Estimate Std. Error  t-value Pr(>|t|)
pf          -0.624054   0.023369 -26.7048   <2e-16 ***
cl          -0.108130   0.008281 -13.0577   <2e-16 ***
loc          1.442730   0.050706  28.4527   <2e-16 ***
wk           0.997726   0.044911  22.2157   <2e-16 ***
tod         -5.454041   0.185186 -29.4517   <2e-16 ***
seas        -5.831122   0.188030 -31.0116   <2e-16 ***
odd.dummy:2  0.057435   0.067904   0.8458   0.3976
odd.dummy:3  0.064776   0.068510   0.9455   0.3444
odd.dummy:4  0.061038   0.067753   0.9009   0.3676


I'll leave it to someone else to try to explain the mathematics of what was happening.