Skip to content

Instantly share code, notes, and snippets.

@mbedward
Created August 21, 2018 07:16
Show Gist options
  • Save mbedward/850fe1923d9b87e3d3c5f9a66fb7e7ca to your computer and use it in GitHub Desktop.
Save mbedward/850fe1923d9b87e3d3c5f9a66fb7e7ca to your computer and use it in GitHub Desktop.
Model observed proportions as Beta distributed with JAGS
# Some test data for proportions with mean 0.4
p <- rbeta(20, 4, 6)
# JAGS model
modelTxt <- "model {
for(i in 1:length(p)) {
p[i] ~ dbeta(alpha, beta)
}
alpha <- mu * phi
beta <- (1-mu) * phi
logit(mu) <- a0
phi ~ dexp(0.1)
a0 ~ dnorm(0, 1)
}"
model <- jags.model(textConnection(modelTxt), data = list(p=p))
sims <- coda.samples(model, c("a0", "mu", "phi"), n.iter = 5000)
summary(sims)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment