Title: | S3 Generics for Bayesian Analyses |
---|---|
Description: | Provides S3 generic methods and some default implementations for Bayesian analyses that generate Markov Chain Monte Carlo (MCMC) samples. The purpose of 'universals' is to reduce package dependencies and conflicts. The 'nlist' package implements many of the methods for its 'nlist' class. |
Authors: | Joe Thorley [aut, cre] , Kirill Müller [ctb] , Poisson Consulting [cph, fnd] |
Maintainer: | Joe Thorley <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.5.9000 |
Built: | 2024-11-01 16:19:28 UTC |
Source: | https://github.com/poissonconsulting/universals |
Binds two MCMC objects (with the same parameters and iterations) by chains.
bind_chains(x, x2, ...)
bind_chains(x, x2, ...)
x |
An object. |
x2 |
A second object. |
... |
Other arguments passed to methods. |
The combined object.
Other MCMC manipulations:
bind_iterations()
,
collapse_chains()
,
estimates()
,
split_chains()
Combines two MCMC objects (with the same parameters and chains) by iterations.
bind_iterations(x, x2, ...)
bind_iterations(x, x2, ...)
x |
An object. |
x2 |
A second object. |
... |
Other arguments passed to methods. |
The combined object.
Other MCMC manipulations:
bind_chains()
,
collapse_chains()
,
estimates()
,
split_chains()
Collapses an MCMC object's chains into a single chain.
collapse_chains(x, ...) ## Default S3 method: collapse_chains(x, ...)
collapse_chains(x, ...) ## Default S3 method: collapse_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object with one chain.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
estimates()
,
split_chains()
Tests whether an object has converged.
converged(x, ...)
converged(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A logical scalar indicating whether the object has converged.
Other convergence:
converged_pars()
,
converged_terms()
,
esr_pars()
,
esr_terms()
,
esr()
,
rhat_pars()
,
rhat_terms()
,
rhat()
Tests whether each parameter of an object has converged.
converged_pars(x, ...)
converged_pars(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A uniquely named logical vector indicating whether each parameter has converged.
Other convergence:
converged_terms()
,
converged()
,
esr_pars()
,
esr_terms()
,
esr()
,
rhat_pars()
,
rhat_terms()
,
rhat()
Tests whether each term of an object has converged.
converged_terms(x, ...)
converged_terms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A list of uniquely named logical objects with whether each term has converged.
Other convergence:
converged_pars()
,
converged()
,
esr_pars()
,
esr_terms()
,
esr()
,
rhat_pars()
,
rhat_terms()
,
rhat()
Gets the dimensions of an object.
dims(x, ...) ## Default S3 method: dims(x, ...) ## S3 method for class 'factor' dims(x, ...)
dims(x, ...) ## Default S3 method: dims(x, ...) ## S3 method for class 'factor' dims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
Unlike base::dim()
, dims returns the length of an atomic vector.
An integer vector of the dimensions.
Other dimensions:
ndims()
,
npdims()
,
pdims()
dims(numeric(0)) dims(1:3) dims(factor("a")) dims(matrix(1:4, nrow = 2L)) dims(array(1:9, dim = c(3L,1L,3L))) dims(ToothGrowth) dims(Titanic)
dims(numeric(0)) dims(1:3) dims(factor("a")) dims(matrix(1:4, nrow = 2L)) dims(array(1:9, dim = c(3L,1L,3L))) dims(ToothGrowth) dims(Titanic)
Calculates the effective sampling rate (esr
).
esr(x, ...)
esr(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
By default
from Brooks et al. (2011) where the infinite sum is truncated at
lag when
.
A number between 0 and 1 indicating the esr value.
Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.
Other convergence:
converged_pars()
,
converged_terms()
,
converged()
,
esr_pars()
,
esr_terms()
,
rhat_pars()
,
rhat_terms()
,
rhat()
Calculates the effective sampling rate (esr
) for each parameter.
esr_pars(x, ...)
esr_pars(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
By default
from Brooks et al. (2011) where the infinite sum is truncated at
lag when
.
A uniquely named numeric vector of values between 0 and 1 indicating the esr value for each parameter.
Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.
Other convergence:
converged_pars()
,
converged_terms()
,
converged()
,
esr_terms()
,
esr()
,
rhat_pars()
,
rhat_terms()
,
rhat()
Calculates the effective sampling rate (esr
) for each term.
esr_terms(x, ...)
esr_terms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
By default
from Brooks et al. (2011) where the infinite sum is truncated at
lag when
.
A list of uniquely named numeric objects with values between 0 and 1 indicating the effectively sampling rate for each term.
Brooks, S., Gelman, A., Jones, G.L., and Meng, X.-L. (Editors). 2011. Handbook for Markov Chain Monte Carlo. Taylor & Francis, Boca Raton.
Other convergence:
converged_pars()
,
converged_terms()
,
converged()
,
esr_pars()
,
esr()
,
rhat_pars()
,
rhat_terms()
,
rhat()
Calculates the estimates for an MCMC object.
estimates(x, ...)
estimates(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A list of uniquely named numeric objects.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
Gets the number of chains of an MCMC object.
nchains(x, ...)
nchains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of chains.
Other MCMC dimensions:
niters()
,
npars()
,
nsams()
,
nsims()
,
nterms()
Gets the number of dimensions of an object as returned by dims()
.
The default methods returns the length of dims()
.
ndims(x, ...) ## Default S3 method: ndims(x, ...) ## S3 method for class 'matrix' ndims(x, ...) ## S3 method for class 'data.frame' ndims(x, ...)
ndims(x, ...) ## Default S3 method: ndims(x, ...) ## S3 method for class 'matrix' ndims(x, ...) ## S3 method for class 'data.frame' ndims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
For matrices ndims()
is always 2L.
For data frames ndims()
is always 2L.
A integer scalar of the number of dimensions.
Other dimensions:
dims()
,
npdims()
,
pdims()
ndims(character(0)) ndims(1:3) ndims(matrix(1)) ndims(data.frame()) ndims(array(1:9, dim = c(3,1,3)))
ndims(character(0)) ndims(1:3) ndims(matrix(1)) ndims(data.frame()) ndims(array(1:9, dim = c(3,1,3)))
Gets the number of iterations (in a chain) of an MCMC object.
niters(x, ...)
niters(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of iterations.
Other MCMC dimensions:
nchains()
,
npars()
,
nsams()
,
nsims()
,
nterms()
Gets the number of parameters of an object.
The default methods returns the length of pars()
if none are
NA
, otherwise it returns NA
.
npars(x, ...) ## Default S3 method: npars(x, ...)
npars(x, ...) ## Default S3 method: npars(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of parameters.
Other MCMC dimensions:
nchains()
,
niters()
,
nsams()
,
nsims()
,
nterms()
Other parameters:
pars()
,
set_pars()
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.
npdims(x, ...) ## Default S3 method: npdims(x, ...)
npdims(x, ...) ## Default S3 method: npdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named integer vector of the number of dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
pdims()
Gets the number of sample values (simulations * terms) of an MCMC object.
The default methods returns the product of nsims()
and nterms()
.
nsams(x, ...) ## Default S3 method: nsams(x, ...)
nsams(x, ...) ## Default S3 method: nsams(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of samples.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsims()
,
nterms()
Gets the number of simulations (iterations * chains) of an MCMC object.
The default methods returns the product of nchains()
and niters()
.
nsims(x, ...) ## Default S3 method: nsims(x, ...)
nsims(x, ...) ## Default S3 method: nsims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
An integer scalar of the number of simulations.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nterms()
Gets the parameter names.
pars(x, ...)
pars(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
Gets the dimensions of each parameter of an object.
pdims(x, ...)
pdims(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A named list of integer vectors of the dimensions of each parameter.
Other dimensions:
dims()
,
ndims()
,
npdims()
Calculates an R-hat (potential scale reduction factor) value.
rhat(x, ...)
rhat(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
By default the uncorrected, unfolded, univariate, split R-hat value.
A number >= 1 indicating the rhat value.
Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.
Other convergence:
converged_pars()
,
converged_terms()
,
converged()
,
esr_pars()
,
esr_terms()
,
esr()
,
rhat_pars()
,
rhat_terms()
Calculates an R-hat (potential scale reduction factor) value for each parameter.
rhat_pars(x, ...)
rhat_pars(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
By default the uncorrected, unfolded, univariate, split R-hat value.
An uniquely named numeric atomic with values >= 1 indicating the rhat value for each parameter.
Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.
Other convergence:
converged_pars()
,
converged_terms()
,
converged()
,
esr_pars()
,
esr_terms()
,
esr()
,
rhat_terms()
,
rhat()
Calculates an R-hat (potential scale reduction factor) value for each term.
rhat_terms(x, ...)
rhat_terms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
By default the uncorrected, unfolded, univariate, split R-hat value.
A list of uniquely named numeric objects with values >= 1 indicating the rhat value for each term.
Gelman, A., and Rubin, D.B. 1992. Inference from Iterative Simulation Using Multiple Sequences. Statistical Science 7(4): 457–472.
Other convergence:
converged_pars()
,
converged_terms()
,
converged()
,
esr_pars()
,
esr_terms()
,
esr()
,
rhat_pars()
,
rhat()
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
set_pars(x, value, ...) pars(x) <- value
set_pars(x, value, ...) pars(x) <- value
x |
An object. |
value |
A character vector of the new parameter names. |
... |
Other arguments passed to methods. |
value
must be a unique character vector of the same length as the
object's parameters.
The modified object.
Other parameters:
npars()
,
pars()
Splits each of an MCMC object's chains in half to double the number of chains and halve the number of iterations.
split_chains(x, ...)
split_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
estimates()