After having read the excellent Think Bayes from Allen Downey, I'm now diving deeper into Bayesian Analysis and learning MCMC with Stan.

The dice problem in Think Bayes goes like this:

Suppose I have a box of dice that contains a 4-sided die, a 6-sided die, an 8-sided die, a 12-sided die, and a 20-sided die. Suppose I select a die from the box at random, roll it, and get a 6. What is the probability that I rolled each die?

My goal is to model this with Stan. It seems that the observed data should follow an uniform distribution between 1 and a second parameter d that we're trying to guess. Probably d has a lower constraint of 4 and an upper constraint of 20. The following is my best guess of what the model should look like, with the obvious problem that d is not bounded to the set of hypothesis (and most likely with other issues):

data {
  int<lower=0> J; // number of draws
  int y[J];       // draws

parameters {
  real<lower=4,upper=20> d;

model {
  y ~ uniform(1, d);
  • $\begingroup$ DSL stands for Domain Specific Language. It's a common acronym, but still... I have taken it out. $\endgroup$ – Hugo Sereno Ferreira Apr 26 '15 at 14:29

You can't naturally use STAN for this problem because d is integer-valued and STAN's sampling only works for (and therefore admits) real numbers. This is explained in the manual. You could do some kind of kludge on the back end to round/truncate the posterior samples, though.

But the bigger problem with the model is that it supposes that, e.g., 9- and 7-sided dice exist. But actually, based on your statement of the problem, your model only admits parameter values of 4, 6, 8, 12, or 20 (uniformly). This can't be represented at all in STAN, integer parameter issues aside, because STAN needs to be able to work with a single contiguous interval for each parameter. I'm fairly good at working out how to "trick" STAN into doing what you want it to, but I don't think this model is possible. (If you disagree, please prove me wrong, though!)

If you need to do inference on this particular problem, just compute the posterior directly over a grid.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.