问题描述
我在R中使用mlogit函数时遇到了问题.我的数据集看起来像这样:
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
类似的问题:使用mlogit R函数时出错:两个索引没有定义唯一的观察结果"
你们中的任何一个都知道出了什么问题吗?预先感谢.
Does any of you have an idea what's going wrong?Thanks in advance.
推荐答案
您的数据样本不足以提供正确的解决方案.
Your data sample is insufficient to provide a correct solution.
- 确保提供正确的索引变量.
mlogit.data()
是 dfidx()
函数的包装,该函数对索引有一些违反直觉的要求.您案例中的 caseID
应该针对所有特定案例而有所不同,而不是仅在单个 personID
中.不同的 personID
不应存在相同的 caseID
.
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
.
- 验证每个选择集中您的替代品数量是否相同.
这篇关于使用mlogit R函数时出错:两个索引未定义唯一的观察值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!