Skip to content

Instantly share code, notes, and snippets.

@takoika
Last active January 25, 2016 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takoika/58ddb0e8ff0ded27d2df to your computer and use it in GitHub Desktop.
Save takoika/58ddb0e8ff0ded27d2df to your computer and use it in GitHub Desktop.
Stan code for inferring probabilities of m-face dice from the number of occurrences of an outcome which is sum of two m-dice's outcomes.
data
{
int <lower=0> m; // The number of dice faces
int <lower=0, upper=N> x[2*m-1]; // The numbers of events. x[i] indeicates the number of occurences that a sum of two dices is i+1 in [2,...,2*m].
}
parameters
{
simplex[m] theta1; // Probability for each face.
simplex[m] theta2; // Probability for each face.
}
model {
vector [2*m-1] phi;
for (s in 2:2*m) {
phi[s-1] <- 0.;
for (a in max(1,s-6):min(6,s-1)) {
phi[s-1] <- phi[s-1]+theta1[a]*theta2[s-a]; // Summing up probabilities that a sum of two dice's outcomes equals s.
}
x ~ multinomial(phi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment