微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R hmftest 多项 logit 模型“系统在计算上是奇异的”

如何解决R hmftest 多项 logit 模型“系统在计算上是奇异的”

我有一个多项 logit 模型,其中包含两个单独的特定变量(first 和 age)。 我想进行 hmftest 以检查 IIA 是否成立。

我的数据集如下所示:

head(df)
  mode choice first age
1 both      1     0  24
2  pre      1     1  23
3 both      1     2  53
4 post      1     3  43
5   no      1     1  55
6 both      1     2  63 

我将 mlogit 调整为:

   mode choice first age    idx
1   TRUE      1     0  24 1:both
2  FALSE      1     0  24   1:no
3  FALSE      1     0  24 1:post
4  FALSE      1     0  24  1:pre
5  FALSE      1     1  23 2:both
6  FALSE      1     1  23   2:no
7  FALSE      1     1  23 2:post
8   TRUE      1     1  23  2:pre
9   TRUE      1     2  53 3:both
10 FALSE      1     2  53   3:no

~~~ indexes ~~~~
   id1  id2
1    1 both
2    1   no
3    1 post
4    1  pre
5    2 both
6    2   no
7    2 post
8    2  pre
9    3 both
10   3   no
indexes:  1,2

我的原始(完整)模型运行如下:

full <- mlogit(mode ~ 0 | first + age,data = df_mlogit,reflevel = "no")

导致以下结果:

Call:
mlogit(formula = mode ~ 0 | first + age,reflevel = "no",method = "nr")

Frequencies of alternatives:choice
  no both post  pre 
 0.2  0.4  0.2  0.2 

nr method
18 iterations,0h:0m:0s 
g'(-H)^-1g = 8.11E-07 
gradient close to zero 

Coefficients :
                    Estimate  Std. Error z-value Pr(>|z|)
(Intercept):both  2.0077e+01  1.0441e+04  0.0019   0.9985
(Intercept):post -4.1283e-01  1.4771e+04  0.0000   1.0000
(Intercept):pre   5.3346e-01  1.4690e+04  0.0000   1.0000
first1:both      -4.0237e+01  1.1059e+04 -0.0036   0.9971
first1:post      -8.9168e-01  1.4771e+04 -0.0001   1.0000
first1:pre       -6.6805e-01  1.4690e+04  0.0000   1.0000
first2:both      -1.9674e+01  1.0441e+04 -0.0019   0.9985
first2:post      -1.8975e+01  1.5683e+04 -0.0012   0.9990
first2:pre       -1.8889e+01  1.5601e+04 -0.0012   0.9990
first3:both      -2.1185e+01  1.1896e+04 -0.0018   0.9986
first3:post       1.9200e+01  1.5315e+04  0.0013   0.9990
first3:pre        1.9218e+01  1.5237e+04  0.0013   0.9990
age:both          2.1898e-02  2.9396e-02  0.7449   0.4563
age:post          9.3377e-03  2.3157e-02  0.4032   0.6868
age:pre          -1.2338e-02  2.2812e-02 -0.5408   0.5886

Log-Likelihood: -61.044
McFadden R^2:  0.54178 
Likelihood ratio test : chisq = 144.35 (p.value = < 2.22e-16)

为了测试 IIA,我从模型中排除了一个替代方案(此处为“pre”)并按如下方式运行模型:

part <- mlogit(mode ~ 0 | first + age,alt.subset = c("no","post","both"))

导致

Call:
mlogit(formula = mode ~ 0 | first + age,"both"),method = "nr")

Frequencies of alternatives:choice
  no both post 
0.25 0.50 0.25 

nr method
18 iterations,0h:0m:0s 
g'(-H)^-1g = 6.88E-07 
gradient close to zero 

Coefficients :
                    Estimate  Std. Error z-value Pr(>|z|)
(Intercept):both  1.9136e+01  6.5223e+03  0.0029   0.9977
(Intercept):post -9.2040e-01  9.2734e+03 -0.0001   0.9999
first1:both      -3.9410e+01  7.5835e+03 -0.0052   0.9959
first1:post      -9.3119e-01  9.2734e+03 -0.0001   0.9999
first2:both      -1.8733e+01  6.5223e+03 -0.0029   0.9977
first2:post      -1.8094e+01  9.8569e+03 -0.0018   0.9985
first3:both      -2.0191e+01  1.1049e+04 -0.0018   0.9985
first3:post       2.0119e+01  1.1188e+04  0.0018   0.9986
age:both          2.1898e-02  2.9396e-02  0.7449   0.4563
age:post          1.9879e-02  2.7872e-02  0.7132   0.4757

Log-Likelihood: -27.325
McFadden R^2:  0.67149 
Likelihood ratio test : chisq = 111.71 (p.value = < 2.22e-16)

但是,当我想对 hmftest 进行编码时,会出现以下错误

> hmftest(full,part)
Error in solve.default(diff.var) : 
  system is computationally singular: reciprocal condition number = 4.34252e-21

有人知道问题出在哪里吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。