130 Bayesian Methods in Health Economics
The loop is delimited by two curly brackets and every instruction contained
within the two brackets is replicated for N times. Quantities that vary with
each value of the index i need to be defined using the syntax variable[index],
e.g. in this case y[i].
Notice that not all the quantities defined inside a loop depend on the index
i. For example, the regression coefficients alpha and beta are scalars that do
not vary with the different data points. Hence they are not associated with the
[i] notation. However, all nodes in the left-hand side of a statement inside a
loop must be defined as a function of the index. For example, if we coded
model {
for (i in 1:N) {
y[i] ~ dnorm(mu[i],tau)
mu <- alpha + beta*X[i]
...
then