I am running a hierarchical Bayesian model and would like to use the "ones trick" to self-define a likelihood function, just to prevent the problems that dmulti() may have with zeros. To be able to use the "ones trick", I would first need to specify the pmf for multinomial distribution.

In this post, Martyn Plummer mentioned that we can actually get the likelihood of the Gamma distribution by using dgamma() directly, e.g.:

logGamma[i] <- log(dgamma(y[i], shape[i], rate[i]))

Based on above, I assumed it applies to other distribution functions too and wrote below code:

LikMulti[i,k]<- dmulti(y.comp[i,2:5,k],comp.p[i,1:4,k],y.comp[i,6,k])

where both y.comp[i,2:5,k] and y.comp[i,6,k] are both observations, and comp.p[i,1:4,k] is the expected population composition obtained from the process model.

However, when I run this, I obtained an error message like this:

 Error in jags.model("test.R", data = data, inits = inits, n.chains = length(inits),  : 
 Compilation error on line 186.
 Unknown function: dmulti

And my questions are:

  1. I wonder has anyone met the same error? As the dmulti() should be the right function to use for multinomial distribution, I wonder does this mean I cannot obtain likelihood of multinomial distribution from dmulti() directly?
  2. If I cannot obtain likelihood directly with dmulti(), I wonder is there any function that can help me put down the pmf of multinomial distribution in JAGS, as the pmf is quite a complicated one?
  • $\begingroup$ The correct syntax for dmulti has only two parameters based on JAGS 4.0 manual: pi and n, where pi is a vector of probabilities and n is the number of trials. $\endgroup$ – Márcio Augusto Diniz Oct 21 '17 at 6:04
  • $\begingroup$ Hi, Marcio, thanks for the reply! Yes I understand that usually the likelihood is specified by y.comp[i,2:5,k] ~ dmulti(comp.p[i,1:4,k],y.comp[i,6,k]). However, in order to self-define a likelihood function by using the "ones trick", i.e. specifying a new sampling distribution that JAGS doesn't have such as zero-inflated distribution, I have to specify the likelihood functions I'd like to contain in the mixture distribution individually by using "<-" and sum them all. $\endgroup$ – CYH Oct 21 '17 at 14:13
  • $\begingroup$ This part isn't included in the JAGS manual, but from the response by Martyn Plummer to post I mentioned above, it seems that the likelihood can be specified directly by using dgamma(y[i], shape[i], rate[i]), just like in R. From the discussion in the post, it seems to work well for dgamma, but it returns an error I don't understand when I applies it to dmulti. This raises my questions. $\endgroup$ – CYH Oct 21 '17 at 14:17
  • $\begingroup$ Based on Plummer's post, I am not sure if dgamma function is the same as the Gamma distribution function which also is also called by dgamma. Notice that he points out that the dgamma function follows the same syntax of the Gamma distribution function. Anyway, writing the likelihood of the multinomial distribution is not so hard in your case. Just ignore the constant: LikMulti[i,k] <- (y.comp[i,2,k]^comp.p[i,1,k])*(y.comp[i,3,k]^comp.p[i,2,k])*(y.comp[i,4,k]^comp.p[i,3,k])*(y.comp[i,5,k]^comp.p[i,4,k]) $\endgroup$ – Márcio Augusto Diniz Oct 22 '17 at 7:08
  • $\begingroup$ Thanks for the idea about putting down the pmf directly. I just came across this post today and found that there is actually an function that helps us putting down factorial in JAGS. This should be helpful. But I was still curious about why we can ignore the coefficient term? $\endgroup$ – CYH Oct 23 '17 at 1:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.