Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nimCopy

Copying function for NIMBLE


Description

Copies values from a NIMBLE model or modelValues object to another NIMBLE model or modelValues. Work in R and NIMBLE. The NIMBLE keyword copy is identical to nimCopy

Usage

nimCopy(from, to, nodes = NULL, nodesTo = NULL, row = NA, rowTo = NA,
  logProb = FALSE, logProbOnly = FALSE)

Arguments

from

Either a NIMBLE model or modelValues object

to

Either a NIMBLE model or modelValues object

nodes

Vector of one or more node names of object from that will be copied from

nodesTo

Vector of one or more node names of object to that will be copied to. If nodesTo is NULL, will automatically be set to nodes

row

If from is a modelValues, the row that will be copied from

rowTo

If to is a modelValues, the row which will be copied to. If rowTo is NA, will automatically be set to row

logProb

A logical value indicating whether the log probabilities of the given nodes should also be copied (i.e. if nodes = 'x' and logProb = TRUE, then both 'x' and 'logProb_x' will be copied)

logProbOnly

A logical value indicating whether only the log probabilities of the given nodes should be copied (i.e. if nodes = 'x' and logProbOnly = TRUE, then only 'logProb_x' will be copied)

Details

This function copies values from one or more nodes (possibly including log probabilities for nodes) between models and modelValues objects. For modelValues objects, the row must be specified. This function allows one to conveniently copy multiple nodes, avoiding having to write a loop.

Author(s)

Clifford Anderson-Bergman

Examples

# Building model and modelValues object
simpleModelCode <- nimbleCode({
for(i in 1:100)
	x[i] ~ dnorm(0,1)
})
rModel <- nimbleModel(simpleModelCode)
rModelValues <- modelValues(rModel)

#Setting model nodes
rModel$x <- rnorm(100)
#Using nimCopy in R.
nimCopy(from = rModel, to = rModelValues, nodes = 'x', rowTo = 1)

#Use of nimCopy in a simple nimbleFunction
cCopyGen <- nimbleFunction(
	setup = function(model, modelValues, nodeNames){},
	run = function(){
		nimCopy(from = model, to = modelValues, nodes = nodeNames, rowTo = 1)
	}
)

rCopy <- cCopyGen(rModel, rModelValues, 'x')
## Not run: 
cModel <- compileNimble(rModel)
cCopy <- compileNimble(rCopy, project = rModel)
cModel[['x']] <- rnorm(100)

cCopy$run() ## execute the copy with the compiled function

## End(Not run)

nimble

MCMC, Particle Filtering, and Programmable Hierarchical Modeling

v0.11.0
BSD_3_clause + file LICENSE | GPL (>= 2)
Authors
Perry de Valpine [aut], Christopher Paciorek [aut, cre], Daniel Turek [aut], Nick Michaud [aut], Cliff Anderson-Bergman [aut], Fritz Obermeyer [aut], Claudia Wehrhahn Cortes [aut] (Bayesian nonparametrics system), Abel Rodrìguez [aut] (Bayesian nonparametrics system), Duncan Temple Lang [aut] (packaging configuration), Sally Paganin [aut] (reversible jump MCMC), Jagadish Babu [ctb] (code for the compilation system for an early version of NIMBLE), Lauren Ponisio [ctb] (contributions to the cross-validation code), Peter Sujan [ctb] (multivariate t distribution code)
Initial release
2021-04-16

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.