Details of the NIMBLE MCMC engine handling of derived quantities, which are deterministic functions that can be calaculated and recorded after each MCMC sampling iteration.
derived_BASE()derived_mean(model, mcmc, interval, control)
derived_variance(model, mcmc, interval, control)
derived_logProb(model, mcmc, interval, control)
derived_predictive(model, mcmc, interval, control)
(uncompiled) model on which the MCMC is to be run
(uncompiled) MCMC object
interval (of MCMC iterations) at which the derived quantity is calculated
named list that controls the precise behavior of the derived quantity calculation, with elements specific to type of derived quantity.
The mean and variance derived quantity functions calculate the running mean and variance, respectively, for each node specified in the nodes argument. If added to an MCMC configuration object using the addDerivedQuantity method, then a value of the interval argument may also be provided to addDerivedQuantity. In that case, the value of interval specifies the number of MCMC iterations between calculations of the statistic. When the statistic is calculated, only the current value of each node is used to update the statistic. For example, if interval is 2, then every other MCMC iteration is used to calculate an updated value of the statistic. If no value of interval is provided as an argument to addDerivedQuantity, then the default value is the thinning interval thin of the MCMC.
The mean and variance derived quantity functions both accept the following control list elements:
nodes. The set of model nodes used for tracking the statistic.
recordingFrequency. The frequency (number of calculations of the statistic) afer which the value of the statistic is saved. For example, if recordingFrequency is 1, then the value of the statistic is saved after every update of its value. But if recordingFrequency is 10, then the value of the statistic is only saved after every tenth update of its value. The dafault value of recordingFrequency is 0, which corresponds to a special case: the value of the statistic is only recorded a single time, which is on the final iteration of the MCMC chain.
The logProb derived quantity function calculates and records values of the log-density of individual nodes or (summed) groups of nodes. If added to an MCMC configuration object using the addDerivedQuantity method, then a value of the interval argument may also be provided to addDerivedQuantity. In that case, the value of interval specifies the number of MCMC iterations between recordings of the log-density values. For example, if interval is 2, then log-density values will be recorded upon every other MCMC iteration. If no value of interval is provided as an argument to addDerivedQuantity, then the default value is the thinning interval thin of the MCMC.
The logProb derived quantity function accepts the following control list elements:
nodes. The nodes argument determines the individual nodes, or (summed) groups of nodes, for recording log-density values. When provided as a character vector, the individual log-density of each node in this vector will be recorded. When provided as a list, each list element may contain one or mode node names, and separately for the node(s) in each element of the list, the summed log-density list will be calculated. In addition, the keyword ".all" may also be provided in either the vector or list argument, which corresponds to the set of all stochastic model nodes (including data).
silent. By default, the logProb derived quantity function will issue a warning when the nodes argument includes node names which are not present in the model. This warning may be suppressed by setting silent to TRUE.
The predictive derived quantity function simulates the values of posterior predictive nodes in the model and stores these simulated values. This may be useful when a model structure includes posterior predictive nodes (or deterministically defined posterior derived quantities), but for reasons of efficiency, these nodes may not undergo MCMC sampling. In such cases, the predictive derived quantity function may be assigned to these nodes, and when executed it will simulate new values for these nodes and record the simulated values.
When added to an MCMC configuration object using the addDerivedQuantity method, a value of the interval argument may also be provided to addDerivedQuantity. In that case, the value of interval specifies the number of MCMC iterations between operations of the predictive function. For example, if interval is 2, then prediction and storing values takes place every other MCMC iteration. If no value of interval is provided as an argument to addDerivedQuantity, then the default value is the thinning interval thin of the MCMC.
The predictive derived quantity function accepts the following control list elements:
nodes. The nodes argument defines the predictive nodes which will have their values recorded and returned. The predictive function will automatically determine which nodes upstream of nodes need to be simulated, prior to storing the values of nodes. If omitted, the default set of nodes will be all (non-data) terminal model nodes. In addition, specifying the value nodes = ".all" will take nodes to be all predictive nodes in the model (all deterministic and stochastic nodes which have no downstream data dependencies).
simNodes. The simNodes specifies the set of model nodes which will be simulated, prior to recording the values of nodes. If ommited, which would be the usual case, simNodes will automatically represent the set of all model nodes which must be simulated in order to reach the predictive nodes. By providing simNodes, more fine-grained control of the simulation process is possible, including omitting simulation of some nodes.
sort. The sort argument determines whether the simulation of simNodes takes place in topological order. This argument has a default value of TRUE. When specified as FALSE the simulation of simNodes will take place in the order in which they were specified in the simNodes argument, which may not be in their natural order of dependency.
silent. By default, the predictive derived quantity function will issue a warning when the simNodes argument includes node names which are being updated by some sampler function in the MCMC. This warning may be suppressed by setting silent to TRUE.
Daniel Turek
configureMCMC addDerivedQuantity buildMCMC runMCMC nimbleMCMC
if (FALSE) {
conf <- configureMCMC(model)
conf$addDerivedQuantity("mean", nodes = c("a", "b"))
conf$addDerivedQuantity("mean", nodes = "theta", interval = 5)
conf$addDerivedQuantity("variance", nodes = "x[1:4]", control = list(recordingFrequency = 10))
conf$addDerivedQuantity("logProb", nodes = c('alpha', 'beta'))
conf <- configureMCMC(model, mean = 'a', variance = 'b', logProb = TRUE)
}
Run the code above in your browser using DataLab