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

时间:2015-07-11 08:31:56

标签: 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-variable已使用以下命令

编码
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-variable做错了。

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

最佳, 亨里克

1 个答案:

答案 0 :(得分:0)

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

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

因此,对于称为C的每个替代方案(即选项输出),我们有一个等于1的ASC

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。