Package 'mcmcderive'

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.9002
Built: 2024-06-11 04:31:43 UTC
Source: https://github.com/poissonconsulting/mcmcderive

Help Index


Convert New Expression

Description

Takes an expression and removes the for loop and adds cbind for arrays.

Usage

expression_vectorize(x)

Arguments

x

An expression

Value

An expression

Examples

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]]}
  )
)

MCMC Derive

Description

Generates an MCMC object with derived parameters from an MCMC object.

Usage

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),
  ...
)

Arguments

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.

Details

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.

Value

An MCMC object with the derived parameter(s).

Methods (by class)

Examples

mcmcr::mcmcr_example

expr <- "
 log(alpha2) <- alpha
 gamma <- sum(alpha) * sigma"

mcmc_derive(mcmcr::mcmcr_example, expr, silent = TRUE)