Get a list of conditionally independent sets of nodes in a nimble model
Conditionally independent sets of nodes are typically groups of latent states whose joint probability (density) will not change even if any other non-fixed node is changed. Default fixed nodes are data nodes and parameter nodes (with no parent nodes), but this can be controlled.
getConditionallyIndependentSets(model, nodes, givenNodes, omit = integer(), inputType = c("latent", "param", "data"), stochOnly = TRUE, returnType = "names", returnScalarComponents = FALSE)
model |
A nimble model object (uncompiled or compiled). |
nodes |
A vector of node names or their graph IDs that are the starting nodes from which conditionally independent sets of nodes should be found. If omitted, the default will be all latent nodes, defined as stochastic nodes that are not data and have at least one stochastic parent node (possible with determinstic nodes in between). Note that this will omit latent states that have no hyperparameters. An example is the first latent state in some state-space (time-series) models, which is sometimes declared with known prior. See |
givenNodes |
A vector of node names or their graph IDs that should be considered as fixed and hence can be conditioned on. If omitted, the default will be all data nodes and all parameter nodes, the latter defined as nodes with no stochastic parent nodes (skipping over deterministic parent nodes). |
omit |
A vector of node names or their graph IDs that should be omitted and should block further graph exploration. |
inputType |
The method of graph exploration depends on what the nodes argument represents. For |
stochOnly |
Logical for whether only stochastic nodes should be returned (default = TRUE). If FALSE, both deterministic and stochastic nodes are returned. |
returnType |
Either |
returnScalarComponents |
If FALSE (default), multivariate nodes are returned as full names (e.g. |
This function returns sets of conditionally independent nodes. Multiple input nodes
might be in the same set or different sets, and other nodes (not in nodes
) will be included.
By default, deterministic dependencies of givenNodes are also
counted as given nodes. This is relevant only for parent nodes.
This allows the givenNodes to include only stochastic nodes. Say
we have A -> B -> C -> D. A and D are givenNodes. C is a latent
node. B is a deterministic node. By default, B is considered
given. Otherwise, other branches that depend on B would be grouped
in the same output set as C, but this is usually what is wanted.
Any use of the resulting output must ensure that B is calculated when
necessary, as usual with nimble's model-generic programming. To
turn off this feature, set
nimbleOptions(groupDetermWithGivenInCondIndSets = FALSE)
.
List of nodes that are in conditionally independent sets. With each set, nodes are returned in topologically sorted order. The sets themselves are returned in topologically sorted order of their first nodes.
Perry de Valpine
There is a non-exported function nimble:::testConditionallyIndependentSets(model, sets, initialize = TRUE)
that tests whether the conditional independence of sets is valid. It should be the case that nimble:::testConditionallyIndependentSets(model, getConditionallyIndependentSets(model), initialize = TRUE)
returns TRUE
.
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.