readBUGSmodel
processes inputs providing the model and values for constants, data, initial values of the model in a variety of forms, returning a NIMBLE BUGS R model
readBUGSmodel(
model,
data = NULL,
inits = NULL,
dir = NULL,
useInits = TRUE,
debug = FALSE,
returnComponents = FALSE,
check = getNimbleOption("checkModel"),
calculate = TRUE,
buildDerivs = getNimbleOption("buildModelDerivs")
)
returns a NIMBLE BUGS R model
one of (1) a character string giving the file name containing the BUGS model code, with relative or absolute path, (2) an R function whose body is the BUGS model code, or (3) the output of nimbleCode
. If a file name, the file can contain a 'var' block and 'data' block in the manner of the JAGS versions of the BUGS examples but should not contain references to other input data files nor a const block. The '.bug' or '.txt' extension can be excluded.
(optional) (1) character string giving the file name for an R file providing the input constants and data as R code [assigning individual objects or as a named list], with relative or absolute path, or (2) a named list providing the input constants and data. If neither is provided, the function will look for a file named 'name_of_model-data' including extensions .R, .r, or .txt.
(optional) (1) character string giving the file name for an R file providing starting values as R code [assigning individual objects or as a named list], with relative or absolute path, or (2) a named list providing the starting values. Unlike JAGS, this should provide a single set of starting values, and therefore if provided as a list should be a simple list and not a list of lists.
(optional) character string giving the directory where the (optional) files are located
boolean indicating whether to set the initial values, either based on inits
or by finding the '-inits' file corresponding to the input model file
logical indicating whether to put the user in a browser for debugging when readBUGSmodel
calls nimbleModel
. Intended for developer use.
logical indicating whether to return pieces of model object without building the model. Default is FALSE.
logical indicating whether to check the model object for missing or invalid values. Default is given by the NIMBLE option 'checkModel'. See nimbleOptions
for details.
logical indicating whether to run calculate
on the model after building it; this will calculate all deterministic nodes and logProbability values given the current state of all nodes. Default is TRUE. For large models, one might want to disable this, but note that deterministic nodes, including nodes introduced into the model by NIMBLE, may be NA
.
logical indicating whether to build derivative capabilities for the model.
Christopher Paciorek
Note that readBUGSmodel
should handle most common ways of providing information on a model as used in BUGS and JAGS but does not handle input model files that refer to additional files containing data. Please see the BUGS examples provided with NIMBLE in the classic-bugs
directory of the installed NIMBLE package or JAGS (https://sourceforge.net/projects/mcmc-jags/files/Examples/) for examples of supported formats. Also, readBUGSmodel
takes both constants and data via the 'data' argument, unlike nimbleModel
, in which these are distinguished. The reason for allowing both to be given via 'data' is for backwards compatibility with the BUGS examples, in which constants and data are not distinguished.
nimbleModel
## Reading a model defined in the R session
code <- nimbleCode({
x ~ dnorm(mu, sd = 1)
mu ~ dnorm(0, sd = prior_sd)
})
data = list(prior_sd = 1, x = 4)
model <- readBUGSmodel(code, data = data, inits = list(mu = 0))
model$x
model[['mu']]
model$calculate('x')
## Reading a classic BUGS model
pumpModel <- readBUGSmodel('pump.bug', dir = getBUGSexampleDir('pump'))
pumpModel$getVarNames()
pumpModel$x
Run the code above in your browser using DataLab