Learn R Programming

BRugs (version 0.8-2)

BRugsFit: BRugs' meta function

Description

This function takes model, data and starting values as input and automatically runs a simulation in BRugs.

Usage

BRugsFit(modelFile, data, inits, numChains = 3, parametersToSave,
    nBurnin = 1000, nIter = 1000, nThin = 1, coda = FALSE,
    DIC = TRUE, working.directory = NULL, digits = 5, seed=NULL,
    BRugsVerbose = getOption("BRugsVerbose"))

Arguments

modelFile
File containing the model written in OpenBUGS code, an R function that contains a BUGS model that is written to a temporary model file (see tempfile) using wri
data
Either a named list (names corresponding to variable names in the modelFile) of the data for the OpenBUGS model, or a vector or list of the names of the data objects used by the model. In these cases data are written i
inits
A list with numChains elements; each element of the list is itself a list of starting values for the OpenBUGS model, or a function creating (possibly random) initial values. In these cases inits are written into files
numChains
Number of Markov chains (default: 3).
parametersToSave
Character vector of the names of the parameters to save which should be monitored.
nBurnin
Length of burn in (before nIter iterations start).
nIter
Number of iterations (without burn in).
nThin
Every nThin-th iteration of each chain is stored.
coda
Determines the output format: if FALSE (default), a list containing sample and DIC statistics is returned. If TRUE, an mcmc.list object as known from the coda
DIC
Logical, whether to calculate and return the DIC.
working.directory
Sets working directory during execution of this function; data, inits and other files are written to / read from this directory if no other directory is explicitly given in those arguments. If NULL, th
digits
Number of significant digits used for OpenBUGS input, see formatC.
seed
Integer value from 1 to 14 defining the state of the random number generator - default is to not specify the state (see modelSetRN).
BRugsVerbose
Logical, whether BRugs is supposed to be verbose. This can be controlled for the whole BRugs package by by the option BRugsVerbose (see options) which is set to TRUE

Value

  • If coda is set to TRUE, an mcmc.list object as known from the coda package is returned, otherwise a list containg components
  • StatsA data frame containing sample statistics. See samplesStats.
  • DICThe DIC statistics, if DIC=TRUE, else NULL. See dicStats.

concept

  • OpenBUGS
  • WinBUGS
  • MCMC

See Also

BRugs, help.WinBUGS. Andrew Gelman proposes some print and plot methods that can be accessed by the openbugs (and bugs) and as.bugs.array functions in the CRAN package R2WinBUGS.

Examples

Run this code
## Prepare the example files in a temporary directory
exfiles <- dir(options()$OpenBUGSExamples, pattern="^Rats.*txt$", full.names=TRUE)
ok <- file.copy(exfiles, tempdir())
BRugsFit(data = "Ratsdata.txt", inits = "Ratsinits.txt",
    para = c("alpha", "beta"), modelFile = "Ratsmodel.txt",
    numChains = 1,
    working.directory = tempdir())

Run the code above in your browser using DataLab