Error with using the mlogit R function: the two indexes don't define unique observations

我的未来我决定 提交于 2021-02-10 05:12:36

问题


I've got a problem with the mlogit funtion in R. My dataset looks like this:

personID    caseID   altID    choice   a1    a2    a3    a4  
   1          1        1         1      3     0     3     1
   1          1        2         0      1     3     0     1
   1          1        3         0      4     4     4     4
   1          2        1         0      2     2     1     3
   1          2        2         1      2     3     1     3
etc....

I've tried running the following code, performing the model.

setV2 <- mlogit.data(data = setV2, choice = "choice", shape = "long", alt.var = "altID", chid.var = "personID")
m <- mlogit(choice ~ a1 + a2 + a3 + a4 | -1, rpar = c(a1 = "n", a2 = "n", a3 = "n", a4 = "n"), correlation = FALSE, halton = NA, TM)

However, I receive the following error (after the first line of code):

Error in dfidx::dfidx(data = data, dfa$idx, drop.index = dfa$drop.index,  : 
  the two indexes don't define unique observations

a similar problem: Error with using mlogit R function: "The two indexes don't define unique observations"

Does any of you have an idea what's going wrong? Thanks in advance.


回答1:


Your data sample is insufficient to provide a correct solution.

  1. Ensure that you provide correct index variables.

The mlogit.data() is a wrapper for dfidx() function, which has some counterintuitive requirements for indexes. The caseID in your case should vary for all specific cases, rather than only within a single personID. There shouldn't exist identical caseID for different personID.

  1. Verify that you have identical number of alternatives within each choice set.


来源:https://stackoverflow.com/questions/62775764/error-with-using-the-mlogit-r-function-the-two-indexes-dont-define-unique-obse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!