在 R Mlogit 中包括选择退出作为替代特定常量

Including opt-out as alternative specific constant in R Mlogit

我正在对硕士论文中治疗减肥的假设药物的属性偏好进行离散选择实验,我需要一点帮助。

我的设计是通用的,有 12 个选择集和三个备选方案:产品 A产品 B选择退出.

不知何故,我需要将选项退出作为替代特定常量包括在内,但似乎我在这里做错了什么。我对 12 个选择集的三个备选方案有 197 个响应,因此 197*12*3 个选择观察值 = 7,092

> head(choice3, 12*3)
id choice_id mode.ids choice noadveff tab infreq_3 cost weightloss weightlosssq optout
1        x1        A      0        1  -1       -1  550        3.5        12.25     -1
1        x1        B      0       -1   1        1   90        6.0        36.00     -1
1        x1        C      1        0   0        0    0        0.0         0.00      1
1       x10        A      0        1  -1        1   50        6.0        36.00     -1
1       x10        B      0       -1   1       -1  165        3.5        12.25     -1
1       x10        C      1        0   0        0    0        0.0         0.00      1
1       x11        A      0       -1  -1        1  165        2.0         4.00     -1
1       x11        B      1        1   1       -1   90        3.5        12.25     -1
1       x11        C      0        0   0        0    0        0.0         0.00     -1
1       x12        A      0       -1  -1        1  550        6.0        36.00     -1
1       x12        B      0        1   1       -1 1000        2.0         4.00     -1
1       x12        C      1        0   0        0    0        0.0         0.00      1
1       x13        A      0       -1  -1       -1   90        6.0        36.00     -1
1       x13        B      0        1   1        1 1000        6.0        36.00     -1
1       x13        C      1        0   0        0    0        0.0         0.00      1
1        x2        A      0       -1  -1       -1 1000        6.0        36.00     -1
1        x2        B      0        1   1        1  300        2.0         4.00     -1
1        x2        C      1        0   0        0    0        0.0         0.00      1
1        x3        A      0       -1  -1        1 1000        6.0        36.00     -1
1        x3        B      1        1   1       -1   50        6.0        36.00     -1
1        x3        C      0        0   0        0    0        0.0         0.00     -1
1        x4        A      0        1  -1        1  165        3.5        12.25     -1
1        x4        B      0       -1   1       -1  550        2.0         4.00     -1
1        x4        C      1        0   0        0    0        0.0         0.00      1
1        x5        A      0       -1  -1       -1  550        2.0         4.00     -1
1        x5        B      1        1   1        1   50        6.0        36.00     -1
1        x5        C      0        0   0        0    0        0.0         0.00     -1
1        x6        A      0        1  -1       -1  300        6.0        36.00     -1
1        x6        B      0       -1   1        1   50        3.5        12.25     -1
1        x6        C      1        0   0        0    0        0.0         0.00      1
1        x8        A      0       -1  -1        1  300        3.5        12.25     -1
1        x8        B      1        1   1       -1  165        6.0        36.00     -1
1        x8        C      0        0   0        0    0        0.0         0.00     -1
1        x9        A      0       -1   1       -1  300        6.0        36.00     -1
1        x9        B      0        1  -1        1   90        2.0         4.00     -1
1        x9        C      1        0   0        0    0        0.0         0.00      1

我正在为我的分类变量(noadfeff、tab、infreq_3 和 optout)使用效果编码

mode.ids 表示备选方案,即产品 A 或 B,或选择退出 (mode.ids == C)

已使用以下命令对 optout 变量进行编码,

choice2$optout <- ifelse(choice2$mode.ids == "C" & choice2$choice == 1, "1", "-1")

使用这个数据集,我为 mlogit-package 设置了数据

mlogit.all <- mlogit.data(choice2,
            choice = "choice",
            shape = c("long"),
            id.var = "id",
            alt.var = "mode.ids",
            varying = c("cost", "cost.square", "noadvef", "tab", "infreq_3", "weightloss", "optout", "costsq", "weightlosssq"),
)

和运行以下型号

model.all <- mlogit(formula = choice ~ noadveff + tab + infreq_3 + cost + weightloss | optout | 0 ,
                     data = mlogit.all,
                     rpar = c(noadveff = 'n', tab = 'n', infreq_3 = 'n', weightloss = 'n', optout = 'u'),
                     R = 100,
                     halton = NA,
                     print.level = 0,
                     panel = TRUE
)

这会导致以下错误。

Error in solve.default(H, g[!fixed]) : 
Lapack routine dgesv: system is exactly singular: U[8,8] = 0

没有 optout 的类似模型没有给出任何问题,所以我的 optout 变量一定是做错了什么。

希望您能看出问题出在哪里? :)

最好的, 亨里克

对不起, 我自己发现了错误 - 下面提供了解决方案,

choice2$optout <- ifelse(choice2$mode.ids == "C", "1", "-1")

因此,对于称为 C 的每个备选方案(即选项 out),我们的 ASC 等于 1

model.all <- mlogit(formula = choice ~ noadveff + tab + infreq_3 + cost + weightloss + optout | -1 | 0 ,
                     data = mlogit.all,
                     rpar = c(noadveff = 'n', tab = 'n', infreq_3 = 'n', weightloss = 'n'),
                     R = 100,
                     halton = NA,
                     print.level = 0,
                     panel = TRUE
)

之后模型将起作用,并为选择退出者生成 ASC。