compileJagsModel: Compile Jags Model from a Hyde Network

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/compileJagsModel.R

Description

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

Usage

1

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)
                

nutterb/HydeNet documentation built on July 13, 2020, 5:21 p.m.