非一致性数组GMNL包

时间:2019-02-19 16:09:14

标签: arrays r matrix mixed-models mlogit

我正在尝试使用R中的gmnl包运行混合的logit和潜在类模型。但是,当我运行以下代码时,遇到了不合格错误:

> data<- mlogit.data(data,id.var = "ID", chid.var="key", 
choice="choice", shape="long",alt.var = "alt")

 > mixl<-gmnl(choice~Medium+Large+Farmed+Imported+Fresh+Frozen+price|0,
+ data = data,reflevel=3, 
ranp = c(Medium = "n", Large="n",Farmed="n", Imported="n",Fresh="n", Frozen="n"), 
model = "mixl", R = 50)

由此,出现以下错误:

Error in s + x[[i]] : non-conformable arrays

有趣的是,当我使用mlogit软件包或使用数据中的特定子集时,例如使用以下代码,此数据确实有效:

> mixl<-gmnl(choice~Medium+Large+Farmed+Imported+Fresh+Frozen+price|0,
+ data = data, subset= 1:3000, reflevel=3, 
ranp = c(Medium = "n", Large="n",Farmed="n", Imported="n",Fresh="n", Frozen="n"), 
model = "mixl", R = 50)

我的总数据集是500个obs,包含16个变量,请参见下面的一个小示例

> head(data,48)
     ID key obs optout alt price choice Small Medium Large Farmed Wild Imported Fresh Frozen Fried
1.1   1   1   1      0   1 12000   TRUE     0      1     0      0    1        0     0      0     1
1.2   1   1   2      0   2  7000  FALSE     1      0     0      0    0        1     0      1     0
1.3   1   1   3      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
2.1   1   2   4      0   1  9000  FALSE     0      1     0      1    0        0     0      0     1
2.2   1   2   5      0   2 10000  FALSE     1      0     0      0    0        1     1      0     0
2.3   1   2   6      1   3     0   TRUE     0      0     0      0    0        0     0      0     0
3.1   1   3   7      0   1 10000  FALSE     1      0     0      0    0        1     1      0     0
3.2   1   3   8      0   2 10000  FALSE     1      0     0      1    0        0     0      1     0
3.3   1   3   9      1   3     0   TRUE     0      0     0      0    0        0     0      0     0
4.1   1   4  10      0   1  8000  FALSE     0      0     1      1    0        0     1      0     0
4.2   1   4  11      0   2 11000   TRUE     0      1     0      0    1        0     0      1     0
4.3   1   4  12      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
5.1   1   5  13      0   1  7000  FALSE     0      0     1      0    0        1     0      0     1
5.2   1   5  14      0   2 12000   TRUE     0      0     1      0    1        0     0      1     0
5.3   1   5  15      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
6.1   1   6  16      0   1  8000   TRUE     0      0     1      0    1        0     0      1     0
6.2   1   6  17      0   2  7000  FALSE     1      0     0      0    0        1     1      0     0
6.3   1   6  18      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
7.1   1   7  19      0   1  8000  FALSE     0      1     0      1    0        0     0      1     0
7.2   1   7  20      0   2 11000  FALSE     1      0     0      1    0        0     0      0     1
7.3   1   7  21      1   3     0   TRUE     0      0     0      0    0        0     0      0     0
8.1   1   8  22      0   1 10000  FALSE     0      0     1      0    0        1     0      1     0
8.2   1   8  23      0   2  9000  FALSE     0      1     0      1    0        0     0      0     1
8.3   1   8  24      1   3     0   TRUE     0      0     0      0    0        0     0      0     0
9.1   1   9  25      0   1 11000  FALSE     1      0     0      0    0        1     0      1     0
9.2   1   9  26      0   2  9000  FALSE     0      1     0      1    0        0     0      0     1
9.3   1   9  27      1   3     0   TRUE     0      0     0      0    0        0     0      0     0
10.1  1  10  28      0   1  9000  FALSE     1      0     0      1    0        0     1      0     0
10.2  1  10  29      0   2 10000  FALSE     0      1     0      0    0        1     0      0     1
10.3  1  10  30      1   3     0   TRUE     0      0     0      0    0        0     0      0     0
11.1  1  11  31      0   1  7000  FALSE     1      0     0      0    0        1     1      0     0
11.2  1  11  32      0   2 12000   TRUE     1      0     0      0    1        0     1      0     0
11.3  1  11  33      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
12.1  1  12  34      0   1 11000  FALSE     1      0     0      0    0        1     1      0     0
12.2  1  12  35      0   2 10000   TRUE     0      1     0      0    1        0     1      0     0
12.3  1  12  36      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
13.1  2  13  37      0   1 10000   TRUE     0      1     0      0    1        0     0      1     0
13.2  2  13  38      0   2  9000  FALSE     1      0     0      0    0        1     1      0     0
13.3  2  13  39      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
14.1  2  14  40      0   1  8000   TRUE     0      1     0      0    1        0     1      0     0
14.2  2  14  41      0   2 11000  FALSE     0      0     1      1    0        0     0      0     1
14.3  2  14  42      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
15.1  2  15  43      0   1 12000   TRUE     0      0     1      0    1        0     0      1     0
15.2  2  15  44      0   2  7000  FALSE     0      0     1      0    0        1     0      0     1
15.3  2  15  45      1   3     0  FALSE     0      0     0      0    0        0     0      0     0
16.1  2  16  46      0   1 11000  FALSE     0      0     1      0    0        1     0      0     0
16.2  2  16  47      0   2  8000   TRUE     0      0     1      0    1        0     0      0     0
16.3  2  16  48      1   3     0  FALSE     0      0     0      0    0        0     0      0     0

有人知道我该如何解决这个错误?预先感谢

0 个答案:

没有答案