# How do I specify a Bayesian Beta binomial model, with predictor variables, for R2jags?

I want to have a beta-binomial Bayesian model, with R2jags. I understand I need something like this:

    for (i in 1:N) {
y[i] ~ dbinom(p,n[i])
p ~ dbeta(a,b)
}


Now suppose I have 2 types of subjects in my observations y, and I want to know whether 'type' makes a difference to p. I imagine I need some way to make a and b depend on my covariate 'type'. How is this done?

It is not really a "how to code it in JAGS" problem, but it is about defining the appropriate model for your data. If you want to include predictor variables for your data, this means you need a regression model. This means that you need something like

  for (i in 1:N) {
y[i] ~ dbinom(p[i], n[i])
logit(p[i]) <- REGRESSION MODEL DEFINITION
}


Check here for one example.

Regarding your comment, you could use a hierarchical model including a lower-level beta regression model, i.e. something like

  for (i in 1:N) {
y[i] ~ dbinom(p[i], n[i])
p[i] ~ dbeta(alpha[i], beta[i])
alpha[i] = phi[i] * mu[i]
beta[i] = phi[i] * (1 - mu[i])
logit(mu[i]) <- REGRESSION MODEL DEFINITION
phi[i] ~ SOME PRIOR
}

• Thank you. I had tried something along those lines, but I find that the binomial does not give me enough variance. Gelman (DBA, p 438) suggests using the beta-binomial, with -in my case- a different probability for each group, drawn from a beta distribution. – Old_Mortality Aug 14 '17 at 9:07
• @Old_Mortality check my edit. – Tim Aug 14 '17 at 10:02