mlogit 是否需要特定类型的行名称?

Does mlogit require a specific kind of row name?

我有这样的数据:

## # A tibble: 6 x 7
##   sampleno    h0    h1    h2    h3    h4 correct_hyp_no
##<dbl> <dbl> <dbl> <dbl> <dbl> <dbl><dbl>
## 1 0  7498  7147  7137  7003  7003 0
## 2 1  7349  7133  7104  7065  6960 0
## 3 2  6907  6676  6671  6575  6575 0
## 4 3  7339  7267  7133  7089  7051 0
## 5 4  5378  5316  5248  5205  5171 NA
## 6 5  7411  7253  7233  7137  7118 4

当我运行

mlogit(correct_hyp_no ~ h0 + h1 + h2 + h3 + h4, my_data)

我收到一个错误

Error in data.frame(lapply(index, function(x) x[drop = TRUE]), row.names = rownames(mydata)) : row names supplied are of the wrong length

我是 R 的新手。我没有明确命名行,但看起来它会自动选择 1,2,3,4,5,6 作为名称。请问有什么问题吗?

我的声望太低无法发表评论,但正如 Michael M 所说,您没有提供可重现的示例。也就是说,您可以做一些事情来开始。

  1. 数据需要转换成 mlogit 可以理解的格式。您的数据似乎是宽格式,因此您想将其转换为长格式。参见 ?mlogit.data
  2. 转换数据将处理结果变量,该变量将被编码为 TRUE/FALSE。但是,可能有必要放弃没有记录结果的情况,即 correct_hyp_no == NA

如果正确设置数据不起作用,请提供可重现的 MWE 以及有关您尝试执行的操作的更多信息。