【问题标题】:R hmftest multinomial logit model " system is computationally singular"R hmftest 多项式 logit 模型“系统在计算上是奇异的”
【发布时间】:2021-07-21 14:32:25
【问题描述】:

我有一个多项式 logit 模型,其中包含两个单独的特定变量(第一和年龄)。 我想进行 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, data = df_mlogit, 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, data = df_mlogit, reflevel = "no", 
               alt.subset = c("no", "post", "both"))

导致

Call:
mlogit(formula = mode ~ 0 | first + age, data = df_mlogit, alt.subset = c("no", 
    "post", "both"), reflevel = "no", 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

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

【问题讨论】:

  • 是否有任何预测变量在按因变量分层时没有变化?
  • 两个自变量仅因个体而异,因此对于每个选择,年龄都将是相同的 f.ex.,这是您的意思吗?

标签: r mlogit


【解决方案1】:

我认为这里的问题可能是 hmftest 检查两个备选方案的概率比是否仅取决于这些备选方案的特征。 由于这里只有个体级别的变量,因此在这种情况下测试将不起作用。

【讨论】:

猜你喜欢
  • 2018-06-20
  • 1970-01-01
  • 2016-08-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-03
相关资源
最近更新 更多