# How can I model a proportion with BUGS/JAGS/STAN?

I am trying to build a model where the response is a proportion (it is actually the share of votes a party gets in constituencies). Its distribution is not normal, so I decided to model it with a beta distribution. I also have several predictors.

However, I don’t know how to write it in BUGS/JAGS/STAN (JAGS would be my best choice, but it doesn’t really matter). My problem is that I make a sum of parameters by predictors, but then what can I do with it?

The code would be something like this (in JAGS syntax), but I don’ know how to “link” the y_hat and y parameters.

for (i in 1:n) {
y[i] ~ dbeta(alpha, beta)

y_hat[i] <- a + b * x[i]
}


(y_hat is just the cross-product of parameters and predictors, hence the deterministic relationship. a and b are the coefficients which I try to estimate, x being a predictor).

The beta regression approach is to reparameterize in terms of $\mu$ and $\phi$. Where $\mu$ will be the equivalent to y_hat that you predict. In this parameterization you will have $\alpha=\mu\times\phi$ and $\beta=(1-\mu) \times \phi$. Then you can model $\mu$ as the logit of the linear combination. $\phi$ can either have its own prior (must be greater than 0), or can be modeled on covariates as well (choose a link function to keep it greater than 0, such as exponential).

Possibly something like:

for(i in 1:n) {
y[i] ~ dbeta(alpha[i], beta[i])
alpha[i] <- mu[i] * phi
beta[i]  <- (1-mu[i]) * phi
logit(mu[i]) <- a + b*x[i]
}
phi ~ dgamma(.1,.1)
a ~ dnorm(0,.001)
b ~ dnorm(0,.001)