Title: | Derive MCMC Parameters |
---|---|
Description: | Generates derived parameter(s) from Monte Carlo Markov Chain (MCMC) samples using R code. This allows Bayesian models to be fitted without the inclusion of derived parameters which add unnecessary clutter and slow model fitting. For more information on MCMC samples see Brooks et al. (2011) <isbn:978-1-4200-7941-8>. |
Authors: | Joe Thorley [aut, cre] , Ayla Pearson [aut] , Kirill Müller [aut] , Nadine Hussein [ctb] , Poisson Consulting [cph, fnd] |
Maintainer: | Joe Thorley <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.2.9003 |
Built: | 2024-11-18 05:55:02 UTC |
Source: | https://github.com/poissonconsulting/mcmcderive |
Takes an expression and removes the for loop and adds cbind
for arrays.
expression_vectorize(x)
expression_vectorize(x)
x |
An expression |
An expression
expression_vectorize(rlang::expr(for(i in 1:nObs) {eCount[i] <- b0})) expression_vectorize( rlang::expr( for(i in 1:length(LogLength)) {eWeightLength[i] <- b0 + bDayte * Dayte[i]} ) ) expression_vectorize( rlang::expr( for(i in 1:nObs) {eAnnual[i] <- bAnn[Ann[i]] + bSA[Site[i], Ann[i]]} ) )
expression_vectorize(rlang::expr(for(i in 1:nObs) {eCount[i] <- b0})) expression_vectorize( rlang::expr( for(i in 1:length(LogLength)) {eWeightLength[i] <- b0 + bDayte * Dayte[i]} ) ) expression_vectorize( rlang::expr( for(i in 1:nObs) {eAnnual[i] <- bAnn[Ann[i]] + bSA[Site[i], Ann[i]]} ) )
Generates an MCMC object with derived parameters from an MCMC object.
mcmc_derive(object, ...) ## S3 method for class 'nlist' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'nlists' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmc' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmc.list' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, parallel = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmcr' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, parallel = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmcrs' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, parallel = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... )
mcmc_derive(object, ...) ## S3 method for class 'nlist' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'nlists' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmc' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmc.list' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, parallel = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmcr' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, parallel = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... ) ## S3 method for class 'mcmcrs' mcmc_derive( object, expr, values = list(), monitor = ".*", primary = FALSE, parallel = FALSE, silent = getOption("mcmcderive.silent", FALSE), ... )
object |
An MCMC object. |
... |
Unused. |
expr |
A string of the R code defining the values of the derived parameter(s) with respect to the parameters in object. |
values |
A named list of additional R objects to evaluate in the R expression. |
monitor |
A regular expression specifying the derived parameter(s) in expr to monitor. |
primary |
A flag specifying whether to include the original primary parameters in the new MCMC object. |
silent |
A flag specifying whether to suppress messages and warnings. |
parallel |
A flag specifying whether to generate the derived parameters for each chain in parallel. |
It's important to note that parameters in the expression that also
occur in the original object are not included in the new object
unless primary = TRUE
in which case they are simply copied from the
original object to the new one.
This applies even when the primary parameters are redefined in values.
An MCMC object with the derived parameter(s).
mcmc_derive(nlist)
: Get derived parameters for an nlist::nlist-object()
mcmc_derive(nlists)
: Get derived parameters for an nlist::nlists-object()
mcmc_derive(mcmc)
: Get derived parameters for an coda::mcmc()
object
mcmc_derive(mcmc.list)
: Get derived parameters for an coda::mcmc.list()
object
mcmc_derive(mcmcr)
: Get derived parameters for an mcmcr::mcmcr-object()
mcmc_derive(mcmcrs)
: Get derived parameters for an mcmcr::mcmcrs-object()
mcmcr::mcmcr_example expr <- " log(alpha2) <- alpha gamma <- sum(alpha) * sigma" mcmc_derive(mcmcr::mcmcr_example, expr, silent = TRUE)
mcmcr::mcmcr_example expr <- " log(alpha2) <- alpha gamma <- sum(alpha) * sigma" mcmc_derive(mcmcr::mcmcr_example, expr, silent = TRUE)