Bayesian modelling is flexible, but I’ve found that there are surprisingly few template models out there for even basic models like Poisson and negative binomial. The ones that exist are usually buried in a whole article that you have to pick through. So here are two simple examples used for count data, for reference:

###Poisson:

model
{
  # Weakly informative priors
  beta0 ~ dnorm(0, 1)
  beta1 ~ dnorm(0, 1)
  
  # N is the sample size
  for(i in 1:N)
  {
    # Y is the response variable (as a count)
    Y[i] ~ dpois(lambda[i])
    
    # X is the exposure variable, and offset.variable is the offset for Y
    # Using a log-link function for the count data
    log(lambda[i]) <- beta0 + 
      beta1 * X[i] + 
      log(offset.variable[i])
  } 
}

Negative binomial:

model
{
  # Weakly informative priors
  beta0 ~ dnorm(0, 1)
  beta1 ~ dnorm(0, 1)
  r ~ dunif(0, 50)
  
  # N is the sample size
  for(i in 1:N)
  {
    # Y is the response variable (as a count)
    Y[i] ~ dnegbin(p[i], r)
    
    # X is the exposure variable, and offset.variable is the offset for Y
    # Using a log-link function for the count data
    log(mu[i]) <- beta0 + 
      beta1 * X[i] + 
      log(offset.variable[i])
    
    # Transforms mu into p, which is used by the negative binomial distribution
    p[i] <- r/(r + mu[i])
  } 
}
Published on 12 September 2016 and tagged as
Browse articles... Browse tags...

Recent posts