Description Usage Arguments Details Value Choosing a Node Type Coding Factor Levels Validation Author(s) Examples
The relationship between a node and its parents must be defined
before the appropriate JAGS model statement can be constructed.
setNode is the utility by which a user can define the distribution
of the node and its relationship to its parents (usually through a model
of some sort).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
setNode( network, node, nodeType, nodeFitter, nodeFormula, fitterArgs = list(), decision = "current", utility = "current", fromData = !is.null(network$data), ..., nodeData = NULL, factorLevels = NULL, validate = TRUE, fitModel = getOption("Hyde_fitModel"), policyValues = factorLevels ) fromData() fromFormula()
A node within
a valid distribution. See the data set
the fitting function, such as
A formula object specifying the relationship between a
node and its parents. It must use as a term every parent of
Additional arguments to be passed to
A value of either
A value of either
Logical. Determines if a node's relationship is calculated
from the data object in
parameters to be passed to the JAGS distribution function. Each parameter
in the distribution function must be named. For
example, the parameters to pass to
A data frame with the appropriate data to fit the model for the node. Data passed in this argument are applied only to this specific node. No checks are performed to ensure that all of the appropriate variables (the node and its parents) are included.
A character vector used to specify the levels of factors
when data are not provided for a node. The order of factors follows the
order provided by the user. This argument is only used when the node type
Logical. Toggles validation of parameters given in
Logical. Toggles if the model is fit within the function call.
This may be set globally using
A vector of values to be used in the policy matrix when
the node is decision node. This may be left
fromData() help to control
Hyde determines the values of parameters passed to JAGS. If the
parameters passed in
params argument are to be calculated from the
data or inferred from the formula, these functions may be used as placeholders
instead of writing JAGS code in the
options(Hyde_fitModel=FALSE). This prevents
from fitting any models. Instead, the fitting is delayed until the user
writeJagsModel and all of the models are fit at the same time.
When using large data sets that may require time to run, it may be better to
leave this option
FALSE so that the models can all be compiled together
(especially if you are working interactively). Using
will cause the model to be fit and the JAGS code for the parameters to be
stored in the
Returns the modified
Many of the distribution functions defined in JAGS have an equivalen
distribution function in R. You may inspect the
frame to see the function names in each language. You may specify
the distribution function using the R name and it will be translated
to the equivalent JAGS function.
You may still use the JAGS names, which allows you to specify a
distribution in JAGS that does not have an R equivalent listed. Note,
however, that where R functions are supported,
the parameter names to be given following R conventions (See
RParameter column of
Of particular interest are
dcat, which are
functions in JAGS that have no immediate equivalent in R. They provide
Bernoulli and Multinomial distributions, respectively.
nodeFormula argument will accept any valid R formula. If desired, you
may use a specific formulation to indicate the presence of factor levels in the
formula. For instance, consider the case of a variable
y with a binary
x coded as 0 = No, and 1 = Yes. JAGS expects the
y ~ c * x == 1 (where
c is a constant). However, in
factor variables with a large number of levels, it can be difficult to remember
what value corresponds to what level.
HydeNet uses an internal (unexported) function within
setNode to allow
an alternate specification:
y ~ c * (x == "Yes"). So long as the factors in
the formula are previously defined within the network structure,
will translate the level into its numeric code.
Note that it is required to write
x == "Yes".
"Yes" == x will not
The validation of parameters is performed by comparing the values provided with
the limits defined in the
jagsDists$paramLogic variable. (look at
data(jagsDists, data='HydeNet'). For most node types, validation will
be performed for numeric variables. For deterministic variables, the validation
will only check that the parameter definition is a formula.
It is possible to pass character strings as definitions, but when this is done,
HydeNet assumes you are passing JAGS code. Unfortunately,
doesn't have to capability to validate JAGS code, so if there is an error in
the character string definition, it won't show up until you try to compile the
network. If you pass a character string as a parameter and leave
validate = TRUE, a message will be printed to indicate that validation
is being ignored. This message can be avoided by using
validate = FALSE
The two exceptions to this rule are when you pass
fromData() as the parameter definition. These will skip the validation
without warning, since the definition will be built by
HydeNet and be
proper JAGS code (barring any bugs, of course).
Jarrod Dalton and Benjamin Nutter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
data(PE, package="HydeNet") Net <- HydeNetwork(~ wells + pe | wells + d.dimer | pregnant*pe + angio | pe + treat | d.dimer*angio + death | pe*treat, data = PE) print(Net, d.dimer) #* Manually change the precision Net <- setNode(Net, d.dimer, nodeType='dnorm', mean=fromFormula(), sd=sqrt(2.65), nodeFormula = d.dimer ~ pregnant * pe, nodeFitter='lm') print(Net, d.dimer)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.