在R Mlogit中包括选择退出作为替代特定常量 [英] Including opt-out as alternative specific constant in R Mlogit

查看:97
本文介绍了在R Mlogit中包括选择退出作为替代特定常量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am doing a discrete choice experiment on preferences for attributes of a hypothetical drug treating weight loss in my master thesis, and I need a little help.

我的设计是通用的,有12个选择集,其中包含三个选择:产品A 产品B 选项输出.

My design is generic, and has 12 choice sets with three alternatives: Product A, Product B and Option out.

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

Somehow, I need to include option-out as an alternative specific constant, but it seems like I am doing something wrong here. I have 197 responses on 12 choice sets of three alternatives, hence 197*12*3 observations of choice = 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)使用效果编码

I am using effects coding for my categorical variables (noadfeff, tab, infreq_3 and optout)

mode.ids表示替代品,即产品A或B,或选项退出(mode.ids == C)

mode.ids indicate the alternatives, i.e. product A or B, or option-out (mode.ids == C)

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

The optout-variable has been coded with the following command,

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

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

Using this data-set I set up the data for the 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变量一定做错了.

The similar model without optout, does not give any problems, so I must be doing something wrong with my optout-variable.

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

I hope you can see where the issue is? :)

最好, 亨里克

推荐答案

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

Sorry, I found the error myself - solution provided beneath,

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

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

Hence, we have a ASC equal to 1 for each alternative called C (i.e. the option out)

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.

After which the model will work, and generate an ASC for option-out'ers.

这篇关于在R Mlogit中包括选择退出作为替代特定常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