Dirichlet multinomial example


Would it be possible to see an example of the dirichlet_multinomial distribution? I’m trying to define an array z which is indicators of cluster membership, for N individuals and R clusters, with posterior probability of cluster membership given by the vector pi_r_hat.

So I thought I’d need to use

N <- 1000
R <- 2
pi_r_hat <- beta(1,1,dim=R)
z <- dirichlet_multinomial(size = 1, alpha = pi_r_hat, n_realisations = N, dimension = R)

where size = 1 since all the elements of z are indicators (1 or 0) and there are N individuals so thus N realisations, and each realisation has dimension R because the individual can only be a member of one cluster.

But I keep getting an error “number of realisations should be 1000, but arguments had 2, 1 rows”

The examples on the greta doc pages seem to be just for multivariate_normal, which is quite a different type of distribution.

Any help would be gratefully received, thanks.


I think I’ve fixed it, now using

z <- dirichlet_multinomial(size=1, alpha=greta_array(rep(pi_r_hat,times=N),dim=c(N,R)), n_realisations=N, dimension = R)

Though if that is the correct solution, it would be very helpful if someone could update the documentation for the greta distributions, because it’s currently not clear from the documentation that the “alpha” parameter for dirichlet_multinomial should be multidimensional with 1 row per realisation.


1 Like