Learn R Programming

HydeNet (version 0.10.11)

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

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.

Details

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

See Also

jags.model

Examples

Run this code
# NOT RUN {
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)
                
# }

Run the code above in your browser using DataLab