Parallel computing with WinBUGS/OpenBUGS
Description
Does the same job as bugs.fit
,
but parallel chanis are run on parallel workers, thus
computations can be faster (up to 1/n.chains
) for long MCMC runs.
Usage
1 2  bugs.parfit(cl, data, params, model, inits=NULL, n.chains = 3,
seed, program=c("winbugs", "openbugs", "brugs"), ...)

Arguments
cl 
A cluster object created by 
data 
A named list or environment containing the data. If an environment,

params 
Character vector of parameters to be sampled. 
model 
Character string (name of the model file), a function
containing the model, or a or 
inits 
Specification of initial values in the form of a
list or a function, can be missing.
If this is a function and using 'snow' type
cluster as 
n.chains 
Number of chains to generate, must be higher than 1. Ideally, this is equal to the number of parallel workers in the cluster. 
seed 
Vector of random seeds, must have 
program 
The program to use, not case sensitive. See 
... 
Other arguments passed to 
Details
Chains are run on parallel workers, and the results are combined in the end.
The seed must be supplied, as it is the user's responsibility to make sure that pseudo random sequences do not seriously overlap.
The WinBUGS implementation is quite unsafe from this regard,
because the pseudorandom number generator used by WinBUGS
generates a finite (albeit very long) sequence of distinct numbers,
which would eventually be repeated if the sampler
were run for a sufficiently long time.
Thus it's usage must be discouraged. That is the reason for the
warning that is issued when program = "winbugs"
.
OpenBUGS (starting from version 3.2.2) implemented a system
where internal state of the pseudo random number generator can be
set to one of 14 predefined states (seed values in 1:14
).
Each predefined state is 10^12 draws apart to avoid overlap in
pseudo random number sequences.
Value
An mcmc.list
object.
Author(s)
Peter Solymos, solymos@ualberta.ca
See Also
Sequential version: bugs.fit
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54  ## Not run:
## fitting with WinBUGS, bugs example
if (require(R2WinBUGS)) {
data(schools)
dat < list(J = nrow(schools),
y = schools$estimate,
sigma.y = schools$sd)
bugs.model < function(){
for (j in 1:J){
y[j] ~ dnorm (theta[j], tau.y[j])
theta[j] ~ dnorm (mu.theta, tau.theta)
tau.y[j] < pow(sigma.y[j], 2)
}
mu.theta ~ dnorm (0.0, 1.0E6)
tau.theta < pow(sigma.theta, 2)
sigma.theta ~ dunif (0, 1000)
}
param < c("mu.theta", "sigma.theta")
SEED < floor(runif(3, 100000, 999999))
cl < makePSOCKcluster(3)
if (.Platform$OS.type == "windows") {
sim < bugs.parfit(cl, dat, param, bugs.model, seed=SEED)
summary(sim)
}
dat2 < dclone(dat, 2, multiply="J")
if (.Platform$OS.type == "windows") {
sim2 < bugs.parfit(cl, dat2, param, bugs.model,
program="winbugs", n.iter=2000, n.thin=1, seed=SEED)
summary(sim2)
}
}
if (require(BRugs)) {
## fitting the model with OpenBUGS
## using the less preferred BRugs interface
sim3 < bugs.parfit(cl, dat2, param, bugs.model,
program="brugs", n.iter=2000, n.thin=1, seed=1:3)
summary(sim3)
}
if (require(R2OpenBUGS)) {
## fitting the model with OpenBUGS
## using the preferred R2OpenBUGS interface
sim4 < bugs.parfit(cl, dat2, param, bugs.model,
program="openbugs", n.iter=2000, n.thin=1, seed=1:3)
summary(sim4)
}
stopCluster(cl)
## multicore type forking
if (require(R2OpenBUGS) && .Platform$OS.type != "windows") {
sim7 < bugs.parfit(3, dat2, param, bugs.model,
program="openbugs", n.iter=2000, n.thin=1, seed=1:3)
summary(sim7)
}
## End(Not run)
