1. Home
  2. BGIMPORT procedure

BGIMPORT procedure

Imports MCMC output in CODA format produced by WinBUGS or OpenBUGS (D.A. Murray).


INDEXFILE = text Name of file containing index for output files
OUTPREFIX = text Prefix name for the output files
WORKDIRECTORY = text Working directory to use; default current Genstat working directory
PNAMES = text Saves the names of the simulated nodes
NOUTFILES = scalar Number of output files or chains to read; default 1


SIMULATIONS = pointers Saves the simulations in a list of pointers, one for each Markov chain


BGIMPORT imports Markov Chain Monte Carlo (MCMC) output in CODA format produced by WinBUGS or OpenBUGS. Data imported using BGIMPORT can be used in the procedure BGPLOT. The monitored values from a MCMC can be saved in text format (CODA files) from WinBUGS or by using BGXGENSTAT. The CODA files consist of an output file for each chain showing the iteration number and value. In addition there is an index file containing a description of which lines of the output files correspond to which variable.

The name of the file containing the index, showing which rows of the output files correspond to which variables, is supplied using the INDEXFILE option. The string for the prefix for the output files is supplied using the OUTPREFIX option. With WinBUGS, the file names have the form index.txt, 1.txt, 2.txt, etc; here you need to set OUTPREFIX=''. Similarly, OpenBUGS produces files with names using the form CODAindex.txt, CODAchain1.txt, and so on; here you need to set OUTPREFIX='CODAchain'. By default, the working directory will be the current directory, but you can supply an alternative directory using the WORKDIRECTORY parameter. The names of the monitored nodes can be saved using the PNAMES option.

The data are saved using the SIMULATIONS parameter as a list of pointers where each pointer contains the simulations and associated information for each Markov chain. These can be input to BGPLOT, for plotting, using its own SIMULATIONS parameter.



See also


Commands for: Bayesian methods.


CAPTION 'BGIMPORT Example','Example from WinBUGS.',\
        !t('Binary dose-response data published by Bliss (1935), in which',\
        'the numbers of beetles killed after 5 hour exposure to carbon',\
        'disulphide at N=8 different concentrations are recorded.',\
        'Data analysed by logit model using WinBUGs.')\,
        !t('Note that WinBUGS or OpenBUGs must be installed on your system',\
        'to run this example.'); style=meta,3(plain)
" Specify WinBUGS model "
TEXT    tmodel; VALUES=!t(\
        '  for( i in 1 : N ) {',\
        '    r[i] ~ dbin(p[i],n[i])',\
        '    logit(p[i]) <- alpha + beta * (x[i] - mean(x[]))',\
        '    rhat[i] <- n[i] * p[i]',\
        '    phat[i] <- r[i]/n[i]',\
        '  }',\
        '  beta ~ dnorm(0.0,0.00001)',\
        '  alpha ~ dnorm(0.0,0.00001)',\
" Write the WinBUGS model to a file "
OPEN    'beetles-model.txt'; CHAN=2; FILE=output
PRINT   [CHANNEL=2; IPRINT=*; SQUASH=yes] tmodel; JUST=left
CLOSE   2; FILETYPE=output
" Data "
VARIATE x; VALUES=!(1.6907,1.7242,1.7552,1.7842,1.8113,1.8369,1.8610,1.8839)
VARIATE n; VALUES=!(59,60,62,56,63,59,62,60)
VARIATE r; VALUES=!(6,13,18,28,52,53,61,60)
TEXT    dnames; VALUES=!t(N,x,n,r)
POINTER [VALUES=N,x,n,r] data
" Initial values "
TEXT    ipnames; VALUES=!T('alpha','beta')
POINTER [NVALUES=ipnames] init
SCALAR  init1[1...2]; VALUE=100,-100
SCALAR  init2[1...2]; VALUE=-100,100
" Run WinBugs"
         DATA=data; IDATANAMES=dnames; NSAMPLES=5000; \
         INAMES=ipnames; NCHAIN=2] init1,init2
" Import results "
         OUTPREFIX='WBGCODA'; PNAMES=tnames; NOUT=2] sim[1,2]
PRINT    tnames
BGPLOT   [PLOT=trace; ARRANGEMENT=multiple] sim[]
Updated on March 8, 2019

Was this article helpful?