【问题标题】:"No Individual Index" Error Mixed Model Mlogit R“没有单个索引”错误混合模型 Mlogit R
【发布时间】:2021-10-05 04:46:08
【问题描述】:

我正在估计一个基于离散选择实验数据的混合模型,该实验具有选择退出的替代方案(替代方案 C)。我定义了个体,但我仍然收到错误消息“没有个体索引”并且模型未估算。

我的数据截图:

每位受访者(个人)收到 6 个选择任务,他必须在三个选项(A、B 或 C)之间做出选择。

我的代码如下:

library("mlogit")
private_car$choice <- as.logical(private_car$choice)
private_car$optout <- ifelse(private_car$card_number == "3", "1", "-1")
V2G_data <- mlogit.data(private_car, choice="choice", shape = "long", id.var = "individual", alt.var = "card_number", id = "individual")

V2G_mixed_model <- mlogit(formula = choice ~ price + autonomy + charge + g_autonomy + saving + premie + optout | -1 | 0 ,
                    data = V2G_data,
                    rpar = c(autonomy = 'n', charge = 'n', g_autonomy  = 'n'),
                    R = 100,
                    halton = NA,
                    print.level = 0,
                    panel = TRUE)

谁能告诉我哪里出错了?

【问题讨论】:

  • 如果没有 reprex 就很难排除故障,但看起来每个人都完成了多项选择任务,如 card 列中所示。可能是 dfidx 使用的单个索引失败的原因。也许尝试将chid.var = "card" 添加到mlogit.data() 函数中?
  • 非常感谢您的回复。但是当我将 chid.var = "card" 添加到 mlogit.data() 函数时,我收到一条新的错误消息,指出: dfidx::dfidx 中的错误(data = data, dfa$idx, drop.index = dfa$drop .index, : 这两个索引没有定义唯一的观察结果

标签: r mixed-models mlogit


【解决方案1】:

我想我找到了答案,感谢您的帮助。我必须创建一个身份索引。 mlogit.data 公式的代码应该是:

V2G_mixed_model <- mlogit.data(private_car, choice = "choice", shape = "long", alt.var = "card_number", idx = c("individual", "card"))

现在可以了!再次感谢您的建议!

【讨论】:

    猜你喜欢
    • 2011-12-15
    • 1970-01-01
    • 2017-02-01
    • 2015-07-03
    • 2021-07-25
    • 2020-02-12
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多