Including opt-out as alternative specific constant in R Mlogit -
i doing discrete choice experiment on preferences attributes of hypothetical drug treating weight loss in master thesis, , need little help.
my design generic, , has 12 choice sets 3 alternatives: product a, product b , option out.
somehow, need include option-out alternative specific constant, seems doing wrong here. have 197 responses on 12 choice sets of 3 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 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 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 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 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 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 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 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 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 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 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 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 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 using effects coding categorical variables (noadfeff, tab, infreq_3 , optout)
mode.ids indicate alternatives, i.e. product or b, or option-out (mode.ids == c)
the optout-variable has been coded following command,
choice2$optout <- ifelse(choice2$mode.ids == "c" & choice2$choice == 1, "1", "-1")
using data-set set data 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 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 following error.
error in solve.default(h, g[!fixed]) : lapack routine dgesv: system singular: u[8,8] = 0
the similar model without optout, not give problems, must doing wrong optout-variable.
i hope can see issue is? :)
best, henrik
sorry, found error myself - solution provided beneath,
choice2$optout <- ifelse(choice2$mode.ids == "c", "1", "-1")
hence, have asc equal 1 each alternative called c (i.e. 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 model work, , generate asc option-out'ers.
Comments
Post a Comment