readBUGSmodel {nimble} | R Documentation |
Create a NIMBLE BUGS model from a variety of input formats, including BUGS model files
Description
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
Usage
readBUGSmodel(
model,
data = NULL,
inits = NULL,
dir = NULL,
useInits = TRUE,
debug = FALSE,
returnComponents = FALSE,
check = getNimbleOption("checkModel"),
calculate = TRUE,
buildDerivs = getNimbleOption("buildModelDerivs")
)
Arguments
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 |
data |
(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. |
inits |
(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. |
dir |
(optional) character string giving the directory where the (optional) files are located |
useInits |
boolean indicating whether to set the initial values, either based on |
debug |
logical indicating whether to put the user in a browser for debugging when |
returnComponents |
logical indicating whether to return pieces of model object without building the model. Default is FALSE. |
check |
logical indicating whether to check the model object for missing or invalid values. Default is given by the NIMBLE option 'checkModel'. See |
calculate |
logical indicating whether to run |
buildDerivs |
logical indicating whether to build derivative capabilities for the model. |
Details
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.
Value
returns a NIMBLE BUGS R model
Author(s)
Christopher Paciorek
See Also
Examples
## 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