R mlogit错误:.subset2(x,i,exact = exact)中的错误:在级别1没有这样的索引

时间:2017-06-14 18:41:02

标签: r levels multinomial mlogit

我有一个广泛的数据集,我已经转换为长格式,用于估计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")

0 个答案:

没有答案