问题
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.
- 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
.
- 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