Solved – How do programs like BUGS/JAGS automatically determine conditional distributions for Gibbs sampling

bayesianbugsconditional probabilitygibbsjags

Seems like full conditionals are often quite difficult to derive, yet programs like JAGS and BUGS derive them automatically. Can someone explain how they algorithmically generate full conditionals for any arbitrary model specification?

Best Answer

Reading through the comments on the othe answers, I believe the correct answer to the question that was intended to be asked is "they don't", in general. As has been mentioned, they construct a DAG and look at the Markov blanket and then (roughly) do the following.

  1. If the Markov blanket around a node correspond to a full conditional that is in a lookup table (say, because it is conjugate) sample from using the technique in the lookup table.
  2. Else, check is the if the unnormalized full conditional density - which is trivial to calculate - is log-concave. If it is, use adaptive rejection sampling.
  3. Else, sample using Metropolis-within-Gibbs to sample from the distribution approximately. While this isn't an exact sample, it can be shown that this algorithm still leaves the posterior invariant.

This isn't exactly what is being done; for example, JAGS will use some other tricks to construct block updates. But this should give an idea of what they are doing.