I've spent the whole of today first battling with formatting my data (updated after finding a bug via BondedDust's table(TM) suggestion) appropriately for mLogit:
raw <-read.csv("C:\\Users\\Andy\\Desktop\\research\\Oxford\\Prefs\\rData.csv", header=T, row.names = NULL,id="id")
raw <-na.omit(raw)
library(mlogit)
TM <- mlogit.data(raw, choice = "selected", shape = "long", alt.var = "dishId", chid.var = "individuals", drop.index = TRUE)
Where I fail is when trying to model my data.
model <- mlogit(selected ~ food + plate | sex + age +hand, data = TM)
Error in solve.default(H, g[!fixed]) : system is computationally singular: reciprocal condition number = 6.26659e-18
I would really appreicate some help on the topic. Afraid I'm going a little bananas with it.
The data itself is from an experiment where we get 1000s of people to decide between pairs of plates of food (we vary how the food looks - either Angular or Circular - and vary how the plate is shaped - is either Angular or Circular).
With best wishes, Andy.
PS Afraid I'm a newbie with statistic Qs on StackOverflow.
I had the same problem, was using
yet the correlation between income and liquid assets was 0.50. But After removing outliers it worked find you van remove the outliers as follows
hope works for you,
This is more a comment than an answer (I don't have anough rep point to comment!). However, I wasn't able to reproduce your code as there isn't any
age
column in yourrData.csv
.The model is unable to interpret your dishId as the alternative index (
alt.var
) because you have different keypairs for different choices. For example, you have "TS" and "RS" as alternative index keys for the first choice in your .csv file but you have "RR" and "RS" as keys for choice 3634. Additionally, you did also not specify the names of the alternatives (alt.levels
). As a result of the fact thatalt.levels
is not filled in,mlogit.data
will automatically try to detect the alternatives based upon the alternative index, which it cannot correctly interpret. This is basically where everything goes wrong: The 'food' and 'plate' variables are not interpreted as alternatives but they are considered as individual specific variables that eventually end up causing singularity issues.You have two options to fix the issue. You can give the actual alternatives as input to
mlogit.data
through thealt.levels
parameter:Alternatively, you could opt to make your index keys consistent so that you can give them as input via
alt.var
.mlogit.data
will now be able to correctly guess what your alternatives are:We verify that both models are indeed identical. The results of model 1:
Versus the results of model 2. Note that the alternatives are correctly identified, but the names are not explicitly added to the model: