Including opt-out as alternative specific constant in R Mlogit

两盒软妹~` 提交于 2019-12-23 03:17:13

问题


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.

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

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

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

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

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

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

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"),
)

and run the following model

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
)

Which results in the following error.

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

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? :)

Best, Henrik


回答1:


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

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

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
)

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



来源:https://stackoverflow.com/questions/31355145/including-opt-out-as-alternative-specific-constant-in-r-mlogit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!