derived_quantities: Create a definition of derived quantities evaluated in R.

View source: R/derived-quantities.R

derived_quantitiesR Documentation

Create a definition of derived quantities evaluated in R.

Description

When the expression contains non-library functions/objects, and parallel processing is enabled, those must be named in the .globals parameter (hopefully we'll be able to detect those automatically in the future). Note that recompute_SBC_statistics() currently does not use parallel processing, so .globals don't need to be set.

Usage

derived_quantities(..., .globals = list())

Arguments

...

named expressions representing the quantitites

.globals

A list of names of objects that are defined in the global environment and need to present for the gen. quants. to evaluate. It is added to the globals argument to future::future(), to make those objects available on all workers.

Examples

# Derived quantity computing the total log likelihood of a normal distribution
# with known sd = 1
normal_lpdf <- function(y, mu, sigma) {
 sum(dnorm(y, mean = mu, sd = sigma, log = TRUE))
}

# Note the use of .globals to make the normal_lpdf function available
# within the expression
log_lik_dq <- derived_quantities(log_lik = normal_lpdf(y, mu, 1),
                                .globals = "normal_lpdf" )


hyunjimoon/SBC documentation built on March 15, 2024, 3:18 a.m.