4

I'm trying to code a dirichlet-multinomial model using BUGS. Basically I have 18 regions and 3 categories per region. In example, Region 1: 0.50 belongs to Low, 0.30 belongs to Middle, and 0.20 belongs to High. The list goes on to Region 18 of course with varying proportions.The only code I got is this

`model  {
 for (i in 1:N) {
 x[1:3] ~ dmulti(p[],n[i])
 p[1:3] ~ ddirch(alpha[])
 }
 for (k in 1:3) {
 alpha[k] <- 1
 }
 }
 DATA list(n=c(38483, 2259, 1900),x=c(29256.42719, 1857.431404, 1548.007808, 29256.42719, 1857.431404, 1548.007808, 29256.42719, 1857.431404, 1548.007808), N=3)`

I shortened it to 3 regions first just for example. It states 'Dirichlet36' after clicking 'gen inits'. Please help me to code this.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3764358
  • 41
  • 1
  • 2
  • This isn't clear - if the x are multinomial they should be integers. Also the code you've given doesn't reproduce the error you've stated. It looks like the x and the p need to be matrices, e.g. x[i,1:3], p[i,1:3], and if x is supposed to be a matrix, it needs to be defined in the data as something like structure(.Data=..., .Dim=c()) – Chris Jackson Jun 27 '14 at 15:54

1 Answers1

5

This may be helpful (source):

Learning about the parameters of a Dirichlet distribution

Suppose as part of a model there are J probability arrays p[j, 1:K], j = 1, ..., J, where K is the dimension of each array and sum(p[j, 1:K]) = 1 for all j. We give each of them a Dirichlet prior:

      p[j, 1:K] ~ ddirch(alpha[])

and we would like to learn about alpha[]. However, the parameters alpha[] of a Dirichlet distribution cannot be stochastic nodes. The trick is to note that if delta[k] ~ dgamma(alpha[k], 1), then the vector with elements delta[k] / sum(delta[1:K]), k = 1, ..., K, is Dirichlet with parameters alpha[k], k = 1, ..., K. So the following construction should allow learning about the parameters alpha[]:

      for (k in 1:K) {
              p[j, k] <- delta[j, k] / sum(delta[j,])
              delta[j, k] ~ dgamma(alpha[k], 1)
      }

A prior can be put directly on the alpha[k]'s.

Pang
  • 9,564
  • 146
  • 81
  • 122
Silvia
  • 51
  • 2