我有一个广泛的数据集,我已将其转换为长格式以在 mlogit 中进行估计。在我没有替代特定数据的数据中,所有替代的值都是相同的。
str(f)
'data.frame': 60 obs. of 6 variables:
$ Outcome: logi FALSE TRUE FALSE FALSE FALSE FALSE ...
$ X1 : num 0.00437 0.00437 0.00437 0.00437 0.00437 ...
$ X2 : num 0.00617 0.00617 0.00617 0.00617 0.00617 ...
$ X3 : num 0.00257 0.00257 0.00257 0.00257 0.00257 ...
$ chid : int 1 1 1 1 1 1 2 2 2 2 ...
$ alt : chr "L1" "L2" "L3" "L4" ...
当我试图估计一个模型时,
model<-mlogit(Outcome~X1+X2+X3,data=f,shape="long",choice="Outcome",alt.var=f$alt)
如果 alt 是 char 类型,我会收到以下错误消息:
.subset2(x, i, exact = exact) 中的错误:级别 1 没有此类索引
如果 alt 是因素,我会得到这个:
.subset2(x, i, exact = exact) 中的错误:递归索引在第 2 级失败
对于这些与 mlogit 相关的消息,我没有找到任何帮助。
这是我使用的截断数据(完整数据集有 3900 行)。mlogit 似乎对其数据非常严格。谢谢。
structure(list(Outcome = c(FALSE, TRUE, FALSE, FALSE, FALSE,
FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE,
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE,
FALSE), X1 = c(0.004373668, 0.004373668, 0.004373668, 0.004373668,
0.004373668, 0.004373668, 0.00237986, 0.00237986, 0.00237986,
0.00237986, 0.00237986, 0.00237986, 0.008879354, 0.008879354,
0.008879354, 0.008879354, 0.008879354, 0.008879354, 0.003356421,
0.003356421, 0.003356421, 0.003356421, 0.003356421, 0.003356421,
0.004611897, 0.004611897, 0.004611897, 0.004611897, 0.004611897,
0.004611897, 0.003225387, 0.003225387, 0.003225387, 0.003225387,
0.003225387, 0.003225387, 0.003495294, 0.003495294, 0.003495294,
0.003495294, 0.003495294, 0.003495294, 0.003639481, 0.003639481,
0.003639481, 0.003639481, 0.003639481, 0.003639481, 0.004911368,
0.004911368, 0.004911368, 0.004911368, 0.004911368, 0.004911368,
0.004165713, 0.004165713, 0.004165713, 0.004165713, 0.004165713,
0.004165713), X2 = c(0.006167994, 0.006167994, 0.006167994, 0.006167994,
0.006167994, 0.006167994, 0.003977765, 0.003977765, 0.003977765,
0.003977765, 0.003977765, 0.003977765, 0.004830369, 0.004830369,
0.004830369, 0.004830369, 0.004830369, 0.004830369, 0.004058219,
0.004058219, 0.004058219, 0.004058219, 0.004058219, 0.004058219,
0.004064723, 0.004064723, 0.004064723, 0.004064723, 0.004064723,
0.004064723, 0.004226818, 0.004226818, 0.004226818, 0.004226818,
0.004226818, 0.004226818, 0.004199124, 0.004199124, 0.004199124,
0.004199124, 0.004199124, 0.004199124, 0.004917811, 0.004917811,
0.004917811, 0.004917811, 0.004917811, 0.004917811, 0.00424221,
0.00424221, 0.00424221, 0.00424221, 0.00424221, 0.00424221, 0.005516136,
0.005516136, 0.005516136, 0.005516136, 0.005516136, 0.005516136
), X3 = c(0.002565325, 0.002565325, 0.002565325, 0.002565325,
0.002565325, 0.002565325, 0.001206929, 0.001206929, 0.001206929,
0.001206929, 0.001206929, 0.001206929, 0.001917941, 0.001917941,
0.001917941, 0.001917941, 0.001917941, 0.001917941, 0.001922314,
0.001922314, 0.001922314, 0.001922314, 0.001922314, 0.001922314,
0.003243962, 0.003243962, 0.003243962, 0.003243962, 0.003243962,
0.003243962, 0.001443621, 0.001443621, 0.001443621, 0.001443621,
0.001443621, 0.001443621, 0.00214728, 0.00214728, 0.00214728,
0.00214728, 0.00214728, 0.00214728, 0.001188095, 0.001188095,
0.001188095, 0.001188095, 0.001188095, 0.001188095, 0.002095854,
0.002095854, 0.002095854, 0.002095854, 0.002095854, 0.002095854,
0.002529183, 0.002529183, 0.002529183, 0.002529183, 0.002529183,
0.002529183), chid = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L,
10L, 10L, 10L), alt = c("L1", "L2", "L3", "L4", "L5", "L6", "L1",
"L2", "L3", "L4", "L5", "L6", "L1", "L2", "L3", "L4", "L5", "L6",
"L1", "L2", "L3", "L4", "L5", "L6", "L1", "L2", "L3", "L4", "L5",
"L6", "L1", "L2", "L3", "L4", "L5", "L6", "L1", "L2", "L3", "L4",
"L5", "L6", "L1", "L2", "L3", "L4", "L5", "L6", "L1", "L2", "L3",
"L4", "L5", "L6", "L1", "L2", "L3", "L4", "L5", "L6")), .Names = c("Outcome",
"X1", "X2", "X3", "chid", "alt"), row.names = c(NA, -60L), class = "data.frame")