UserContributedCode

Contributed Code

One of the useful parts of BUGS has been the long list of examples, that were developed by the BUGS writers. But the range of things BUGS has been used for is much wider, so here are pieces of code from a wide variety of users, which you can use to understand the models, and adapt them for your own analyses.


If you want to contribute some code, read the instructions first! And follow them (please!).


BUGS Code:

RatsExample: The old standard

TadpoleSurvival: Quantitative genetics


Code for use with R:

BRugs and R2OpenBUGS

R2OpenBUGS is the OpenBUGS equivalent of R2WinBUGS. This allows an OpenBUGS analysis to be performed by calling a function in R. It works by automatically constructing an OpenBUGS script to perform the analysis, launching OpenBUGS in the background to run the script, then exiting OpenBUGS. It was originally motivated by simulation studies, where a WinBUGS analysis must be run repeatedly on different datasets. R2OpenBUGS now has a 'restart' feature that allows a user to retrieve OpenBUGS output to R, monitor the results, and then continue execution.


BRugs, on the other hand, allows OpenBUGS analyses to be run fully interactively from within R, without needing to launch the standalone OpenBUGS program. Each OpenBUGS menu or script command, such as checking the model, loading the data, and compiling, has its own R function. Graphs can be plotted using the graphical facilities of R. BRugs no longer comes with an OpenBUGS download. The latest version of OpenBUGS must be installed separately using the Windows installer or the Linux .tar.gz source package. BRugs automatically searches standard locations for the programs. BRugs works natively on 32-bit R under Windows by calling the 32-bit OpenBUGS shared library. Under Linux or 64-bit R Windows, BRugs uses a proxy program to call the shared library - therefore on these platforms BRugs is less efficient and stable.


Both BRugs and R2OpenBUGS are available from the CRAN repository of contributed R packages. To install them from within R, type

install.packages("BRugs")
install.packages("R2OpenBUGS") 


To install BRugs from source on Linux, the necessary 32-bit C development packages are required. Compilation has been successful on 64-bit Ubuntu using the g++-multilib package, and on 64-bit Fedora using the glibc-devel package. If you installed OpenBUGS to a non-default location, for example /home/chris/usr, type

R CMD INSTALL BRugs_0.7.1.tar.gz --configure-args='--with-openbugs=/home/chris/usr/lib/OpenBUGS'


The coda package also works with the files created by OpenBUGS.


Script conversion code

Larry Gould (Merck) has created an R function to convert WinBUGS script files to OpenBUGS script files. Chris Jackson (mrc-bsu.cam.ac.uk)has revised the code to fix some errors: Convert WinBUGS to OpenBUGS.


Code for use with SAS

This is a working example on using OpenBUGS with SAS. This is based on an earlier version of OpenBUGS. I haven't tried out the newer version. But I'll update it ASAP. The link to the example http://www.psychstat.org/us/article.php/84.htm

Mike K Smith (Pfizer) has updated his WinBUGSio macro to work with OpenBUGS: OpenBUGSio - SAS to OpenBUGS macro.

Using OpenBUGS online

A Web interface coded as WebBUGS for OpenBUGS is developed and can be accessed at http://webbugs.psychstat.org. It uses OpenBUGS and R as backend to conduct Bayesian analysis. The current server is for test only and therefore it is discouraged to run computationally intensive applications now.

Other CODE

UserContributedCode (last edited 2012-02-07 20:54:14 by JohnnyZhang)