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-12-17 03:10:48 UTC |
Source: | https://github.com/poissonconsulting/mcmcr |
Coerce an R object to an nlist_object()
.
## S3 method for class 'mcmcr' as_nlist(x, ...)
## S3 method for class 'mcmcr' as_nlist(x, ...)
x |
An object. |
... |
Unused. |
An nlist object.
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
Other coerce:
as_nlists()
as_nlist(list(x = 1:4)) as_nlist(c(`a[2]` = 3, `a[1]` = 2))
as_nlist(list(x = 1:4)) as_nlist(c(`a[2]` = 3, `a[1]` = 2))
Coerce an R object to an nlists_object()
.
## S3 method for class 'mcmcr' as_nlists(x, ...)
## S3 method for class 'mcmcr' as_nlists(x, ...)
x |
An object. |
... |
Unused. |
An nlists object.
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
Other coerce:
as_nlist()
as_nlists(list(nlist(x = c(1, 5)), nlist(x = c(2, 3)), nlist(x = c(3, 2))))
as_nlists(list(nlist(x = c(1, 5)), nlist(x = c(2, 3)), nlist(x = c(3, 2))))
Coerces MCMC objects to an mcarray object.
as.mcarray(x, ...) ## S3 method for class 'list' as.mcmcr(x, ...)
as.mcarray(x, ...) ## S3 method for class 'list' as.mcmcr(x, ...)
x |
object to coerce. |
... |
Unused. |
as.mcmcr(list)
: Convert a list of uniquely named objects that can be coerced to [mcmcarray-object]s
to an mcmcr object
Other coerce:
as.mcmcarray()
,
as.mcmcr()
,
mcmcrs()
as.mcarray(mcmcr_example$beta)
as.mcarray(mcmcr_example$beta)
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
.
## S3 method for class 'mcarray' as.mcmc(x, ...)
## S3 method for class 'mcarray' as.mcmc(x, ...)
x |
An object that may be coerced to an mcmc object |
... |
Further arguments to be passed to specific methods |
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.
Martyn Plummer
mcmc.list
,
mcmcUpgrade
,
thin
,
window.mcmc
,
summary.mcmc
,
plot.mcmc
.
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
.
## S3 method for class 'mcmc' as.mcmc(x, ...)
## S3 method for class 'mcmc' as.mcmc(x, ...)
x |
An object that may be coerced to an mcmc object |
... |
Further arguments to be passed to specific methods |
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.
Martyn Plummer
mcmc.list
,
mcmcUpgrade
,
thin
,
window.mcmc
,
summary.mcmc
,
plot.mcmc
.
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
.
## S3 method for class 'mcmcarray' as.mcmc(x, ...)
## S3 method for class 'mcmcarray' as.mcmc(x, ...)
x |
An object that may be coerced to an mcmc object |
... |
Further arguments to be passed to specific methods |
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.
Martyn Plummer
mcmc.list
,
mcmcUpgrade
,
thin
,
window.mcmc
,
summary.mcmc
,
plot.mcmc
.
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
.
## S3 method for class 'mcmcr' as.mcmc(x, ...)
## S3 method for class 'mcmcr' as.mcmc(x, ...)
x |
An object that may be coerced to an mcmc object |
... |
Further arguments to be passed to specific methods |
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.
Martyn Plummer
mcmc.list
,
mcmcUpgrade
,
thin
,
window.mcmc
,
summary.mcmc
,
plot.mcmc
.
Coerces MCMC objects to an mcmcarray-object()
.
as.mcmcarray(x, ...)
as.mcmcarray(x, ...)
x |
object to coerce. |
... |
Unused. |
Other coerce:
as.mcarray()
,
as.mcmcr()
,
mcmcrs()
as.mcmcarray(as.mcarray(mcmcr_example$beta))
as.mcmcarray(as.mcarray(mcmcr_example$beta))
Converts an MCMC object to an mcmcr-object()
.
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, ...)
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, ...)
x |
An MCMC object. |
... |
Unused. |
name |
A string specifying the parameter name. |
An mcmcr object.
as.mcmcr(mcarray)
: Convert an mcarray object to an mcmcr object
as.mcmcr(mcmcarray)
: Convert an mcmcarray-object()
to an mcmcr object
as.mcmcr(nlist)
: Convert an nlist::nlist-object()
to an mcmcr object
as.mcmcr(nlists)
: Convert an nlist::nlists-object()
to an mcmcr object
as.mcmcr(mcmc)
: Convert an coda::mcmc()
object to an mcmcr object
as.mcmcr(mcmc.list)
: Convert an coda::mcmc.list()
object to an mcmcr object
as.mcmcr(mcmcrs)
: Convert tan mcmcrs-object()
to an mcmcr object
Other coerce:
as.mcarray()
,
as.mcmcarray()
,
mcmcrs()
mcmc.list <- coda::as.mcmc.list(mcmcr::mcmcr_example) as.mcmcr(mcmc.list)
mcmc.list <- coda::as.mcmc.list(mcmcr::mcmcr_example) as.mcmcr(mcmc.list)
Converts an MCMC object to an mcmcrs-object()
.
as.mcmcrs(x, ...) ## S3 method for class 'list' as.mcmcrs(x, ...) ## S3 method for class 'mcmcr' as.mcmcrs(x, name = "mcmcr1", ...)
as.mcmcrs(x, ...) ## S3 method for class 'list' as.mcmcrs(x, ...) ## S3 method for class 'mcmcr' as.mcmcrs(x, name = "mcmcr1", ...)
x |
An MCMC object. |
... |
Unused. |
name |
A string specifying the element name. |
An mcmcrs object.
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
as.mcmcrs(mcmcr::mcmcr_example)
as.mcmcrs(mcmcr::mcmcr_example)
Binds two MCMC objects (with the same parameters and iterations) by chains.
## S3 method for class 'mcarray' bind_chains(x, x2, ...)
## S3 method for class 'mcarray' 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()
Binds two MCMC objects (with the same parameters and iterations) by chains.
## S3 method for class 'mcmc' bind_chains(x, x2, ...)
## S3 method for class 'mcmc' 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()
Binds two MCMC objects (with the same parameters and iterations) by chains.
## S3 method for class 'mcmc.list' bind_chains(x, x2, ...)
## S3 method for class 'mcmc.list' 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()
Binds two MCMC objects (with the same parameters and iterations) by chains.
## S3 method for class 'mcmcarray' bind_chains(x, x2, ...)
## S3 method for class 'mcmcarray' 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()
Binds two MCMC objects (with the same parameters and iterations) by chains.
## S3 method for class 'mcmcr' bind_chains(x, x2, ...)
## S3 method for class 'mcmcr' 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 multiple MCMC objects (with the same parameters, chains and iterations) by parameter dimensions.
bind_dimensions(x, x2, along = NULL, ...)
bind_dimensions(x, x2, along = NULL, ...)
x |
An MCMC object. |
x2 |
a second MCMC object. |
along |
A count (or NULL) indicating the parameter dimension to bind along. |
... |
Unused. |
Other bind:
bind_dimensions_n()
,
bind_parameters()
bind_dimensions(mcmcr_example, mcmcr_example)
bind_dimensions(mcmcr_example, mcmcr_example)
Combines multiple MCMC objects (with the same parameters, chains and iterations) by parameter dimensions.
bind_dimensions_n(...)
bind_dimensions_n(...)
... |
one or more MCMC objects |
Other bind:
bind_dimensions()
,
bind_parameters()
bind_dimensions_n(mcmcr_example, mcmcr_example, mcmcr_example)
bind_dimensions_n(mcmcr_example, mcmcr_example, mcmcr_example)
Combines two MCMC objects (with the same chains and iterations) by their parameters.
bind_parameters(x, x2, ...)
bind_parameters(x, x2, ...)
x |
an MCMC object |
x2 |
a second MCMC object. |
... |
Unused. |
Other bind:
bind_dimensions_n()
,
bind_dimensions()
bind_parameters( subset(mcmcr_example, pars = "sigma"), subset(mcmcr_example, pars = "beta") )
bind_parameters( subset(mcmcr_example, pars = "sigma"), subset(mcmcr_example, pars = "beta") )
check_mcmcarray(x, x_name = substitute(x), error = TRUE)
check_mcmcarray(x, x_name = substitute(x), error = TRUE)
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. |
An invisible copy of x (it if doesn't throw an error).
check_mcmcarray(mcmcr::mcmcr_example$beta)
check_mcmcarray(mcmcr::mcmcr_example$beta)
check_mcmcr(x, sorted = FALSE, x_name = substitute(x), error = TRUE)
check_mcmcr(x, sorted = FALSE, x_name = substitute(x), error = TRUE)
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. |
An invisible copy of x (it if doesn't throw an error).
check_mcmcr(mcmcr::mcmcr_example)
check_mcmcr(mcmcr::mcmcr_example)
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()
.
chk_mcmcarray(x, x_name = NULL) chk_mcmcr(x, x_name = NULL) chk_mcmcrs(x, x_name = NULL)
chk_mcmcarray(x, x_name = NULL) chk_mcmcr(x, x_name = NULL) chk_mcmcrs(x, x_name = NULL)
x |
The object to check. |
x_name |
A string of the name of object x or NULL. |
To just check class use chk::chk_s3_class()
.
NULL
, invisibly. Called for the side effect of throwing an error
if the condition is not met.
chk_mcmcarray()
: Check mcmcarray Object
chk_mcmcr()
: Check mcmcr Object
chk_mcmcrs()
: Check mcmcrs Object
# 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))
# 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))
Gets coefficients for all the terms in an MCMC object.
## S3 method for class 'mcmc' coef(object, conf_level = 0.95, estimate = median, simplify = TRUE, ...)
## S3 method for class 'mcmc' coef(object, conf_level = 0.95, estimate = median, simplify = TRUE, ...)
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. |
An data frame of the coefficients with the columns indicating the
term
, estimate
,
lower
and upper
credible intervals and svalue
coef(mcmc)
: Get coefficients for terms in mcmc object
coef(mcmcr_example)
coef(mcmcr_example)
Collapses an MCMC object's chains into a single chain.
## S3 method for class 'mcmcr' collapse_chains(x, ...)
## S3 method for class 'mcmcr' 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()
Combines MCMC object samples by dimensions along along
using fun
.
combine_dimensions(x, fun = mean, along = NULL, ...)
combine_dimensions(x, fun = mean, along = NULL, ...)
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. |
The MCMC object with reduced dimensions.
Other combine:
combine_samples_n()
,
combine_samples()
combine_dimensions(mcmcr_example$alpha)
combine_dimensions(mcmcr_example$alpha)
Combines samples of two MCMC objects (with the same parameters, chains and iterations) using a function.
combine_samples(x, x2, fun = mean, ...)
combine_samples(x, x2, fun = mean, ...)
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. |
The combined samples as an MCMC object with the same parameters, chains and iterations as the original objects.
Other combine:
combine_dimensions()
,
combine_samples_n()
combine_samples(mcmcr_example, mcmcr_example, fun = sum)
combine_samples(mcmcr_example, mcmcr_example, fun = sum)
Combines samples of multiple MCMC objects (with the same parameters, chains and iterations) using a function.
combine_samples_n(x, ..., fun = mean)
combine_samples_n(x, ..., fun = mean)
x |
An MCMC object (or a list of mcmc objects). |
... |
Additional MCMC objects. |
fun |
A function. |
Other combine:
combine_dimensions()
,
combine_samples()
combine_samples_n(mcmcr_example, mcmcr_example, mcmcr_example, fun = sum)
combine_samples_n(mcmcr_example, mcmcr_example, mcmcr_example, fun = sum)
Tests whether an object has converged.
## Default S3 method: converged( x, rhat = 1.1, esr = 0.33, by = "all", as_df = FALSE, na_rm = FALSE, ... )
## Default S3 method: converged( x, rhat = 1.1, esr = 0.33, by = "all", as_df = FALSE, na_rm = FALSE, ... )
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. |
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()
converged(mcmcr_example)
converged(mcmcr_example)
Tests whether an object has converged.
## S3 method for class 'mcmcrs' converged( x, rhat = 1.1, esr = 0.33, by = "all", as_df = FALSE, bound = FALSE, na_rm = FALSE, ... )
## S3 method for class 'mcmcrs' converged( x, rhat = 1.1, esr = 0.33, by = "all", as_df = FALSE, bound = FALSE, na_rm = FALSE, ... )
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. |
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()
converged(mcmcrs(mcmcr_example, mcmcr_example)) converged(mcmcrs(mcmcr_example, mcmcr_example), bound = TRUE)
converged(mcmcrs(mcmcr_example, mcmcr_example)) converged(mcmcrs(mcmcr_example, mcmcr_example), bound = TRUE)
Calculates the effective sampling rate (esr
).
## S3 method for class 'mcarray' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcarray' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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
).
## S3 method for class 'mcmc' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmc' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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
).
## S3 method for class 'mcmc.list' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmc.list' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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
).
## S3 method for class 'mcmcarray' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmcarray' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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
).
## S3 method for class 'mcmcr' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmcr' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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()
esr(mcmcr_example)
esr(mcmcr_example)
Calculates the effective sampling rate (esr
).
## S3 method for class 'mcmcrs' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmcrs' esr(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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()
esr(mcmcrs(mcmcr_example, mcmcr_example))
esr(mcmcrs(mcmcr_example, mcmcr_example))
Calculates the effective sample size based on esr()
.
ess(x, by = "all", as_df = FALSE)
ess(x, by = "all", as_df = FALSE)
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. |
ess(mcmcr_example)
ess(mcmcr_example)
Calculates the estimates for an MCMC object.
## S3 method for class 'mcarray' estimates(x, fun = median, as_df = FALSE, ...)
## S3 method for class 'mcarray' estimates(x, fun = median, as_df = FALSE, ...)
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. |
A named list or data frame.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
Calculates the estimates for an MCMC object.
## S3 method for class 'mcmc' estimates(x, fun = median, as_df = FALSE, ...)
## S3 method for class 'mcmc' estimates(x, fun = median, as_df = FALSE, ...)
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. |
A named list or data frame.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
Calculates the estimates for an MCMC object.
## S3 method for class 'mcmc.list' estimates(x, fun = median, as_df = FALSE, ...)
## S3 method for class 'mcmc.list' estimates(x, fun = median, as_df = FALSE, ...)
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. |
A named list or data frame.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
Calculates the estimates for an MCMC object.
## S3 method for class 'mcmcarray' estimates(x, fun = median, as_df = FALSE, ...)
## S3 method for class 'mcmcarray' estimates(x, fun = median, as_df = FALSE, ...)
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. |
A named list or data frame.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
Calculates the estimates for an MCMC object.
## S3 method for class 'mcmcr' estimates(x, fun = median, as_df = FALSE, ...)
## S3 method for class 'mcmcr' estimates(x, fun = median, as_df = FALSE, ...)
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. |
A named list or data frame.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
split_chains()
estimates(mcmcr_example)
estimates(mcmcr_example)
Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.
## S3 method for class 'mcarray' fill_all(x, value = 0, nas = TRUE, ...)
## S3 method for class 'mcarray' fill_all(x, value = 0, nas = TRUE, ...)
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. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_na()
# 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)
# 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)
Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.
## S3 method for class 'mcmcarray' fill_all(x, value = 0, nas = TRUE, ...)
## S3 method for class 'mcmcarray' fill_all(x, value = 0, nas = TRUE, ...)
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. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_na()
# 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)
# 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)
Fills all of an object's (missing and non-missing) values while preserving the object's dimensionality and class.
## S3 method for class 'mcmcr' fill_all(x, value = 0, nas = TRUE, ...)
## S3 method for class 'mcmcr' fill_all(x, value = 0, nas = TRUE, ...)
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. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_na()
# 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)
# 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)
Fills all of an object's missing values while preserving the object's dimensionality and class.
## S3 method for class 'mcarray' fill_na(x, value = 0, ...)
## S3 method for class 'mcarray' fill_na(x, value = 0, ...)
x |
An object. |
value |
A scalar of the value to replace values with. |
... |
Other arguments passed to methods. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_all()
# 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)
# 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)
Fills all of an object's missing values while preserving the object's dimensionality and class.
## S3 method for class 'mcmcarray' fill_na(x, value = 0, ...)
## S3 method for class 'mcmcarray' fill_na(x, value = 0, ...)
x |
An object. |
value |
A scalar of the value to replace values with. |
... |
Other arguments passed to methods. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_all()
# 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)
# 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)
Fills all of an object's missing values while preserving the object's dimensionality and class.
## S3 method for class 'mcmcr' fill_na(x, value = 0, ...)
## S3 method for class 'mcmcr' fill_na(x, value = 0, ...)
x |
An object. |
value |
A scalar of the value to replace values with. |
... |
Other arguments passed to methods. |
It should only be defined for objects with values of consistent class ie not standard data.frames.
The modified object.
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
Other fill:
fill_all()
# 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)
# 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)
Tests whether an object is an mcarray.
is.mcarray(x)
is.mcarray(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Other is:
is.mcmcarray()
,
is.mcmcrs()
,
is.mcmcr()
is.mcarray(mcmcr_example)
is.mcarray(mcmcr_example)
Tests whether an object is an mcmcarray-object()
.
is.mcmcarray(x)
is.mcmcarray(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Other is:
is.mcarray()
,
is.mcmcrs()
,
is.mcmcr()
is.mcmcarray(mcmcr_example$beta)
is.mcmcarray(mcmcr_example$beta)
Tests whether an object is an mcmcr-object()
.
is.mcmcr(x)
is.mcmcr(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Other is:
is.mcarray()
,
is.mcmcarray()
,
is.mcmcrs()
is.mcmcr(mcmcr_example)
is.mcmcr(mcmcr_example)
Tests whether an object is an mcmcrs-object()
.
is.mcmcrs(x)
is.mcmcrs(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Other is:
is.mcarray()
,
is.mcmcarray()
,
is.mcmcr()
is.mcmcrs(mcmcrs(mcmcr_example))
is.mcmcrs(mcmcrs(mcmcr_example))
Transpose an MCMC object by permuting its parameter dimensions.
mcmc_aperm(x, perm, ...)
mcmc_aperm(x, perm, ...)
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. |
The modified MCMC object
Other manipulate:
mcmc_map()
Adjust the sample values of an MCMC object using a function.
mcmc_map(.x, .f, .by = 1:npdims(.x), ...)
mcmc_map(.x, .f, .by = 1:npdims(.x), ...)
.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. |
The updated MCMC object.
Other manipulate:
mcmc_aperm()
mcmc_map(mcmcr_example$beta, exp)
mcmc_map(mcmcr_example$beta, exp)
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.
Other objects:
mcmcr-object
,
mcmcrs-object
mcmcr_example$beta
mcmcr_example$beta
An example mcmcr-object()
derived from coda::line()
.
mcmcr_example
mcmcr_example
An object of class mcmcr
of length 3.
mcmcr_example
mcmcr_example
An mcmcr
object stores multiple uniquely named mcmcarray-object()
objects with the same number of chains and iterations.
mcmcr
objects allow a set of dimensionality preserving parameters
to be manipulated and queried as a whole.
Other objects:
mcmcarray-object
,
mcmcrs-object
mcmcr_example
mcmcr_example
Creates an mcmcrs-object()
from multiple link{mcmcr-object}
s.
mcmcrs(...)
mcmcrs(...)
... |
Objects of class mcmcr. |
An object of class mcmcrs
Other coerce:
as.mcarray()
,
as.mcmcarray()
,
as.mcmcr()
mcmcrs(mcmcr_example, mcmcr_example)
mcmcrs(mcmcr_example, mcmcr_example)
An mcmcrs
object stores multiple mcmcr-object()
s
with the same parameters and the same number of chains and iterations.
mcmcrs
objects allow the results of multiple analyses
using the same model to be manipulated and queried as a whole.
Other objects:
mcmcarray-object
,
mcmcr-object
mcmcrs(mcmcr_example, mcmcr_example)
mcmcrs(mcmcr_example, mcmcr_example)
Gets the number of chains of an MCMC object.
## S3 method for class 'mcarray' nchains(x, ...)
## S3 method for class 'mcarray' 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 chains of an MCMC object.
## S3 method for class 'mcmcarray' nchains(x, ...)
## S3 method for class 'mcmcarray' 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 chains of an MCMC object.
## S3 method for class 'mcmcr' nchains(x, ...)
## S3 method for class 'mcmcr' 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 chains of an MCMC object.
## S3 method for class 'mcmcrs' nchains(x, ...)
## S3 method for class 'mcmcrs' 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 iterations (in a chain) of an MCMC object.
## S3 method for class 'mcarray' niters(x, ...)
## S3 method for class 'mcarray' 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 iterations (in a chain) of an MCMC object.
## S3 method for class 'mcmcarray' niters(x, ...)
## S3 method for class 'mcmcarray' 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 iterations (in a chain) of an MCMC object.
## S3 method for class 'mcmcr' niters(x, ...)
## S3 method for class 'mcmcr' 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 iterations (in a chain) of an MCMC object.
## S3 method for class 'mcmcrs' niters(x, ...)
## S3 method for class 'mcmcrs' 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
.
## S3 method for class 'mcarray' npars(x, scalar = NULL, ...)
## S3 method for class 'mcarray' npars(x, scalar = NULL, ...)
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. |
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 parameters of an object.
The default methods returns the length of pars()
if none are
NA
, otherwise it returns NA
.
## S3 method for class 'mcmcarray' npars(x, scalar = NULL, ...)
## S3 method for class 'mcmcarray' npars(x, scalar = NULL, ...)
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. |
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 parameters of an object.
The default methods returns the length of pars()
if none are
NA
, otherwise it returns NA
.
## S3 method for class 'mcmcr' npars(x, scalar = NULL, ...)
## S3 method for class 'mcmcr' npars(x, scalar = NULL, ...)
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. |
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.
## S3 method for class 'mcmcarray' npdims(x, ...)
## S3 method for class 'mcmcarray' 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 the dimensions of each parameter of an object.
The default methods returns the length of each element of pdims()
as an integer vector.
## S3 method for class 'mcmcr' npdims(x, ...)
## S3 method for class 'mcmcr' 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 terms of an MCMC object.
## S3 method for class 'mcmcarray' nterms(x, ...)
## S3 method for class 'mcmcarray' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
Gets the number of terms of an MCMC object.
## S3 method for class 'mcmcr' nterms(x, ...)
## S3 method for class 'mcmcr' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
Gets the number of terms of an MCMC object.
## S3 method for class 'mcmcrs' nterms(x, ...)
## S3 method for class 'mcmcrs' nterms(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
A integer scalar of the number of terms.
Other MCMC dimensions:
nchains()
,
niters()
,
npars()
,
nsams()
,
nsims()
Parameter descriptions
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. |
Gets the parameter names.
## S3 method for class 'mcmcr' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'mcmcr' pars(x, scalar = NULL, terms = FALSE, ...)
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. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
Gets the parameter names.
## S3 method for class 'mcmcrs' pars(x, scalar = NULL, terms = FALSE, ...)
## S3 method for class 'mcmcrs' pars(x, scalar = NULL, terms = FALSE, ...)
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. |
A character vector of the names of the parameters.
Other parameters:
npars()
,
set_pars()
Gets the dimensions of each parameter of an object.
## S3 method for class 'mcarray' pdims(x, ...)
## S3 method for class 'mcarray' 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()
Gets the dimensions of each parameter of an object.
## S3 method for class 'mcmcarray' pdims(x, ...)
## S3 method for class 'mcmcarray' 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()
Gets the dimensions of each parameter of an object.
## S3 method for class 'mcmcr' pdims(x, ...)
## S3 method for class 'mcmcr' 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.
## S3 method for class 'mcarray' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcarray' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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.
## S3 method for class 'mcmc' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmc' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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.
## S3 method for class 'mcmc.list' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmc.list' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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.
## S3 method for class 'mcmcarray' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmcarray' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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.
## S3 method for class 'mcmcr' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
## S3 method for class 'mcmcr' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, ...)
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. |
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()
rhat(mcmcr_example) rhat(mcmcr_example, by = "parameter") rhat(mcmcr_example, by = "term") rhat(mcmcr_example, by = "term", as_df = TRUE)
rhat(mcmcr_example) rhat(mcmcr_example, by = "parameter") rhat(mcmcr_example, by = "term") rhat(mcmcr_example, by = "term", as_df = TRUE)
Calculates an R-hat (potential scale reduction factor) value.
## S3 method for class 'mcmcrs' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, bound = FALSE, ...)
## S3 method for class 'mcmcrs' rhat(x, by = "all", as_df = FALSE, na_rm = FALSE, bound = FALSE, ...)
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. |
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()
rhat(mcmcrs(mcmcr_example, mcmcr_example)) rhat(mcmcrs(mcmcr_example, mcmcr_example), bound = TRUE)
rhat(mcmcrs(mcmcr_example, mcmcr_example)) rhat(mcmcrs(mcmcr_example, mcmcr_example), bound = TRUE)
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'mcmcr' set_pars(x, value, ...)
## S3 method for class 'mcmcr' set_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()
Sets an object's parameter names.
The assignment version pars<-()
forwards to set_pars()
.
## S3 method for class 'mcmcrs' set_pars(x, value, ...)
## S3 method for class 'mcmcrs' set_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.
## S3 method for class 'mcmcarray' split_chains(x, ...)
## S3 method for class 'mcmcarray' split_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
estimates()
Splits each of an MCMC object's chains in half to double the number of chains and halve the number of iterations.
## S3 method for class 'mcmcr' split_chains(x, ...)
## S3 method for class 'mcmcr' split_chains(x, ...)
x |
An object. |
... |
Other arguments passed to methods. |
The modified object.
Other MCMC manipulations:
bind_chains()
,
bind_iterations()
,
collapse_chains()
,
estimates()
Subsets an MCMC object by its chains, iterations and/or parameters.
## 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, ... )
## 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, ... )
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. |
subset(mcmcarray)
: Subset an mcmcarray object
subset(mcmcr)
: Subset an mcmcr object
subset(mcmcrs)
: Subset an mcmcrs object
subset(mcmcr_example, chains = 2L, iters = 1:100, pars = c("beta", "alpha") )
subset(mcmcr_example, chains = 2L, iters = 1:100, pars = c("beta", "alpha") )
Validates class and structure of MCMC objects.
vld_mcmcarray(x) vld_mcmcr(x) vld_mcmcrs(x)
vld_mcmcarray(x) vld_mcmcr(x) vld_mcmcrs(x)
x |
The object to check. |
To just validate class use chk::vld_s3_class()
.
A flag indicating whether the object was validated.
vld_mcmcarray()
: Validate mcmcarray-object()
vld_mcmcr()
: Validate mcmcr-object()
vld_mcmcrs()
: Validate mcmcrs-object()
#' vld_mcmcarray vld_mcmcarray(1) # vld_mcmcr vld_mcmcr(1) vld_mcmcr(mcmcr::mcmcr_example) # vld_mcmcrs vld_mcmcrs(1)
#' vld_mcmcarray vld_mcmcarray(1) # vld_mcmcr vld_mcmcr(1) vld_mcmcr(mcmcr::mcmcr_example) # vld_mcmcrs vld_mcmcrs(1)
Zeros an MCMC object's sample values.
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, ...)
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, ...)
x |
The MCMC object. |
... |
Unused. |
pars |
A character vector (or NULL) of the pars to zero. |
It is used for removing the effect of a random effect where the expected value is 0.
The MCMC
zero(mcarray)
: Zero an mcarray object
zero(mcmcarray)
: Zero an mcmcarray object
zero(mcmcr)
: Zero an mcmcr object
zero(mcmcr_example, pars = "beta")
zero(mcmcr_example, pars = "beta")