
model
{
  # Likelihood
  for( t in 1:Today ){
  for(s in 1:S){
  for(d in 0:D){
  n[t,s,(d+1)] ~ dnegbin(p[t,s,(d+1)],r)
  log(lambda[t,s,(d+1)]) <- alpha[t,s] + beta.logged[(d+1)] + inprod(X[t, 1:6], gamma[,s])
  # Conversions
  p[t,s,(d+1)] <- r/(r+lambda[t,s,(d+1)])
  }
  sum.n[t,s] <- sum(n[t,s,]) + m[t,s]
  }
  }
  # Prior for neg binomial rate
  r ~ dgamma(dispersion.prior.shape,dispersion.prior.rate)
  # Prior for alpha
  for( s in 1:S ){
  alpha[1,s] ~ dnorm(alpha1.mean.prior, alpha1.prec.prior)
  for( t in 2:Today ){
  alpha[t,s] ~ dnorm(alpha[t-1,s],tau2.alpha)
  }
  }
  ## Prior for beta
  beta.logged <- log(beta)
  beta ~ ddirch(beta.priors)

  # Priors for gamma (day-of-week covariate effects)
  # Estimate only 6 coefficients, excluding the last (Sunday) which is fixed as 0 for reference
  for(s in 1:S){
    for(j in 1:6) {
      gamma[j,s] ~ dnorm(gamma.mean.prior[j], gamma.prec.prior[j])
    }
  }
  
  # Prior for variance
  tau2.alpha ~ dgamma(alphat.shape.prior,alphat.rate.prior)
}