# Representing a Suite of Hypothesis with Stan

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);
}

• DSL stands for Domain Specific Language. It's a common acronym, but still... I have taken it out. Apr 26, 2015 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.