setAndCalculate {nimble} | R Documentation |
Creates a nimbleFunction for setting the values of one or more model nodes, calculating the associated deterministic dependents and logProb values, and returning the total sum log-probability.
Description
This nimbleFunction generator must be specialized to any model object and one or more model nodes. A specialized instance of this nimbleFunction will set the values of the target nodes in the specified model, calculate the associated logProbs, calculate the values of any deterministic dependents, calculate the logProbs of any stochastic dependents, and return the sum log-probability associated with the target nodes and all stochastic dependent nodes.
Usage
setAndCalculate(model, targetNodes)
setAndCalculateDiff(model, targetNodes)
Arguments
model |
An uncompiled or compiled NIMBLE model. This argument is required. |
targetNodes |
A character vector containing the names of one or more nodes or variables in the model. This argument is required. |
Details
Calling setAndCalculate(model, targetNodes)
or setAndCalculate(model, targetNodes)
will return a nimbleFunction object whose run
function takes a single, required argument:
targetValues: A vector of numeric values which will be put into the target nodes in the specified model object. The length of this numeric vector much exactly match the number of target nodes.
The difference between setAndCalculate
and setAndCalculateDiff
is the return value of their run
functions. In the former, run
returns the sum of the log probabilities of the targetNodes
with the provided targetValues
, while the latter returns the difference between that sum with the new targetValues
and the previous values in the model
.
Author(s)
Daniel Turek
Examples
code <- nimbleCode({ for(i in 1:3) { x[i] ~ dnorm(0,1); y[i] ~ dnorm(0, 1)}})
Rmodel <- nimbleModel(code)
my_setAndCalc <- setAndCalculate(Rmodel, c('x[1]', 'x[2]', 'y[1]', 'y[2]'))
lp <- my_setAndCalc$run(c(1.2, 1.4, 7.6, 8.9))