As Daniel pointed out, you can try to code up the Dirichlet
yourself using a *normalized* set of gammas. But that's
sub-optimal for clarity and for efficiency in Stan.
We have everything you need built-in. A basic Dirichlet-multinomial
with N observations over K categories looks like this:
data {
int K; // num dims
int N; // num observations
int y[N, K]; // multinomial observations
}
parameters {
real<lower=0> alpha;
simplex[K] theta[N];
}
model {
alpha ~ lognormal(0, 5); // or some other prior on alpha
for (n in 1:N) {
theta[n] ~ dirichlet(alpha);
y[n] ~ multinomial(theta[n]);
}
}
It'd be much more efficient to code up the compound Dirichlet-multinomial
by marginalizing out the theta. That's what you get in the beta-binomial,
but we don't have Dirichlet-multinomial built in.
- Bob
P.S. You can use matrices rather than all those hand-coded variables
and do all the linear algebra you do row- or column-wise with matrix ops,
but you don't need to if you choose the dimensions caefully.