Clinician's
corner

Back to main page

Programmer's
corner
So, you use WinBUGS a lot? Want more?
Patrick Blisle
Division of Clinical Epidemiology
McGill University Health Center
Montreal, Quebec CANADA
patrick.belisle@rimuhc.ca

Last modification: 10 sep 2015















Version 2.0 (September 2015)
RunWinBUGSScript
The running of WinBUGS Scripts made easier
[ RunWinBUGSScript is a Perl program that facilitates the running of WinBUGS scripts, especially when a series of WinBUGS scripts are to be submitted. Use of this program will also prevent crashes that may arise from time to time when running WinBUGS scripts through DOS-prompt batch command. ]


Why use RunWinBUGSScript

The following points are advantages to running your WinBUGS script yourself, that is, by typing the usual WinBUGS command at the DOS-prompt (not accounting for the advantage of not having to type a command at the DOS-prompt!)
  1. When a WinBUGS script contains a file path (either to a model file, a data file or an inits file) that is more than 119 characters long, it will crash! (If you didn't know that and fall into that trap one day, it may take some time to figure that out. Add to this that coda() WinBUGS script commands will fall into the same trap if file paths involved are more than 114 characters long...)

    RunWinBUGSScript will prevent this by writing a copy of the faulty file(s) to a shorter-named temporary location and rewriting the script accordingly; output files will also be saved to temporary location, if their original names are too long. All this is done transparently, and the output file(s) will be copied to its (their) final location(s) when RunWinBUGSScript closes. Thus, the user of RunWinBUGSScript need not worry about troublesome lengthy paths anymore.

  2. Used jointly with WriteWinBUGSScript, it can be used to monitor problematic (in terms of rare extreme values) nodes, such as exponential values of other monitored nodes (see section below for details).

    It can also be used to drop unused variables from data files (which would cause WinBUGS to crash) through WriteWinBUGSScript-generated comments.

  3. When called by dragging and dropping more than one script onto its desktop icon, RunWinBUGSScript will run each of them one after another (rather than simultaneously, which could inadvertantly lengthen the total runtime, as well as slow down your computer in a more noticable way).
Finally, note that RunWinBUGSScript will add the run time to the bottom of the WinBUGS text output file.


Getting node statistics for exp() or inv.logit() for some nodes

As discussed on the WriteWinBUGSScript page, directly monitoring nodes such as

odds.ratio <- exp(log.OR)

in WinBUGS models can be problematic and lead to trap error messages. The -exp command in WriteWinBUGSScript will add a comment to the script generated, as in

display(log)
check('c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/models/SomeModel.txt')
compile(1)
gen.inits()
update(1000)
set(log.OR)
update(1000)
stats(*)
density(log.OR)
history(log.OR)
save('c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/log/tmp.odc')
save('c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/log/tmp-WinBUGSlog.txt')
quit()
# when done, compute stats for exp() of log.OR

Of course, running this script directly from the DOS-prompt would not give any information about the exponentiated node at all, as it is a comment and hence is ignored. Running the same script with RunWinBUGSScript, however, will produce a WinBUGS text log file that includes node statistics about the exponentiated node, as in:
Node statistics
  node          mean     sd      MC error   2.5%    median   97.5%   start  sample   
  log.OR        0.02654  0.9779  0.02926    -1.973  0.01147  1.981   1001   1000  
	
  /odds ratio/
	
  exp(log.OR)   ->       ->      ->         0.1390  1.0115   7.2499  1001   1000  


Dropping variables from data files

RunWinBUGSScript will read comments about deleting variables; for example, see the bottom two lines of the WinBUGS script excerpted below –
check('c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/models/model.txt')
data('c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/data/list.txt')
data('c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/data/rectangle.txt')
# RunWinBUGSScript will drop the following variable(s) from file(s) above:
# datavar1 datavar2
These two lines were generated by WriteWinBUGSScript (see Dropping variables from data files section): RunWinBUGSScript will interpret them and make temporary copies of the modified data files, which will be used in place of the original data files in the modified WinBUGS script actually run. Consequently, the WinBUGS .odc output file may include unexpected paths to data files, as in

check(c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/models/SomeModel.txt)
model is syntactically correct
data(c:/DOCUME~1/patrick/LOCALS~1/Temp/_rwbs.txt)
data loaded
data(c:/DOCUME~1/patrick/LOCALS~1/Temp/_rwbs1.txt)
Don't worry! These files are the modified versions of data files listed in the original WinBUGS script submitted. The WinBUGS text log file is more informative about the true data files read with that regards as they list the original data files, followed by a comment relative to variables deletion.

check(c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/models/SomeModel.txt)
model is syntactically correct
data(c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/data/list.txt)
# from which the following variables was dropped:
# datavar2
data loaded
data(c:/users/pbelisle/My Documents/Home/MyProject/WinBUGS/data/rectangle.txt)
# from which the following variable was dropped:
# datavar1


How to use RunWinBUGSScript

RunWinBUGSScript is a program written in Perl. Please refer to my generic page on running Perl programs for instructions.


Additional tip

From the instructions section linked above, you know that the natural way to submit a script to RunWinBUGSScript is to drag-and-drop the text file in which the script was filed onto RunWinBUGSScript's desktop icon.

After running such a script and viewing the WinBUGS log file produced (whose name ends by -WinBUGSlog.txt), one may want to resubmit the script, after some modification to the model, the inits files, or even the data files. The natural way to resubmit the script is, again, to drag-and-drop it onto RunWinBUGSScript's desktop icon: however, since the user just had a look at the WinBUGS log file, it may be more convenient to just drag-and-drop that WinBUGS log file onto RunWinBUGSScript's desktop icon, rather than having to browse through Windows Explorer to find the script that produced it.

Avoiding trap errors from permission settings on Windows 7 and Windows Vista platforms

If you are working on a Windows 7 or Windows Vista platform and have run WinBUGS before, y ou may have already run into the cryptic Trap #060 error message illustrated to the right. This is due to restricted write permissions in c:\Program Files, where you may have installed WinBUGS.

WinBUGS must be installed in a directory where you have write permissions (e.g. in C:\Users\user name\Documents) for RunWinBUGSScript to run smoothly.



Download RunWinBUGSScript

RunWinBUGSScript is a free program. Download version 2.0, unzip and make sure RunWinBUGSScript finds WinBUGS by changing the path to WinBUGS14.exe: edit the file RunWinBUGSScript.pl and change the path found on the line
# our %My = (WinBUGS=> {path => "C:/Program Files (x86)/WinBUGS14/WinBUGS14.exe"});
and uncomment that line (by removing the leading sharp character (#)).
Be careful! Use forward slashes (/) rather than backslashes (\) in the path expression.