Package 'mcmcr'

Title: Manipulate MCMC Samples
Description: Functions and classes to store, manipulate and summarise Monte Carlo Markov Chain (MCMC) samples. For more information see Brooks et al. (2011) <isbn:978-1-4200-7941-8>.
Authors: Joe Thorley [aut, cre] , Kirill Müller [ctb] , Nadine Hussein [ctb] , Ayla Pearson [ctb] , Poisson Consulting [cph, fnd]
Maintainer: Joe Thorley <[email protected]>
License: MIT + file LICENSE
Version: 0.6.1.9002
Built: 2024-07-02 04:02:00 UTC
Source: https://github.com/poissonconsulting/mcmcr

Help Index


Coerce to nlist

Description

Coerce an R object to an nlist_object().

Usage

## S3 method for class 'mcmcr'
as_nlist(x, ...)

Arguments

x

An object.

...

Unused.

Value

An nlist object.

Methods (by class)

  • as_nlist(numeric): Coerce named numeric vector to nlist

  • as_nlist(list): Coerce list to nlist

  • as_nlist(data.frame): Coerce data.frame to nlist

  • as_nlist(mcmc): Coerce mcmc (with one iteration) to nlist

  • as_nlist(mcmc.list): Coerce mcmc.list (with one iteration) to nlist

See Also

Other coerce: as_nlists()

Examples

as_nlist(list(x = 1:4))
as_nlist(c(`a[2]` = 3, `a[1]` = 2))

Coerce to nlists

Description

Coerce an R object to an nlists_object().

Usage

## S3 method for class 'mcmcr'
as_nlists(x, ...)

Arguments

x

An object.

...

Unused.

Value

An nlists object.

Methods (by class)

  • as_nlists(list): Coerce list to nlists

  • as_nlists(mcmc): Coerce mcmc to nlists

  • as_nlists(mcmc.list): Coerce mcmc.list to nlists

  • as_nlists(nlist): Coerce nlist to nlists

See Also

Other coerce: as_nlist()

Examples

as_nlists(list(nlist(x = c(1, 5)), nlist(x = c(2, 3)), nlist(x = c(3, 2))))

Coerce to an mcarray object

Description

Coerces MCMC objects to an mcarray object.

Usage

as.mcarray(x, ...)

## S3 method for class 'list'
as.mcmcr(x, ...)

Arguments

x

object to coerce.

...

Unused.

Functions

  • as.mcmcr(list): Convert a list of uniquely named objects that can be coerced to ⁠[mcmcarray-object]s⁠ to an mcmcr object

See Also

Other coerce: as.mcmcarray(), as.mcmcr(), mcmcrs()

Examples

as.mcarray(mcmcr_example$beta)

Markov Chain Monte Carlo Objects

Description

The function mcmc is used to create a Markov Chain Monte Carlo object. The input data are taken to be a vector, or a matrix with one column per variable.

If the optional arguments start, end, and thin are omitted then the chain is assumed to start with iteration 1 and have thinning interval 1. If data represents a chain that starts at a later iteration, the first iteration in the chain should be given as the start argument. Likewise, if data represents a chain that has already been thinned, the thinning interval should be given as the thin argument.

An mcmc object may be summarized by the summary function and visualized with the plot function.

MCMC objects resemble time series (ts) objects and have methods for the generic functions time, start, end, frequency and window.

Usage

## S3 method for class 'mcarray'
as.mcmc(x, ...)

Arguments

x

An object that may be coerced to an mcmc object

...

Further arguments to be passed to specific methods

Note

The format of the mcmc class has changed between coda version 0.3 and 0.4. Older mcmc objects will now cause is.mcmc to fail with an appropriate warning message. Obsolete mcmc objects can be upgraded with the mcmcUpgrade function.

Author(s)

Martyn Plummer

See Also

mcmc.list, mcmcUpgrade, thin, window.mcmc, summary.mcmc, plot.mcmc.


Markov Chain Monte Carlo Objects

Description

The function mcmc is used to create a Markov Chain Monte Carlo object. The input data are taken to be a vector, or a matrix with one column per variable.

If the optional arguments start, end, and thin are omitted then the chain is assumed to start with iteration 1 and have thinning interval 1. If data represents a chain that starts at a later iteration, the first iteration in the chain should be given as the start argument. Likewise, if data represents a chain that has already been thinned, the thinning interval should be given as the thin argument.

An mcmc object may be summarized by the summary function and visualized with the plot function.

MCMC objects resemble time series (ts) objects and have methods for the generic functions time, start, end, frequency and window.

Usage

## S3 method for class 'mcmc'
as.mcmc(x, ...)

Arguments

x

An object that may be coerced to an mcmc object

...

Further arguments to be passed to specific methods

Note

The format of the mcmc class has changed between coda version 0.3 and 0.4. Older mcmc objects will now cause is.mcmc to fail with an appropriate warning message. Obsolete mcmc objects can be upgraded with the mcmcUpgrade function.

Author(s)

Martyn Plummer

See Also

mcmc.list, mcmcUpgrade, thin, window.mcmc, summary.mcmc, plot.mcmc.


Markov Chain Monte Carlo Objects

Description

The function mcmc is used to create a Markov Chain Monte Carlo object. The input data are taken to be a vector, or a matrix with one column per variable.

If the optional arguments start, end, and thin are omitted then the chain is assumed to start with iteration 1 and have thinning interval 1. If data represents a chain that starts at a later iteration, the first iteration in the chain should be given as the start argument. Likewise, if data represents a chain that has already been thinned, the thinning interval should be given as the thin argument.

