readBUGSmodel: Create a NIMBLE BUGS model from a variety of input formats,...

Description Usage Arguments Details Value Author(s) Examples

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

1
2
3
readBUGSmodel(model, data = NULL, inits = NULL, dir = NULL,
  useInits = TRUE, useData = TRUE, debug = FALSE,
  returnModelComponentsOnly = FALSE)

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 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.

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 {modelName}-data including extensions .R, .r, or .txt.

inits

(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

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 inits or by finding the '-inits' file corresponding to the input model file

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 JAGS (http://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

return returns a NIMBLE BUGS R model

Author(s)

Christopher Paciorek

Examples

1
2
3
4
5
6
7
8
9
code <- nimbleCode({
    x ~ dnorm(mu, sd = 1)
    mu ~ dnorm(0, sd = prior_sd)
})
data = list(prior_sd = 1, x = 4)
Rmodel <- readBUGSmodel(code, data = data, inits = list(mu = 0))
Rmodel$setData(data['x'])
Rmodel[['mu']]
Rmodel$nodes[['x']]$calculate()

thirdwing/nimble documentation built on May 31, 2019, 10:41 a.m.