[This article was first published on Statforbiology, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here) Want to share your content on R-bloggers? click here if you have a blog, or here if you don't. There is a quote I really love from Marc Kéry’s book, “Introduction to WinBUGS for Ecologists” (2010, p. 11): “WinBUGS helps free the modeler in you.” And it’s so true!

Once you deeply understand a statistical model in all its moving parts, translating it into BUGS code feels remarkably logical and natural. The downside? More often than not, the resulting code turns out to be very problem-specific.

If you want to reuse it for a slightly different experimental setup, you usually end up doing a lot of tedious copy-pasting and editing. Take ANOVA models with all their different “flavors”: one-way, two-way with interaction, nested, randomized blocks, and so on. These models are the bread and butter of agricultural research and genotype trials.

While coding them individually in BUGS isn’t overly difficult, transitioning from one model structure to another requires manual code tweaks. And as anyone who has worked with BUGS/JAGS knows, spotting a subtle typo in BUGS code can easily eat up your entire afternoon… For example, consider a field experiment where seven wheat genotypes were compared in a field trial laid out as a randomized complete block design with three replicates.

The data comes from statforbiology, the companion R package for this blog. Let’s load the package and data: library(statforbiology) dataset