An mcmc object may be summarized by the summary function and visualized with the plot function.

MCMC objects resemble time series (ts) objects and have methods for the generic functions time, start, end, frequency and window.

Usage

## S3 method for class 'mcmcarray'
as.mcmc(x, ...)

Arguments

x

An object that may be coerced to an mcmc object

...

Further arguments to be passed to specific methods

Note

The format of the mcmc class has changed between coda version 0.3 and 0.4. Older mcmc objects will now cause is.mcmc to fail with an appropriate warning message. Obsolete mcmc objects can be upgraded with the mcmcUpgrade function.

Author(s)

Martyn Plummer

See Also

mcmc.list, mcmcUpgrade, thin, window.mcmc, summary.mcmc, plot.mcmc.


Markov Chain Monte Carlo Objects

Description

The function mcmc is used to create a Markov Chain Monte Carlo object. The input data are taken to be a vector, or a matrix with one column per variable.

If the optional arguments start, end, and thin are omitted then the chain is assumed to start with iteration 1 and have thinning interval 1. If data represents a chain that starts at a later iteration, the first iteration in the chain should be given as the start argument. Likewise, if data represents a chain that has already been thinned, the thinning interval should be given as the thin argument.

An mcmc object may be summarized by the summary function and visualized with the plot function.

MCMC objects resemble time series (ts) objects and have methods for the generic functions time, start, end, frequency and window.

Usage

## S3 method for class 'mcmcr'
as.mcmc(x, ...)

Arguments

x

An object that may be coerced to an mcmc object

...

Further arguments to be passed to specific methods

Note

The format of the mcmc class has changed between coda version 0.3 and 0.4. Older mcmc objects will now cause is.mcmc to fail with an appropriate warning message. Obsolete mcmc objects can be upgraded with the mcmcUpgrade function.

Author(s)

Martyn Plummer

See Also

mcmc.list, mcmcUpgrade, thin, window.mcmc, summary.mcmc, plot.mcmc.


Coerce to an mcmcarray object

Description

Coerces MCMC objects to an mcmcarray-object().

Usage

as.mcmcarray(x, ...)

Arguments

x

object to coerce.

...

Unused.

See Also

Other coerce: as.mcarray(), as.mcmcr(), mcmcrs()

Examples

as.mcmcarray(as.mcarray(mcmcr_example$beta))

Convert to an mcmcr object

Description

Converts an MCMC object to an mcmcr-object().

Usage

as.mcmcr(x, ...)

## S3 method for class 'mcarray'
as.mcmcr(x, name = "par", ...)

## S3 method for class 'mcmcarray'
as.mcmcr(x, name = "par", ...)

## S3 method for class 'nlist'
as.mcmcr(x, ...)

## S3 method for class 'nlists'
as.mcmcr(x, ...)

## S3 method for class 'mcmc'
as.mcmcr(x, ...)

## S3 method for class 'mcmc.list'
as.mcmcr(x, ...)

## S3 method for class 'mcmcrs'
as.mcmcr(x, ...)

Arguments

x

An MCMC object.

...

Unused.

name

A string specifying the parameter name.

Value

An mcmcr object.

Methods (by class)

See Also

Other coerce: as.mcarray(), as.mcmcarray(), mcmcrs()

Examples

mcmc.list <- coda::as.mcmc.list(mcmcr::mcmcr_example)
as.mcmcr(mcmc.list)

Convert to an mcmcrs object

Description

Converts an MCMC object to an mcmcrs-object().

Usage

as.mcmcrs(x, ...)

## S3 method for class 'list'
as.mcmcrs(x, ...)

## S3 method for class 'mcmcr'
as.mcmcrs(x, name = "mcmcr1", ...)

Arguments

x

An MCMC object.

...

Unused.

name

A string specifying the element name.

Value

An mcmcrs object.

Methods (by class)

  • as.mcmcrs(list): Convert a list of ⁠[mcmcr-object]s⁠ to an mcmcrs object

  • as.mcmcrs(mcmcr): Convert an mcmcr-object() to an mcmcrs object

Examples

as.mcmcrs(mcmcr::mcmcr_example)

Bind by Chains.

Description

Binds two MCMC objects (with the same parameters and iterations) by chains.

Usage

