WARNING: DON'T save these files by right-clicking in Explorer; instead, open the file and do "File-Save As", *OR* (better yet) open the file and copy-paste it into a .txt file to ensure proper decoding of carriage returns!!!
From within R, click "File" and pull down to "Change dir" to change your the working directory to the one where you stored the two above files (you'll see I stored my files in K:\book3). You will also need to edit the "setwd" command at the top of the BRugs file, or simply comment this line out (put a "#" at the beginning of the line).
Speaking of comments, to save copies of the plots that are created you may want to un-comment out the "postcript" and "dev.off" commands. Indeed, the first time you run this you may want to simply cut and paste the commands into R one line at a time, so you can see what each one does.
From within R, source the stacks_BRugs.txt file. This should call OpenBUGS 21 times (once for each data point), and ultimately obtain a plot of the two diagnostics.
This example is based on work by Dr. Haijun Ma, and follows the residual analysis portion (pp.33-38) of my intermediate Bayesian data analysis short course slides, which in turn follow Section 2.5 (pp. 79-86) and Exercise 22 (p. 104) of the Carlin and Louis book, Bayesian Methods for Data Analysis , published by Chapman and Hall/CRC Press/Taylor and Francis.
From within R, source the Power.BRugs file. This file generates the data (which is all fake here, since this is a design problem) and the initial values as well.
This example follows the clinical trial design portion (pp.39-44) of my intermediate Bayesian data analysis short course slides, which are in turn based on a Bayesian class project paper written by Joe Koopmeiners. The "classic" reference in this area is:
This material is all located on a separate website created by Brian Hobbs, current PhD student in the Division of Biostatistics at the University of Minnesota. The work is based on Section 3 of a paper by Hobbs and Carlin, submitted to the Journal of Biopharmaceutical Statistics.