【问题标题】:Error with using the mlogit R function: the two indexes don't define unique observations使用 mlogit R 函数时出错:两个索引未定义唯一观察值
【发布时间】:2020-10-27 17:46:44
【问题描述】:

R 中的 mlogit 函数有问题。我的数据集如下所示:

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

我尝试运行以下代码,执行模型。

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)

但是,我收到以下错误(在第一行代码之后):

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

类似的问题: Error with using mlogit R function: "The two indexes don't define unique observations"

你们中有人知道出了什么问题吗? 提前致谢。

【问题讨论】:

  • 不,不幸的是它没有。我对那个讨论很熟悉,但在这里不起作用。

标签: r regression logistic-regression mlogit


【解决方案1】:

您的数据样本不足以提供正确的解决方案。

  1. 确保您提供正确的索引变量。

mlogit.data() 是dfidx() 函数的包装器,它对索引有一些违反直觉的要求。在您的情况下,caseID 应针对所有特定情况而有所不同,而不是仅在单个 personID 内。不同的personID 不应该存在相同的caseID。

  1. 验证您在每个选择集中有相同数量的备选方案。

【讨论】:

    猜你喜欢
    • 2020-09-22
    • 1970-01-01
    • 2022-01-18
    • 2021-11-02
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多