1
$\begingroup$

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?

$\endgroup$
2
$\begingroup$

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
  }
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Old_Mortality Aug 14 '17 at 9:07
  • $\begingroup$ @Old_Mortality check my edit. $\endgroup$ – Tim Aug 14 '17 at 10:02

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.