1) The probabilistic dnorm, dunif etc. functions are just describing the probability distribution which the variable on the left hand side (lhs) is assumed to have. If the variable is a parameter, then it's a prior distribution. If the variable is data, then it's p(data | parameters).
2) The distribution is not what is used for sampling. Don't think that pop.mean ~ dunif(0,5000)
means that pop.mean
is actually drawn from a Uniform(0,5000) distribution when the code is executed! The sampling is done using various algorithms inside WinBUGS / JAGS. The code describes a statistical model, not an algorithm to be executed.
3) As Tomas points out, the order of statements doesn't matter.
prec <- 1/pop.variance
pop.variance <- pop.sd * pop.sd
pop.sd ~ dunif(0,100)
merely tells the underlying sampler that 1) the prior on pop.sd is a U(0,100) distribution, 2) pop.variance = pop.sd*pop.sd, and 3) prec = 1/pop.variance. You can rearrange those statements however you like without changing their meaning.
Pretty much everything that happens goes on under the hood of WinBUGS / JAGS. The software takes the statistical model, as described by the code, and processes it using whatever algorithms it determines are "best". I'll repeat: the code describes the model, it does not specify an algorithm for processing the model + data. This is the hardest thing to get about WinBUGS / JAGS, or functional programming languages in general (at least, it was for me,) and once you get it, programming becomes much easier.
External BUGS variants are the standard. Working within R may be convenient, but I'd be surprised if those packages are as mature and perform as well. Using a library which bridges R and the external program is usually the most common compromise.
I use the jags/rjags combo (jags might be roughly considered a dialect of bugs). I haven't tried the other bugs variants, but the reports I've heard are that jags's performance and ability to deal with numerical issues is a bit better than the other bugs variants. I find jags easy to use, but of course, you need some knowledge of bayesian data analysis to know how to use it.
Best Answer
Yes, you can. In Bayesian tools, it is very easy to get predictions. In your design matrix, just add new rows, with response variable set to NA. You can see concrete example here.