Setting up a Discrete Choice Model in RStan

649 views
Skip to first unread message

krishna mohan

unread,
Oct 6, 2016, 3:50:27 PM10/6/16
to Stan users mailing list
Hi 

I'm a first time user of RStan. I 'm trying to setup a Hierarchical Bayes Random Effects model using RStan and R. I want to compare RStan results against the CBC/HB from Sawtooth

Thanks 

Krishna

Here is a description of the Discrete Choice /  Conjoint exercise:


1.       Each subject sees 3 profiles (generated from a combination of levels in the X1 to X5 independent factors) and they choose one profile per task. X1 has 2 levels and X2 to X5 have 3 levels each

2.       This represents one task and in similar way, each subject completes a total of 8 tasks

3.       I have data collected on 30 respondents

4.       Each respondent has 24 rows of data derived from 8 tasks, 3 profiles per task, There is no "None" option.

5.    Could some one point me to an example that I can learn from to specify my model? How do I specify dummy coding vs effects coding?

6.    Data for one respondent is shown below:

            ID           task         stim           x1           x2           x3           x4            x5     choice
250111223221
250112133130
250113131230
250121123230
250122212112
250123131110
250131212110
250132222112
250133133310
250141212110
250142131212
250143212130
250151221330
250152213332
250153233120
250161221330
250162112112
250163122220
250171221231
250172131310
250173212310
250181121221
250182212110
250183113230

Bob Carpenter

unread,
Oct 6, 2016, 4:59:51 PM10/6/16
to stan-...@googlegroups.com
The manual chapter on regression and the Gelman and Hill
book example-models (its own GitHub repo, linked from our
web doc page) should help. It's basically a hierarchical
multi-logit model.

Not sure what you mean by dummy vs. effects. But in Stan,
you're just going to be coding the likelihood and priors, so
as long as you know how to do that, that's how you code it.

Stan indexes categorical variables from 1 so you'll have to
add one to your choices.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

krishna mohan

unread,
Oct 6, 2016, 5:40:43 PM10/6/16
to Stan users mailing list
Thanks for Bob for getting back. I will look up that section for doing the initial coding and see how it works.

In Sawtooth CBC/HB / Latent Gold Choice / R package ChoiceModelR estimation of the attributes levels is done either as a Dummy Code or through Effects coding:

The difference may be coming from the language I'm using. So as I understand an IV factor with three levels will be dummy coded as

IV level 1 = 0 and level 2 and level 3 are estimated relative to level 1

L2    L3

1      0
0      1
0      0

Effects coding for same would be

L2    L3

1      0
0      1
-1    -1

I hope I have clarified my understand of dummy vs. effects coding of factor variables. I was wondering how Stan accepts that specification.

Krishna

Bob Carpenter

unread,
Oct 10, 2016, 1:03:03 AM10/10/16
to stan-...@googlegroups.com
I don't know any of those packages, don't know what "IV" is
or what dummy codes or effects are in this context.

In Stan, you just define the density you want. So if you can
write a density down, I can help code it in Stan. Or maybe someone
else can jump in who knows these models.

- Bob

Daniel Guhl

unread,
Oct 10, 2016, 1:14:47 PM10/10/16
to stan-...@googlegroups.com, sebasti...@hu-berlin.de
Hi Krishna,

A colleague and I are currently working on implementing the Mixed Logit Discrete
Choice model in R using Rstan. I think we'll be able to release our package/code within
the next 3-4 weeks. We are still testing the implementation in simulation
studies, I'll ping you when we finished testing...

In the meantime, you could look at this: http://eml.berkeley.edu/~train/foundations.pdf.
Check out the appendix :)

- Daniel
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.

krishna mohan

unread,
Oct 10, 2016, 2:48:46 PM10/10/16
to Stan users mailing list, sebasti...@hu-berlin.de
Hi Daniel

Thank you for your follow up and your feedback. I look forward to your package. I can test your package with a couple of real world 
data sets (varying from 6 predictors to 15 predictors in discrete choice settings) and benchmark it against both ChoiceModelR and Sawtooth CBC/HB for speed and accuracy

I have used bayesm, ChoiceModelR and I use Sawtooth CBC/HB for choice conjoint analyses.
Stan and RStan do represent a slight shift but I'm learning. I have just succeeded in executing a simple bivariate regression using RStan.

Krishna

krishna mohan

unread,
Oct 10, 2016, 3:17:30 PM10/10/16
to Stan users mailing list, sebasti...@hu-berlin.de
Daniel,

Thanks a lot for sharing the article with me. I have gone through the Appendix material A through C. I see the R and Stan implementation. I will study it further through the data sets I have and let you know how that goes.
I'm a kid in a candy store!

Krishna

On Monday, October 10, 2016 at 1:14:47 PM UTC-4, dg wrote:

krishna mohan

unread,
Oct 10, 2016, 3:32:59 PM10/10/16
to Stan users mailing list, sebasti...@hu-berlin.de
Daniel

I apologize for the number of different posts. Is it possible to get the table grapes data file? I find the complexity introduced through correlated coefficients very valuable and I would like to study that further.

Krishna

Daniel Guhl

unread,
Oct 10, 2016, 4:08:41 PM10/10/16
to stan-...@googlegroups.com
Hi Krishna, 

Is it possible to get the table grapes data file?
IDK, maybe you should ask the authors.

I can test your package with a couple of real world data sets (varying from 6 predictors to 15 predictors in discrete choice settings) and benchmark it against both ChoiceModelR and Sawtooth CBC/HB for speed and accuracy
Sounds good, I let you know when we finished the package.

Cheers,
Daniel
Reply all
Reply to author
Forward
0 new messages