Learn R Programming

postpack (version 0.5.4)

write_model: Export BUGS/JAGS model from function to file

Description

Performs the same basic function as R2OpenBUGS::write.model()

Usage

write_model(fun, file)

Value

Nothing, but file is written to disk.

Arguments

fun

A function object containing BUGS/JAGS model code

file

A character vector of length == 1: the name of the file to write to

Details

Performs the same basic function as R2OpenBUGS::write.model(), but with slightly better output (scientific notation, spacing, etc.). The main reason it was created for use in 'postpack' was to remove the need for using the 'R2OpenBUGS' package when not using OpenBUGS.

Examples

Run this code
if (interactive()) {
  # define some simple BUGS model as an R function
  # note the use of %_% to include a truncation
  mod = function() {
    # PRIORS
    mu ~ dnorm(0,0.001) %_% T(0,)
    sig ~ dunif(0,10)
    tau <- 1/sig^2

    # LIKELIHOOD
    for (i in 1:n) {
      y[i] ~ dnorm(mu, tau)
    }
  }

  # write model to a text file to be called by BUGS/JAGS
  write_model(mod, "model.txt")
}

Run the code above in your browser using DataLab