pbugs | R Documentation |
WinBUGS
or OpenBUGS
Models in ParallelRun WinBUGS
or OpenBUGS
models from your R
session running parallel instances of these programs, one per chain. In
this manner several cores (one per chain) are used to run the MCMC
simulation of the corresponding model. Results are returned in an object of
bugs
and pbugs
classes.
pbugs(data, inits, parameters.to.save, model.file,debug = FALSE, program =
c("winbugs", "openbugs"),bugs.directory = "default", cluster = NULL, pbugs.directory
= "default",slice = FALSE, OpenBUGS.pgm = "default", cluster_export = NULL, ...)
data |
List or character. Either a named list (names corresponding to
variable names in the |
inits |
Function or list (length == n.chains). List with |
parameters.to.save |
Character vector of the names of the parameters to
save which should be monitored. This argument is also required, with the
same format, by the |
model.file |
Function or character (length 1). File containing the model
written in |
debug |
Logical, default: FALSE. Open |
program |
Character (length 1), default argument: |
bugs.directory |
Character (length 1), default: system dependent
(Unix-Windows). The default argument calls to the corresponding default
argument of the |
cluster |
Integer (length 1), default: NULL. Number of computer cores to use for running the model. If not provided, the function sets it to the minimum of the number of available cores minus one the number of chains run. |
pbugs.directory |
Character (length 1). Path to the pbugs directory were
different copies (one per chain) of either |
slice |
Logical, default: FALSE. Should |
OpenBUGS.pgm |
Character (length 1), default: system dependent
(Unix-Windows). The default argument calls to the corresponding default
argument of the |
cluster_export |
Character, default: NULL. Additional objects to export to computer cores. |
... |
Additional arguments to be passed to |
This function basically executes parallel calls (one per chain) to
R2WinBUGS::bugs
, so it is possible to use almost all the
arguments associated to that function. The summary.only
argument of
bugs
can be only set equal to FALSE
in pbugs
.
The idea of the pbugs
implementation is to minimize code adaptation
from regular bugs
instances. Suitable code for the bugs
function should run in principle in parallel by simply calling to the
pbugs
function with the same arguments as the original bugs
call.
Aditionally, this function has some enhanced functionality as compared to
bugs
such as replacing WinBUGS
' adaptive rejection sampler
(DFreeARS
) by a Slice
sampler, to sort out some classical
'Traps', from R
. This option does not work with OpenBUGS
.
Note that when DIC == TRUE
in pbugs
, DICs and their
components are calculated as the mean of the different DICs returned per
each of the chains run. If convergence is appropriately achieved this
should not be hardly different to the DIC calcuted for all the chains
simulated.
The arguments in the returned pbugs
object are the same than
for any R2WinBUGS::bugs
object, plus the following:
exec_time |
Execution time taken by the function |
seed |
Seed used, for reproducible simulations |
n_cores |
Number of computer cores used |
R2WinBUGS::bugs
## Not run:
library(pbugs)
data(sample_df)
bugs_model <- function() {
for (i in 1:N) {
y[i] ~ dbern(pi[i])
logit(pi[i]) <- beta[1] + beta[2] * x1[i] + beta[3] * x2[i] + beta[4] * x3[i]
}
for (j in 1:4) {
beta[j] ~ dflat()
}
}
bugs_data <- with(sample_df, list(y = y, x1 = x1, x2 = x2, x3 = x3, N = length(y)))
bugs_init <- function() list(beta = rnorm(4, sd = .5))
bugs_pars <- c("beta", "pi")
result <- pbugs(data = bugs_data, inits = bugs_init, parameters.to.save = bugs_pars,
model.file = bugs_model, n.thin = 1, n.chains = 4)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.