我正在尝试为 R 中的 mlogit-package 设置我的数据,但不知何故似乎遇到了麻烦。
我的数据框称为choice2,它看起来像这样:
id choice_id mode.ids choice weightloss adveffect inj tab infreq_1 infreq_3 cost
1 x1 A 0 3.5 0 1 0 1 0 550
1 x1 B 0 10.0 1 0 1 0 1 90
1 x1 C 1 0.0 0 0 0 0 0 0
1 x10 A 0 6.0 0 1 0 0 1 50
1 x10 B 0 3.5 1 0 1 1 0 165
1 x10 C 1 0.0 0 0 0 0 0 0
1 x11 A 0 2.0 1 1 0 0 1 165
1 x11 B 1 3.5 0 0 1 1 0 90
1 x11 C 0 0.0 0 0 0 0 0 0
1 x12 A 0 10.0 1 1 0 0 1 550
我通过运行以下命令为 R 中的 mlgit-package 设置我的数据:
require(mlogit)
CLOGIT <- mlogit.data(choice2,
choice = "choice",
shape = c("long"),
id.var = "id",
alt.var = "mode.ids",
varying = 5:11,
chid.var = "choice_id",
)
但是,这会导致以下错误消息:
Error in `row.names<-.data.frame`(`*tmp*`, value = c("x1.A", "x1.B", "x1.C", :
duplicate 'row.names' are not allowed
In addition: Warning message:
non-unique values when setting 'row.names': ‘x1.A’, ‘x1.B’, ‘x1.C’, ‘x10.A’, ‘x10.B’, ‘x10.C’, ‘x11.A’, ‘x11.B’, ‘x11.C’, ‘x12.A’, ‘x12.B’, ‘x12.C’, ‘x13.A’, ‘x13.B’, ‘x13.C’, ‘x2.A’, ‘x2.B’, ‘x2.C’, ‘x3.A’, ‘x3.B’, ‘x3.C’, ‘x4.A’, ‘x4.B’, ‘x4.C’, ‘x5.A’, ‘x5.B’, ‘x5.C’, ‘x6.A’, ‘x6.B’, ‘x6.C’, ‘x7.A’, ‘x7.B’, ‘x7.C’, ‘x8.A’, ‘x8.B’, ‘x8.C’, ‘x9.A’, ‘x9.B’, ‘x9.C’
Choice2 可以通过以下方式描述:
> str(choice2)
'data.frame': 7722 obs. of 11 variables:
$ id : int 1 1 1 1 1 1 1 1 1 1 ...
$ choice_id : Factor w/ 13 levels "x1","x10","x11",..: 1 1 1 2 2 2 3 3 3 4 ...
$ mode.ids : Factor w/ 3 levels "A","B","C": 1 2 3 1 2 3 1 2 3 1 ...
$ choice : Factor w/ 2 levels "0","1": 1 1 2 1 1 2 1 2 1 1 ...
$ weightloss: num 3.5 10 0 6 3.5 0 2 3.5 0 10 ...
$ adveffect : int 0 1 0 0 1 0 1 0 0 1 ...
$ inj : int 1 0 0 1 0 0 1 0 0 1 ...
$ tab : int 0 1 0 0 1 0 0 1 0 0 ...
$ infreq_1 : int 1 0 0 0 1 0 0 1 0 0 ...
$ infreq_3 : int 0 1 0 1 0 0 1 0 0 1 ...
$ cost : int 550 90 0 50 165 0 165 90 0 550 ...
谁能告诉我我在这里可能做错了什么?我已经搜索了 mlogit 的帮助文档,并在 stackowerflow 上搜索了类似的主题,但没有成功:)
一切顺利,亨里克