包括选择退出作为可选的特定常数在R Mlogit



在我的硕士论文中,我正在做一个关于一种假设的减肥药物的属性偏好的离散选择实验,我需要一点帮助。

我的设计是通用的,有12个选择集,有三个选择:产品A产品BOption out

不知何故,我需要包括option-out作为一个可选的特定常数,但似乎我在这里做错了什么。我对3个选项的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)的效果编码

模式。id表示备选项,即产品A或B,或退出选项(模式)。id == C)

optout变量已经用以下命令编码,

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

使用这个数据集,我为mlogit包

设置数据
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变量。

我希望你能看到问题在哪里?:)

最好的,Henrik

对不起,我自己发现了这个错误——解决方案如下,

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。