| openbugs {R2WinBUGS} | R Documentation |
Wrapper to run OpenBUGS
Description
The openbugs function takes data and starting values
as input. It automatically calls the package BRugs and runs
something similar to BRugsFit. Not available in
S-PLUS.
Usage
openbugs(data, inits, parameters.to.save,
model.file = "model.txt", n.chains = 3, n.iter = 2000,
n.burnin = floor(n.iter/2),
n.thin = max(1, floor(n.chains * (n.iter - n.burnin) / n.sims)),
n.sims = 1000, DIC = TRUE,
bugs.directory = "c:/Program Files/OpenBUGS/",
working.directory = NULL, digits = 5, over.relax = FALSE, seed=NULL)
Arguments
data |
either a named list (names corresponding to variable names
in the |
inits |
a list with |
parameters.to.save |
character vector of the names of the parameters to save which should be monitored |
model.file |
file containing the model written in OpenBUGS code.
The extension can be either ‘.bug’ or ‘.txt’. If
‘.bug’, a copy of the file with extension ‘.txt’ will be
created in the |
n.chains |
number of Markov chains (default: 3) |
n.iter |
number of total iterations per chain (including burn in; default: 2000) |
n.burnin |
length of burn in, i.e. number of iterations to
discard at the beginning. Default is |
n.thin |
thinning rate. Must be a positive integer. Set
|
n.sims |
The approximate number of simulations to keep after thinning. |
DIC |
logical; if |
digits |
number of significant digits used for OpenBUGS input,
see |
bugs.directory |
directory that contains the OpenBUGS executable - currently unused |
working.directory |
sets working directory during execution of
this function; WinBUGS in- and output will be stored in this
directory; if |
over.relax |
If |
seed |
random seed (default is no seed) |
Value
A bugs object.
Note
By default, BRugs (and hence openbugs()) is quite verbose.
This can be controlled for the whole BRugs package by the option ‘BRugsVerbose’ (see options)
which is set to TRUE by default.
Author(s)
Andrew Gelman, gelman@stat.columbia.edu; modifications and packaged by Sibylle Sturtz, sturtz@statistik.tu-dortmund.de, and Uwe Ligges.
See Also
bugs and the BRugs package
Examples
# An example model file is given in:
model.file <- system.file(package = "R2WinBUGS", "model", "schools.txt")
# Let's take a look:
file.show(model.file)
# Some example data (see ?schools for details):
data(schools)
schools
J <- nrow(schools)
y <- schools$estimate
sigma.y <- schools$sd
data <- list ("J", "y", "sigma.y")
inits <- function(){
list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100),
sigma.theta = runif(1, 0, 100))
}
## or alternatively something like:
# inits <- list(
# list(theta = rnorm(J, 0, 90), mu.theta = rnorm(1, 0, 90),
# sigma.theta = runif(1, 0, 90)),
# list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100),
# sigma.theta = runif(1, 0, 100))
# list(theta = rnorm(J, 0, 110), mu.theta = rnorm(1, 0, 110),
# sigma.theta = runif(1, 0, 110)))
parameters <- c("theta", "mu.theta", "sigma.theta")
## Not run:
## both write access in the working directory and package BRugs required:
schools.sim <- bugs(data, inits, parameters, model.file,
n.chains = 3, n.iter = 5000,
program = "openbugs", working.directory = NULL)
print(schools.sim)
plot(schools.sim)
## End(Not run)