Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

compileJagsModel

Compile Jags Model from a Hyde Network


Description

Generates the JAGS code from the Hyde network and uses it to create an object representing a Bayesian graphical model.

Usage

compileJagsModel(network, data = NULL, ...)

Arguments

network

An object of class HydeNetwork

data

A list of data values to be observed in the nodes. It is passed to the data argument of rjags::jags. Alternatively, a data frame representing a policy matrix may be provided to compile multiple JAGS models.

...

Additional arguments to be passed to jags.model

Details

compileJagsModel is a partial wrapper for jags.model. Running compileJagsModel(network) is equivalent to running jags.model(textConnection(writeNetworkModel(network))).

Value

Returns a compiledHydeNetwork object. The jags element of this object is suitable to pass to coda.samples. Otherwise, the primary function of the object is plotting the network with observed data shown.

Author(s)

Benjamin Nutter

See Also

jags.model

Examples

data(PE, package="HydeNet")
Net <- HydeNetwork(~ wells + 
                     pe | wells + 
                     d.dimer | pregnant*pe + 
                     angio | pe + 
                     treat | d.dimer*angio + 
                     death | pe*treat,
                     data = PE) 
  
                 
compiledNet <- compileJagsModel(Net, n.chains=5)

#* Generate the posterior distribution
Posterior <- HydeSim(compiledNet, 
                     variable.names = c("d.dimer", "death"), 
                     n.iter = 1000)
Posterior

#* For a single model (ie, not a decision model), the user may choose to 
#* use the \code{rjags} function \code{coda.samples}.
#* However, this does not have a succinct print method
library(rjags)
s <- coda.samples(compiledNet$jags, 
                  variable.names = c("d.dimer", "death"), 
                  n.iter=1000)

HydeNet

Hybrid Bayesian Networks Using R and JAGS

v0.10.11
MIT + file LICENSE
Authors
Jarrod E. Dalton <daltonj@ccf.org> and Benjamin Nutter <benjamin.nutter@gmail.com>
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.