## S3 method for class 'mcarray'
bind_chains(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_iterations(), collapse_chains(), estimates(), split_chains()


Bind by Chains.

Description

Binds two MCMC objects (with the same parameters and iterations) by chains.

Usage

## S3 method for class 'mcmc'
bind_chains(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_iterations(), collapse_chains(), estimates(), split_chains()


Bind by Chains.

Description

Binds two MCMC objects (with the same parameters and iterations) by chains.

Usage

## S3 method for class 'mcmc.list'
bind_chains(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_iterations(), collapse_chains(), estimates(), split_chains()


Bind by Chains.

Description

Binds two MCMC objects (with the same parameters and iterations) by chains.

Usage

## S3 method for class 'mcmcarray'
bind_chains(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_iterations(), collapse_chains(), estimates(), split_chains()


Bind by Chains.

Description

Binds two MCMC objects (with the same parameters and iterations) by chains.

Usage

## S3 method for class 'mcmcr'
bind_chains(x, x2, ...)

Arguments

x

An object.

x2

A second object.

...

Other arguments passed to methods.

Value

The combined object.

See Also

Other MCMC manipulations: bind_iterations(), collapse_chains(), estimates(), split_chains()


Combine two MCMC objects by dimensions

Description

Combines multiple MCMC objects (with the same parameters, chains and iterations) by parameter dimensions.

Usage

bind_dimensions(x, x2, along = NULL, ...)

Arguments

x

An MCMC object.

x2

a second MCMC object.

along

A count (or NULL) indicating the parameter dimension to bind along.

...

Unused.

See Also

universals::bind_chains()

Other bind: bind_dimensions_n(), bind_parameters()

Examples

bind_dimensions(mcmcr_example, mcmcr_example)

Combine multiple MCMC objects by parameter dimensions

Description

Combines multiple MCMC objects (with the same parameters, chains and iterations) by parameter dimensions.

Usage

bind_dimensions_n(...)

Arguments

...

one or more MCMC objects

See Also

universals::bind_chains()

Other bind: bind_dimensions(), bind_parameters()

Examples

bind_dimensions_n(mcmcr_example, mcmcr_example, mcmcr_example)

Combine two MCMC object by parameters

Description

Combines two MCMC objects (with the same chains and iterations) by their parameters.

Usage

bind_parameters(x, x2, ...)

Arguments

x

an MCMC object

x2

a second MCMC object.

...

Unused.

See Also

universals::bind_chains()

Other bind: bind_dimensions_n(), bind_dimensions()

Examples

bind_parameters(
  subset(mcmcr_example, pars = "sigma"),
  subset(mcmcr_example, pars = "beta")
)

[Soft-deprecated] Check mcmcarray

Description

[Soft-deprecated] Check mcmcarray

Usage

check_mcmcarray(x, x_name = substitute(x), error = TRUE)

Arguments

x

The object to check.

x_name

A string of the name of the object.

error

A flag indicating whether to throw an informative error or immediately generate an informative message if the check fails.

Value

An invisible copy of x (it if doesn't throw an error).

See Also

check_mcmcr()

Examples

check_mcmcarray(mcmcr::mcmcr_example$beta)

[Soft-deprecated] Check mcmcr

Description

[Soft-deprecated] Check mcmcr

Usage

check_mcmcr(x, sorted = FALSE, x_name = substitute(x), error = TRUE)

Arguments

x

The object to check.

sorted

A flag specifying whether the parameters must be sorted.

x_name

A string of the name of the object.

error

A flag indicating whether to throw an informative error or immediately generate an informative message if the check fails.

Value

An invisible copy of x (it if doesn't throw an error).

See Also

check_mcmcr()

Examples

check_mcmcr(mcmcr::mcmcr_example)

Check MCMC objects

Description

Checks class and structure of MCMC objects.

chk_mcmcarray checks if mcmcarray-object() object using

is.array(x) && is.numeric(x)

chk_mcmcr checks if an mcmcr-object().

chk_mcmcrs checks if an mcmcrs-object().

Usage

chk_mcmcarray(x, x_name = NULL)

chk_mcmcr(x, x_name = NULL)

chk_mcmcrs(x, x_name = NULL)

Arguments

x

The object to check.

x_name

A string of the name of object x or NULL.

Details

To just check class use chk::chk_s3_class().

Value

NULL, invisibly. Called for the side effect of throwing an error if the condition is not met.

Functions

  • chk_mcmcarray(): Check mcmcarray Object

  • chk_mcmcr(): Check mcmcr Object

  • chk_mcmcrs(): Check mcmcrs Object

See Also

vld_mcmcr()

Examples

# chk_mcmcarray
try(chk_mcmcarray(1))

# chk_mcmcr
chk_mcmcr(as.mcmcr(list(x = 1)))
try(chk_mcmcr(1))

# chk_mcmcrs
chk_mcmcrs(as.mcmcrs(as.mcmcr(list(x = 1))))
try(chk_mcmcrs(1))

Term coefficients

Description

Gets coefficients for all the terms in an MCMC object.

Usage

## S3 method for class 'mcmc'
coef(object, conf_level = 0.95, estimate = median, simplify = TRUE, ...)

Arguments

object

The MCMC object to get the coefficients for

conf_level

A number specifying the confidence level. By default 0.95.

estimate

The function to use to calculate the estimate.

simplify

A flag specifying whether to return just the estimate, lower, upper and svalue.

...

Unused.

Value

An data frame of the coefficients with the columns indicating the term, estimate, lower and upper credible intervals and svalue

Methods (by class)

  • coef(mcmc): Get coefficients for terms in mcmc object

See Also

stats::coef

Examples

coef(mcmcr_example)

Collapse Chains

Description

Collapses an MCMC object's chains into a single chain.

Usage

## S3 method for class 'mcmcr'
collapse_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

The modified object with one chain.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), estimates(), split_chains()


Combine samples by dimensions

Description

Combines MCMC object samples by dimensions along along using fun.

Usage

combine_dimensions(x, fun = mean, along = NULL, ...)

Arguments

x

An MCMC object

fun

The function to use when combining dimensions

along

A positive integer (or NULL) indicating the parameter dimension(s) to bind along.

...

Unused.

Value

The MCMC object with reduced dimensions.

See Also

Other combine: combine_samples_n(), combine_samples()

Examples

combine_dimensions(mcmcr_example$alpha)

Combine MCMC samples of two objects

Description

Combines samples of two MCMC objects (with the same parameters, chains and iterations) using a function.

Usage

combine_samples(x, x2, fun = mean, ...)

Arguments

x

An MCMC object.

x2

a second MCMC object.

fun

The function to use to combine the samples. The function must return a scalar.

...

Unused.

Value

The combined samples as an MCMC object with the same parameters, chains and iterations as the original objects.

See Also

Other combine: combine_dimensions(), combine_samples_n()

Examples

combine_samples(mcmcr_example, mcmcr_example, fun = sum)

Combine MCMC samples of multiple objects

Description

Combines samples of multiple MCMC objects (with the same parameters, chains and iterations) using a function.

Usage

combine_samples_n(x, ..., fun = mean)

Arguments

x

An MCMC object (or a list of mcmc objects).

...

Additional MCMC objects.

fun

A function.

See Also

Other combine: combine_dimensions(), combine_samples()

Examples

combine_samples_n(mcmcr_example, mcmcr_example, mcmcr_example, fun = sum)

Converged

Description

Tests whether an object has converged.

Usage

## Default S3 method:
converged(
  x,
  rhat = 1.1,
  esr = 0.33,
  by = "all",
  as_df = FALSE,
  na_rm = FALSE,
  ...
)

Arguments

x

An object.

rhat

The maximum rhat value.

esr

The minimum effective sampling rate.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Value

A logical scalar indicating whether the object has converged.

See Also

Other convergence: converged_pars(), converged_terms(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms(), rhat()

Examples

converged(mcmcr_example)

Converged

Description

Tests whether an object has converged.

Usage

## S3 method for class 'mcmcrs'
converged(
  x,
  rhat = 1.1,
  esr = 0.33,
  by = "all",
  as_df = FALSE,
  bound = FALSE,
  na_rm = FALSE,
  ...
)

Arguments

x

An object.

rhat

The maximum rhat value.

esr

The minimum effective sampling rate.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

bound

flag specifying whether to bind mcmcrs objects by their chains before calculating rhat.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Value

A logical scalar indicating whether the object has converged.

See Also

Other convergence: converged_pars(), converged_terms(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms(), rhat()

Examples

converged(mcmcrs(mcmcr_example, mcmcr_example))
converged(mcmcrs(mcmcr_example, mcmcr_example), bound = TRUE)

Effective Sampling Rate

Description

Calculates the effective sampling rate (esr).

Usage

## S3 method for class 'mcarray'
esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default

11+2k=1ρk(θ)\frac{1}{1 + 2 \sum_{k = 1}^\infty\rho_k(\theta)}

from Brooks et al. (2011) where the infinite sum is truncated at lag kk when ρk+1(θ)<0\rho_{k+1}(\theta) < 0.

Value

A number between 0 and 1 indicating the esr value.

References

Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), rhat_pars(), rhat_terms(), rhat()


Effective Sampling Rate

Description

Calculates the effective sampling rate (esr).

Usage

## S3 method for class 'mcmc'
esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default

11+2k=1ρk(θ)\frac{1}{1 + 2 \sum_{k = 1}^\infty\rho_k(\theta)}

from Brooks et al. (2011) where the infinite sum is truncated at lag kk when ρk+1(θ)<0\rho_{k+1}(\theta) < 0.

Value

A number between 0 and 1 indicating the esr value.

References

Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), rhat_pars(), rhat_terms(), rhat()


Effective Sampling Rate

Description

Calculates the effective sampling rate (esr).

Usage

## S3 method for class 'mcmc.list'
esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default

11+2k=1ρk(θ)\frac{1}{1 + 2 \sum_{k = 1}^\infty\rho_k(\theta)}

from Brooks et al. (2011) where the infinite sum is truncated at lag kk when ρk+1(θ)<0\rho_{k+1}(\theta) < 0.

Value

A number between 0 and 1 indicating the esr value.

References

Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), rhat_pars(), rhat_terms(), rhat()


Effective Sampling Rate

Description

Calculates the effective sampling rate (esr).

Usage

## S3 method for class 'mcmcarray'
esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default

11+2k=1ρk(θ)\frac{1}{1 + 2 \sum_{k = 1}^\infty\rho_k(\theta)}

from Brooks et al. (2011) where the infinite sum is truncated at lag kk when ρk+1(θ)<0\rho_{k+1}(\theta) < 0.

Value

A number between 0 and 1 indicating the esr value.

References

Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), rhat_pars(), rhat_terms(), rhat()


Effective Sampling Rate

Description

Calculates the effective sampling rate (esr).

Usage

## S3 method for class 'mcmcr'
esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default

11+2k=1ρk(θ)\frac{1}{1 + 2 \sum_{k = 1}^\infty\rho_k(\theta)}

from Brooks et al. (2011) where the infinite sum is truncated at lag kk when ρk+1(θ)<0\rho_{k+1}(\theta) < 0.

Value

A number between 0 and 1 indicating the esr value.

References

Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), rhat_pars(), rhat_terms(), rhat()

Examples

esr(mcmcr_example)

Effective Sampling Rate

Description

Calculates the effective sampling rate (esr).

Usage

## S3 method for class 'mcmcrs'
esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default

11+2k=1ρk(θ)\frac{1}{1 + 2 \sum_{k = 1}^\infty\rho_k(\theta)}

from Brooks et al. (2011) where the infinite sum is truncated at lag kk when ρk+1(θ)<0\rho_{k+1}(\theta) < 0.

Value

A number between 0 and 1 indicating the esr value.

References

Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), rhat_pars(), rhat_terms(), rhat()

Examples

esr(mcmcrs(mcmcr_example, mcmcr_example))

P-Value effective sample size

Description

Calculates the effective sample size based on esr().

Usage

ess(x, by = "all", as_df = FALSE)

Arguments

x

An MCMC object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

See Also

universals::esr

Examples

ess(mcmcr_example)

Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'mcarray'
estimates(x, fun = median, as_df = FALSE, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

as_df

A flag indicating whether to return the results as a data frame versus a named list.

...

Optional arguments to fun.

Value

A named list or data frame.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()


Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'mcmc'
estimates(x, fun = median, as_df = FALSE, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

as_df

A flag indicating whether to return the results as a data frame versus a named list.

...

Optional arguments to fun.

Value

A named list or data frame.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()


Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'mcmc.list'
estimates(x, fun = median, as_df = FALSE, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

as_df

A flag indicating whether to return the results as a data frame versus a named list.

...

Optional arguments to fun.

Value

A named list or data frame.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()


Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'mcmcarray'
estimates(x, fun = median, as_df = FALSE, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

as_df

A flag indicating whether to return the results as a data frame versus a named list.

...

Optional arguments to fun.

Value

A named list or data frame.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()


Estimates

Description

Calculates the estimates for an MCMC object.

Usage

## S3 method for class 'mcmcr'
estimates(x, fun = median, as_df = FALSE, ...)

Arguments

x

An object.

fun

A function that given a numeric vector returns a numeric scalar.

as_df

A flag indicating whether to return the results as a data frame versus a named list.

...

Optional arguments to fun.

Value

A named list or data frame.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), split_chains()

Examples

estimates(mcmcr_example)

Fill All Values

Description

Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'mcarray'
fill_all(x, value = 0, nas = TRUE, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

nas

A flag specifying whether to also fill missing values.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_all(logical): Fill All for logical Objects

  • fill_all(integer): Fill All for integer Objects

  • fill_all(numeric): Fill All for numeric Objects

  • fill_all(character): Fill All for character Objects

See Also

Other fill: fill_na()

Examples

# logical
fill_all(c(TRUE, NA, FALSE))
fill_all(c(TRUE, NA, FALSE, nas = FALSE))
fill_all(c(TRUE, NA, FALSE, value = NA))

# integer
fill_all(matrix(1:4, nrow = 2), value = -1)

# numeric
fill_all(c(1, 4, NA), value = TRUE)
fill_all(c(1, 4, NA), value = TRUE, nas = FALSE)

# character
fill_all(c("some", "words"), value = TRUE)

Fill All Values

Description

Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'mcmcarray'
fill_all(x, value = 0, nas = TRUE, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

nas

A flag specifying whether to also fill missing values.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_all(logical): Fill All for logical Objects

  • fill_all(integer): Fill All for integer Objects

  • fill_all(numeric): Fill All for numeric Objects

  • fill_all(character): Fill All for character Objects

See Also

Other fill: fill_na()

Examples

# logical
fill_all(c(TRUE, NA, FALSE))
fill_all(c(TRUE, NA, FALSE, nas = FALSE))
fill_all(c(TRUE, NA, FALSE, value = NA))

# integer
fill_all(matrix(1:4, nrow = 2), value = -1)

# numeric
fill_all(c(1, 4, NA), value = TRUE)
fill_all(c(1, 4, NA), value = TRUE, nas = FALSE)

# character
fill_all(c("some", "words"), value = TRUE)

Fill All Values

Description

Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'mcmcr'
fill_all(x, value = 0, nas = TRUE, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

nas

A flag specifying whether to also fill missing values.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_all(logical): Fill All for logical Objects

  • fill_all(integer): Fill All for integer Objects

  • fill_all(numeric): Fill All for numeric Objects

  • fill_all(character): Fill All for character Objects

See Also

Other fill: fill_na()

Examples

# logical
fill_all(c(TRUE, NA, FALSE))
fill_all(c(TRUE, NA, FALSE, nas = FALSE))
fill_all(c(TRUE, NA, FALSE, value = NA))

# integer
fill_all(matrix(1:4, nrow = 2), value = -1)

# numeric
fill_all(c(1, 4, NA), value = TRUE)
fill_all(c(1, 4, NA), value = TRUE, nas = FALSE)

# character
fill_all(c("some", "words"), value = TRUE)

Fill Missing Values

Description

Fills all of an object's missing values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'mcarray'
fill_na(x, value = 0, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_na(logical): Fill Missing Values for logical Objects

  • fill_na(integer): Fill Missing Values for integer Objects

  • fill_na(numeric): Fill Missing Values for numeric Objects

  • fill_na(character): Fill Missing Values for character Objects

See Also

Other fill: fill_all()

Examples

# logical
fill_na(c(TRUE, NA))

# integer
fill_na(c(1L, NA), 0)

# numeric
fill_na(c(1, NA), Inf)

# character
fill_na(c("text", NA))
fill_na(matrix(c("text", NA)), value = Inf)

Fill Missing Values

Description

Fills all of an object's missing values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'mcmcarray'
fill_na(x, value = 0, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_na(logical): Fill Missing Values for logical Objects

  • fill_na(integer): Fill Missing Values for integer Objects

  • fill_na(numeric): Fill Missing Values for numeric Objects

  • fill_na(character): Fill Missing Values for character Objects

See Also

Other fill: fill_all()

Examples

# logical
fill_na(c(TRUE, NA))

# integer
fill_na(c(1L, NA), 0)

# numeric
fill_na(c(1, NA), Inf)

# character
fill_na(c("text", NA))
fill_na(matrix(c("text", NA)), value = Inf)

Fill Missing Values

Description

Fills all of an object's missing values while preserving the object's dimensionality and class.

Usage

## S3 method for class 'mcmcr'
fill_na(x, value = 0, ...)

Arguments

x

An object.

value

A scalar of the value to replace values with.

...

Other arguments passed to methods.

Details

It should only be defined for objects with values of consistent class ie not standard data.frames.

Value

The modified object.

Methods (by class)

  • fill_na(logical): Fill Missing Values for logical Objects

  • fill_na(integer): Fill Missing Values for integer Objects

  • fill_na(numeric): Fill Missing Values for numeric Objects

  • fill_na(character): Fill Missing Values for character Objects

See Also

Other fill: fill_all()

Examples

# logical
fill_na(c(TRUE, NA))

# integer
fill_na(c(1L, NA), 0)

# numeric
fill_na(c(1, NA), Inf)

# character
fill_na(c("text", NA))
fill_na(matrix(c("text", NA)), value = Inf)

Is mcarray object

Description

Tests whether an object is an mcarray.

Usage

is.mcarray(x)

Arguments

x

The object to test.

Value

A flag indicating whether the test was positive.

See Also

Other is: is.mcmcarray(), is.mcmcrs(), is.mcmcr()

Examples

is.mcarray(mcmcr_example)

Is mcmcarray object

Description

Tests whether an object is an mcmcarray-object().

Usage

is.mcmcarray(x)

Arguments

x

The object to test.

Value

A flag indicating whether the test was positive.

See Also

Other is: is.mcarray(), is.mcmcrs(), is.mcmcr()

Examples

is.mcmcarray(mcmcr_example$beta)

Is mcmcr object

Description

Tests whether an object is an mcmcr-object().

Usage

is.mcmcr(x)

Arguments

x

The object to test.

Value

A flag indicating whether the test was positive.

See Also

Other is: is.mcarray(), is.mcmcarray(), is.mcmcrs()

Examples

is.mcmcr(mcmcr_example)

Is mcmcrs object

Description

Tests whether an object is an mcmcrs-object().

Usage

is.mcmcrs(x)

Arguments

x

The object to test.

Value

A flag indicating whether the test was positive.

See Also

Other is: is.mcarray(), is.mcmcarray(), is.mcmcr()

Examples

is.mcmcrs(mcmcrs(mcmcr_example))

MCMC object transposition

Description

Transpose an MCMC object by permuting its parameter dimensions.

Usage

mcmc_aperm(x, perm, ...)

Arguments

x

The MCMC object to transpose. Missing parameter dimensions are added on the end. If perm = NULL (the default) the parameter dimensions are reversed.

perm

A integer vector of the new order for the parameter dimensions.

...

Unused.

Value

The modified MCMC object

See Also

Other manipulate: mcmc_map()


MCMC map

Description

Adjust the sample values of an MCMC object using a function.

Usage

mcmc_map(.x, .f, .by = 1:npdims(.x), ...)

Arguments

.x

An MCMC object

.f

The function to use

.by

A positive integer vector of the dimensions to apply the function over.

...

Additional arguments passed to .f.

Value

The updated MCMC object.

See Also

Other manipulate: mcmc_aperm()

Examples

mcmc_map(mcmcr_example$beta, exp)

mcmcarray

Description

An mcmcarray object is an an array where the first dimension is the chains, the second dimension is the iterations and the subsequent dimensions represent the dimensionality of the parameter. The name mcmcarray reflects the fact that the MCMC dimensions, ie the chains and iterations, precede the parameter dimensions.

See Also

Other objects: mcmcr-object, mcmcrs-object

Examples

mcmcr_example$beta

An example mcmcr object

Description

An example mcmcr-object() derived from coda::line().

Usage

mcmcr_example

Format

An object of class mcmcr of length 3.

Examples

mcmcr_example

mcmcr

Description

An mcmcr object stores multiple uniquely named mcmcarray-object() objects with the same number of chains and iterations.

Details

mcmcr objects allow a set of dimensionality preserving parameters to be manipulated and queried as a whole.

See Also

Other objects: mcmcarray-object, mcmcrs-object

Examples

mcmcr_example

Create mcmcrs

Description

Creates an mcmcrs-object() from multiple link{mcmcr-object}s.

Usage

mcmcrs(...)

Arguments

...

Objects of class mcmcr.

Value

An object of class mcmcrs

See Also

Other coerce: as.mcarray(), as.mcmcarray(), as.mcmcr()

Examples

mcmcrs(mcmcr_example, mcmcr_example)

mcmcrs

Description

An mcmcrs object stores multiple mcmcr-object()s with the same parameters and the same number of chains and iterations.

Details

mcmcrs objects allow the results of multiple analyses using the same model to be manipulated and queried as a whole.

See Also

Other objects: mcmcarray-object, mcmcr-object

Examples

mcmcrs(mcmcr_example, mcmcr_example)

Number of Chains

Description

Gets the number of chains of an MCMC object.

Usage

## S3 method for class 'mcarray'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of chains.

See Also

Other MCMC dimensions: niters(), npars(), nsams(), nsims(), nterms()


Number of Chains

Description

Gets the number of chains of an MCMC object.

Usage

## S3 method for class 'mcmcarray'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of chains.

See Also

Other MCMC dimensions: niters(), npars(), nsams(), nsims(), nterms()


Number of Chains

Description

Gets the number of chains of an MCMC object.

Usage

## S3 method for class 'mcmcr'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of chains.

See Also

Other MCMC dimensions: niters(), npars(), nsams(), nsims(), nterms()


Number of Chains

Description

Gets the number of chains of an MCMC object.

Usage

## S3 method for class 'mcmcrs'
nchains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of chains.

See Also

Other MCMC dimensions: niters(), npars(), nsams(), nsims(), nterms()


Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'mcarray'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()


Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'mcmcarray'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()


Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'mcmcr'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()


Number of Iterations

Description

Gets the number of iterations (in a chain) of an MCMC object.

Usage

## S3 method for class 'mcmcrs'
niters(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

An integer scalar of the number of iterations.

See Also

Other MCMC dimensions: nchains(), npars(), nsams(), nsims(), nterms()


Number of Parameters

Description

Gets the number of parameters of an object.

The default methods returns the length of pars() if none are NA, otherwise it returns NA.

Usage

## S3 method for class 'mcarray'
npars(x, scalar = NULL, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

...

Other arguments passed to methods.

Value

An integer scalar of the number of parameters.

See Also

pars()

Other MCMC dimensions: nchains(), niters(), nsams(), nsims(), nterms()

Other parameters: pars(), set_pars()


Number of Parameters

Description

Gets the number of parameters of an object.

The default methods returns the length of pars() if none are NA, otherwise it returns NA.

Usage

## S3 method for class 'mcmcarray'
npars(x, scalar = NULL, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

...

Other arguments passed to methods.

Value

An integer scalar of the number of parameters.

See Also

pars()

Other MCMC dimensions: nchains(), niters(), nsams(), nsims(), nterms()

Other parameters: pars(), set_pars()


Number of Parameters

Description

Gets the number of parameters of an object.

The default methods returns the length of pars() if none are NA, otherwise it returns NA.

Usage

## S3 method for class 'mcmcr'
npars(x, scalar = NULL, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

...

Other arguments passed to methods.

Value

An integer scalar of the number of parameters.

See Also

pars()

Other MCMC dimensions: nchains(), niters(), nsams(), nsims(), nterms()

Other parameters: pars(), set_pars()


Number of Parameter Dimensions

Description

Gets the number of the dimensions of each parameter of an object.

The default methods returns the length of each element of pdims() as an integer vector.

Usage

## S3 method for class 'mcmcarray'
npdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named integer vector of the number of dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), pdims()


Number of Parameter Dimensions

Description

Gets the number of the dimensions of each parameter of an object.

The default methods returns the length of each element of pdims() as an integer vector.

Usage

## S3 method for class 'mcmcr'
npdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named integer vector of the number of dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), pdims()


Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'mcmcarray'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()


Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'mcmcr'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()


Number of Terms

Description

Gets the number of terms of an MCMC object.

Usage

## S3 method for class 'mcmcrs'
nterms(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A integer scalar of the number of terms.

See Also

Other MCMC dimensions: nchains(), niters(), npars(), nsams(), nsims()


Parameter descriptions

Description

Parameter descriptions

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A logical scalar specifying whether to provide the parameters for each term.

nas

A flag specifying whether to also fill missing values.

nthin

A positive integer of the thinning rate.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

fun

A function that given a numeric vector returns a numeric scalar.

bound

flag specifying whether to bind mcmcrs objects by their chains before calculating rhat.

rhat

The maximum rhat value.

esr

The minimum effective sampling rate.

na_rm

A flag specifying whether to ignore missing values.

parameters

A character vector (or NULL) of the parameters to subset by.

iterations

An integer vector (or NULL) of the iterations to subset by.

...

Unused.

x2

a second MCMC object.

x_name

A string of the name of the object.

error

A flag indicating whether to throw an informative error or immediately generate an informative message if the check fails.

sorted

A flag specifying whether the parameters must be sorted.

object

The MCMC object to get the coefficients for

conf_level

A number specifying the confidence level. By default 0.95.

estimate

The function to use to calculate the estimate.

simplify

A flag specifying whether to return just the estimate, lower, upper and svalue.

perm

A integer vector of the new order for the parameter dimensions.

pars

A character vector (or NULL) of the pars to zero.

name

A string specifying the parameter name.


Parameter Names

Description

Gets the parameter names.

Usage

## S3 method for class 'mcmcr'
pars(x, scalar = NULL, terms = FALSE, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A logical scalar specifying whether to provide the parameters for each term.

...

Other arguments passed to methods.

Value

A character vector of the names of the parameters.

See Also

Other parameters: npars(), set_pars()


Parameter Names

Description

Gets the parameter names.

Usage

## S3 method for class 'mcmcrs'
pars(x, scalar = NULL, terms = FALSE, ...)

Arguments

x

An object.

scalar

A logical scalar specifying whether to include all parameters (NULL), only scalars (TRUE) or all parameters except scalars (FALSE).

terms

A logical scalar specifying whether to provide the parameters for each term.

...

Other arguments passed to methods.

Value

A character vector of the names of the parameters.

See Also

Other parameters: npars(), set_pars()


Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'mcarray'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()


Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'mcmcarray'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()


Parameter Dimensions

Description

Gets the dimensions of each parameter of an object.

Usage

## S3 method for class 'mcmcr'
pdims(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

A named list of integer vectors of the dimensions of each parameter.

See Also

Other dimensions: dims(), ndims(), npdims()


R-hat

Description

Calculates an R-hat (potential scale reduction factor) value.

Usage

## S3 method for class 'mcarray'
rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default the uncorrected, unfolded, univariate, split R-hat value.

Value

A number >= 1 indicating the rhat value.

References

Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms()


R-hat

Description

Calculates an R-hat (potential scale reduction factor) value.

Usage

## S3 method for class 'mcmc'
rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default the uncorrected, unfolded, univariate, split R-hat value.

Value

A number >= 1 indicating the rhat value.

References

Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms()


R-hat

Description

Calculates an R-hat (potential scale reduction factor) value.

Usage

## S3 method for class 'mcmc.list'
rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default the uncorrected, unfolded, univariate, split R-hat value.

Value

A number >= 1 indicating the rhat value.

References

Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms()


R-hat

Description

Calculates an R-hat (potential scale reduction factor) value.

Usage

## S3 method for class 'mcmcarray'
rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default the uncorrected, unfolded, univariate, split R-hat value.

Value

A number >= 1 indicating the rhat value.

References

Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms()


R-hat

Description

Calculates an R-hat (potential scale reduction factor) value.

Usage

## S3 method for class 'mcmcr'
rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

...

Other arguments passed to methods.

Details

By default the uncorrected, unfolded, univariate, split R-hat value.

Value

A number >= 1 indicating the rhat value.

References

Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms()

Examples

rhat(mcmcr_example)
rhat(mcmcr_example, by = "parameter")
rhat(mcmcr_example, by = "term")
rhat(mcmcr_example, by = "term", as_df = TRUE)

R-hat

Description

Calculates an R-hat (potential scale reduction factor) value.

Usage

## S3 method for class 'mcmcrs'
rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, bound = FALSE, ...)

Arguments

x

An object.

by

A string indicating whether to determine by "term", "parameter" or "all".

as_df

A flag indicating whether to return the results as a data frame versus a named list.

na_rm

A flag specifying whether to ignore missing values.

bound

flag specifying whether to bind mcmcrs objects by their chains before calculating rhat.

...

Other arguments passed to methods.

Details

By default the uncorrected, unfolded, univariate, split R-hat value.

Value

A number >= 1 indicating the rhat value.

References

Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.

See Also

Other convergence: converged_pars(), converged_terms(), converged(), esr_pars(), esr_terms(), esr(), rhat_pars(), rhat_terms()

Examples

rhat(mcmcrs(mcmcr_example, mcmcr_example))
rhat(mcmcrs(mcmcr_example, mcmcr_example), bound = TRUE)

Set Parameters

Description

Sets an object's parameter names.

The assignment version ⁠pars<-()⁠ forwards to set_pars().

Usage

## S3 method for class 'mcmcr'
set_pars(x, value, ...)

Arguments

x

An object.

value

A character vector of the new parameter names.

...

Other arguments passed to methods.

Details

value must be a unique character vector of the same length as the object's parameters.

Value

The modified object.

See Also

Other parameters: npars(), pars()


Set Parameters

Description

Sets an object's parameter names.

The assignment version ⁠pars<-()⁠ forwards to set_pars().

Usage

## S3 method for class 'mcmcrs'
set_pars(x, value, ...)

Arguments

x

An object.

value

A character vector of the new parameter names.

...

Other arguments passed to methods.

Details

value must be a unique character vector of the same length as the object's parameters.

Value

The modified object.

See Also

Other parameters: npars(), pars()


Split Chains

Description

Splits each of an MCMC object's chains in half to double the number of chains and halve the number of iterations.

Usage

## S3 method for class 'mcmcarray'
split_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

The modified object.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), estimates()


Split Chains

Description

Splits each of an MCMC object's chains in half to double the number of chains and halve the number of iterations.

Usage

## S3 method for class 'mcmcr'
split_chains(x, ...)

Arguments

x

An object.

...

Other arguments passed to methods.

Value

The modified object.

See Also

Other MCMC manipulations: bind_chains(), bind_iterations(), collapse_chains(), estimates()


Subset an MCMC object

Description

Subsets an MCMC object by its chains, iterations and/or parameters.

Usage

## S3 method for class 'mcmcarray'
subset(x, chains = NULL, iters = NULL, iterations = NULL, ...)

## S3 method for class 'mcmcr'
subset(
  x,
  chains = NULL,
  iters = NULL,
  pars = NULL,
  iterations = NULL,
  parameters = NULL,
  ...
)

## S3 method for class 'mcmcrs'
subset(
  x,
  chains = NULL,
  iters = NULL,
  pars = NULL,
  iterations = NULL,
  parameters = NULL,
  ...
)

Arguments

x

The MCMC object to subset

chains

An integer vector of chains.

iters

An integer vector of iterations.

iterations

An integer vector (or NULL) of the iterations to subset by.

...

Unused.

pars

A character vector of parameter names.

parameters

A character vector (or NULL) of the parameters to subset by.

Methods (by class)

  • subset(mcmcarray): Subset an mcmcarray object

  • subset(mcmcr): Subset an mcmcr object

  • subset(mcmcrs): Subset an mcmcrs object

See Also

universals::split_chains()

Examples

subset(mcmcr_example,
  chains = 2L, iters = 1:100,
  pars = c("beta", "alpha")
)

Validate MCMC objects

Description

Validates class and structure of MCMC objects.

Usage

vld_mcmcarray(x)

vld_mcmcr(x)

vld_mcmcrs(x)

Arguments

x

The object to check.

Details

To just validate class use chk::vld_s3_class().

Value

A flag indicating whether the object was validated.

Functions

See Also

chk_mcmcr()

Examples

#' vld_mcmcarray
vld_mcmcarray(1)

# vld_mcmcr
vld_mcmcr(1)
vld_mcmcr(mcmcr::mcmcr_example)

# vld_mcmcrs
vld_mcmcrs(1)

Zero MCMC sample values

Description

Zeros an MCMC object's sample values.

Usage

zero(x, ...)

## S3 method for class 'mcarray'
zero(x, ...)

## S3 method for class 'mcmcarray'
zero(x, ...)

## S3 method for class 'mcmcr'
zero(x, pars = NULL, ...)

Arguments

x

The MCMC object.

...

Unused.

pars

A character vector (or NULL) of the pars to zero.

Details

It is used for removing the effect of a random effect where the expected value is 0.

Value

The MCMC

Methods (by class)

  • zero(mcarray): Zero an mcarray object

  • zero(mcmcarray): Zero an mcmcarray object

  • zero(mcmcr): Zero an mcmcr object

Examples

zero(mcmcr_example, pars = "beta")