Consider a generic model for simple linear regression. The data are metric values, modeled as coming from a normal distribution that has mean parameter μ=β0+β1x1 and precision parameter τ (=1/σ2). The priors on the intercept and slope parameters (β0 and β1) are normal, and the prior on the precision is gamma.
Notice that the description of the model started with the nature of the data, then described the likelihood function, then described the prior. This is the sequential order of description that makes sense for communicating to people. First you have to know the nature of the data being modeled. Next, you have to know the choice of likelihood function. For example, the metric data might have been modeled by a normal distribution, or by a log-normal distribution, or by a Weibull distribution, or by a t distribution, or whatever. Each of those likelihood functions has different parameters. Once the likelihood function is specified, with its corresponding parameters, then it makes sense to talk about the prior on those parameters.
The JAGS/BUGS code, in all the book's programs, specifies the model details in that order: from data, to likelihood, to prior. For example, here is the model specification for simple linear regression:
But, unlike the JAGS/BUGS code, the hierarchical diagrams in the book put the data at the bottom and the priors on the top. This might feel "upside down" relative to the JAGS/BUGS code, but the diagrams are forced to be this way because of pre-existing conventions for drawing probability distributions. The convention is to put the parameter axis on the abscissa (x axis), with the probability density on the ordinate (y axis). Therefore the parameter being modeled must be oriented at the bottom, and the parameters describing the density must be at the top, like this:
Therefore, the hierarchical diagrams should always be read starting at the bottom, then working upward.
I actually much prefer to write my jags code in the same direction of hierarchical diagram. It fits how I think about code in general - that everything is described in terms of what came before (above it). Of course, jags doesn't care.
ReplyDelete