I am trying to read some WinBUGS/OpenBUGS examples to figure out how to specify models. I can't seem to understand where the probabilistic dnorm, dunif etc. functions are sampling from the distribution and where they are calculating likelihoods. Also, does the order of the statements matter, because it seems that the order is reversed. The statements seem to use variables not defined yet. For example, on page 50 of the book "Introduction to WinBUGS for Ecologists", is a small example:
model(
# priors
pop.mean ~ dunif(0,5000)
prec <- 1/pop.variance
pop.variance <- pop.sd * pop.sd
pop.sd ~ dunif(0,100)
# likelihood
for (i 1:nobs) {
m[i] ~ dnorm(pop.mean, prec)
}
)
It seems that pop.mean ~ dunif(0,5000) samples pop.mean from a uniform distribution while m[i] ~ dnorm(pop.mean, prec) does not sample m[i] but calculates a part of the likelihood that is used to reject/accept the move. But there is no difference in the syntax! Also prec is calculated using pop.variance before pop.variance has been defined. What if we had written it the other way round? Would it be the same model?