I'm trying to write such likelihood using JAGS in R
(in order to estimate parameters $\xi$ and $\pi$, being $m$ fixed equal 7) using the "ones trick" and got stuck in defining the binomial coefficient (term3
). How would you define the binomial coefficient?
$$
P(Y=y)=\left\{
\pi\binom{m-1}{y-1} (1-\xi)^{y-1}\xi^{m-r}+(1-\pi){1\over m}\right\}
$$
This is my model:
model {
for (i in 1:N) {
term1[i] <- pai[i]*pow(1-csi[i],(y[i]-1))*pow(csi[i],(m-y[i]))
term2[i] <- (1-pai[i])*(1/m)
term3[i] <- logfact(m-1)/logfact(m-y[i]-1)*logfact(y[i])
L[i] <- term3[i]*term1[i]+term2[i]
phi[i] <- L[i]/C
ones[i] ~ dbern(phi[i])
csi[i] ~ dbeta (alfa, beta)
pai[i] ~ dunif (0,1)
}
}