使用嵌套多项logit模型预测()

时间:2017-06-15 13:35:42

标签: r nested mlogit

我正在使用mlogit中的R包来创建一个医疗保健提供者选择的嵌套多项logit模型,给出我的选择数据。数据如下所示:

          ID   RES    weight age  wealth    educ married urban partnerAge totalChildren survivingChildren anyANC
1.0  2468158 FALSE 0.2609153  29    Poor Primary       1     0         31             4                 4      1
1.1  2468158  TRUE 0.2609153  29    Poor Primary       1     0         31             4                 4      1
1.2  2468158 FALSE 0.2609153  29    Poor Primary       1     0         31             4                 4      1
1.3  2468158 FALSE 0.2609153  29    Poor Primary       1     0         31             4                 4      1
2.0 14233860 FALSE 0.2754970  19 Poorest Primary       1     0         30             1                 1      1
2.1 14233860  TRUE 0.2754970  19 Poorest Primary       1     0         30             1                 1      1
2.2 14233860 FALSE 0.2754970  19 Poorest Primary       1     0         30             1                 1      1
2.3 14233860 FALSE 0.2754970  19 Poorest Primary       1     0         30             1                 1      1
    outlier50Km optout alt               spa     mes   dist      bobs  cobs    Q fees chid educSec
1.0           0     -1   0              Home    Home  0.000 0.0000000 0.000 0.00    0    1       0
1.1           0     -1   1     Health center  Public 13.167 0.4898990    NA 0.64    0    1       0
1.2           0     -1   2     Health center  Public 30.596 0.5202020    NA 0.56    0    1       0
1.3           0     -1   3 District hospital  Public 41.164 0.7171717 0.825 0.88    0    1       0
2.0           0     -1   0              Home    Home  0.000 0.0000000 0.000 0.00    0    2       0
2.1           0     -1   1     Health center Mission 14.756 0.7676768    NA 0.64    1    2       0
2.2           0     -1   2     Health center  Public 41.817 0.3787879    NA 0.56    0    2       0
2.3           0     -1   3 District hospital  Public 50.419 0.7171717 0.825 0.88    0    2       0

其中spa, mes, dist, bobs, cobs, Q,fees是提供者的特征以及特定于个人的其余变量。这些数据是长格式的,这意味着每个人都有四行,反映了她的四个选择(alt = 0:3),其中RES是响应变量。

非嵌套模型表现得恰当

f.full <- RES ~ 0 + dist + Q + bobs + fees + spa | 0 + age + wealth + educSec + married + urban + totalChildren + survivingChildren
choice.ml.full <- mlogit(formula = f.full, data = data, weights = weight)
predict(choice.ml.full, data[1:8,])

             0         1          2          3
[1,] 0.1124429 0.7739403 0.06893341 0.04468343
[2,] 0.4465272 0.3107375 0.11490317 0.12783210

然而,通过模型拟合的所有度量,嵌套模型优于非嵌套模型。嵌套模型适当地给出了系数:

ns2 <- mlogit(formula = f.full, nests = list(home = "0", useCare = c("1", "2", "3")), data = data, weight = weight, un.nest.el = TRUE)
summary(ns2)
Call:
mlogit(formula = f.full, data = data, weights = weight, nests = list(home = "0", 
    useCare = c("1", "2", "3")), un.nest.el = TRUE)

Frequencies of alternatives:
       0        1        2        3 
0.094378 0.614216 0.194327 0.097079 

bfgs method
23 iterations, 0h:0m:13s 
g'(-H)^-1g = 9.51E-07 
gradient close to zero 

Coefficients :
                        Estimate Std. Error t-value  Pr(>|t|)    
dist                  -0.0336233  0.0040136 -8.3773 < 2.2e-16 ***
Q                      0.1780058  0.0768181  2.3172 0.0204907 *  
bobs                  -0.0695695  0.0505795 -1.3754 0.1689925    
fees                  -0.8488132  0.1001928 -8.4718 < 2.2e-16 ***
etc...

但是,如果我尝试预测单个人,我会收到以下错误:

predict(ns2, data[1:4,])
Error in apply(Gl, 1, sum) : dim(X) must have a positive length

如果我尝试预测多个人,则会出现另一个错误:

predict(ns2, data[1:8,])
Error in solve.default(crossprod(attr(x, "gradi")[, !fixed])) : 
  Lapack routine dgesv: system is exactly singular: U[5,5] = 0

非常感谢任何帮助。

0 个答案:

没有答案