simNodesMV | R Documentation |
simulate, calculate, or get the existing log probabilities for values in a modelValues object using a NIMBLE model
simNodesMV(model, mv, nodes)
calcNodesMV(model, mv, nodes)
getLogProbNodesMV(model, mv, nodes)
model |
A nimble model. |
mv |
A modelValues object in which multiple sets of model variables and their corresponding logProb values are or will be saved. |
nodes |
A set of nodes. If none are provided, default is all |
simNodesMV
simulates values in the given nodes and saves them in mv
. calcNodesMV
calculates these nodes for each row of mv
and returns a vector of the total log probabilities (densities) for each row. getLogProbNodesMV
is like calcNodesMV
without actually doing the calculations.
Each of these will expand variables or index blocks and topologically sort them so that each node's parent nodes are processed before itself.
getLogProbMV
should be used carefully. It is generally for situations where the logProb values are guaranteed to have already been calculated, and all that is needed is to query them. The risk is that a program may have changed the values in the nodes, in which case getLogProbMV
would collect logProb values that are out of date with the node values.
from simNodesMV
: NULL. from calcNodesMV
and getLogProbMV
: a vector of the sum of log probabilities (densities) from any stochastic nodes in nodes
.
m
. (simNodesMV
only). Number of simulations requested.
saveLP
. (calcNodesMV
only). Whether to save the logProb values in mv
. Should be given as TRUE
unless there is a good reason not to.
Clifford Anderson-Bergman
code <- nimbleCode({
for(i in 1:5)
x[i] ~ dnorm(0,1)
})
myModel <- nimbleModel(code)
myMV <- modelValues(myModel)
Rsim <- simNodesMV(myModel, myMV)
Rcalc <- calcNodesMV(myModel, myMV)
Rglp <- getLogProbNodesMV(myModel, myMV)
## Not run:
cModel <- compileNimble(myModel)
Csim <- compileNimble(Rsim, project = myModel)
Ccalc <- compileNimble(Rcalc, project = myModel)
Cglp <- compileNimble(Rglp, project = myModel)
Csim$run(10)
Ccalc$run(saveLP = TRUE)
Cglp$run() #Gives identical answers to Ccalc because logProbs were saved
Csim$run(10)
Ccalc$run(saveLP = FALSE)
Cglp$run() #Gives wrong answers because logProbs were not saved
result <- as.matrix(Csim$mv)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.