| MCMCresult {compareMCMCs} | R Documentation |
R6 class to hold MCMC samples, timing results, and metrics
Description
R6 class to hold MCMC samples, timing results, and metrics
R6 class to hold MCMC samples, timing results, and metrics
Public fields
MCMCOptional name for the MCMC method.
samplesMatrix of MCMC samples. Rows are for MCMC iterations. Columns are for parameters. Columns must be named.
timesA list of times including elements for
setup,burnin,postburnin(sampling for recorded samples), andsampling(normallyburnin+postburnin). Each list element should be a single numeric value.metricsA list of MCMC performance metrics such as effective sample size (ESS), efficiency, mean, median, and credible interval boundaries.
metrics' is organized as a list with three elements:byMCMC,byParameter, andother' (currently unused).byMCMCis for metrics with one number for an entire MCMC sample (as opposed to one number for each parameter).byMCMCis a data frame with one row and columns for MCMC name each metric. These would be metrics where there is a singlebyParameteris for metrics with one number for each parameter in each MCMC sample.byParameteris adata.framewith one row for each MCMC-x-parameter combination and columns for MCMC method, parameter name, and each metric. There will only be one MCMC method name (all entries in the MCMC column will be the same).The MCMC columns in
byMCMCandbyParameterare useful for combiningmetricsfrom a list ofMCMCresultobjects, such as done bycombineMetrics, and for retaining MCMC method labels if thesedata.framesare copied and used outside of anMCMCresultobject.otheris simply an arbitrary list. This allows arbitrarily structured metrics to be saved.Elements of
metricsare normally populated byaddMetricsorcompareMCMCs(which callsaddMetrics).sessionInfoResult of running
sessionInfo()prior to calling an MCMC engine, if requested.
Methods
Public methods
Method new()
Create a new MCMCresult object.
Usage
MCMCresult$new(...)
Arguments
...Arbitrary initialization. If a matrix is passed, it will be used to initialize
samplesand themetricselements. If a list with a matrix element namedsamplesis passed, this element will be used as if the matrix itself was passed. Any other named elements of a list that correspond to fields of anMCMCresultobject will be initialized from them.
Method setSamples()
Populate the samples and initialize the metrics
Usage
MCMCresult$setSamples(samples)
Arguments
samplesA
data.framewith MCMC output.
Returns
NULL
Method rename()
Change the MCMC method name from oldName to newName
Usage
MCMCresult$rename(newName, oldName)
Arguments
newNameNew name for MCMC method in
metricsoldNameOld name for MCMC method in
metrics
Details
This change the MCMC field and the corresponding columns
of metrics$byParameter and metrics$byMCMC.
If oldName is not the MCMC method name, this function does nothing.
Returns
NULL
Method initializeMetrics()
Initialize metrics if necessary
Usage
MCMCresult$initializeMetrics(silent = FALSE)
Arguments
silentlogicalindicating whether to emit warnings
Details
This function does nothing if metrics are already initialized.
It does not clear metrics. See clearMetrics for information on
how metrics are initialized.
Returns
logical indicating whether metrics is well-formed or not.
Method clearMetrics()
Clear (reset) byParameter and/or byMCMC metrics
Usage
MCMCresult$clearMetrics(byParameter = TRUE, byMCMC = TRUE)
Arguments
byParameterlogicalindicating whether to clearbyParametermetricsbyMCMClogicalindicating whether to clearbyMCMCmetrics
Details
byParameter metrics are initialized to a data.frame with columns for
MCMC (all the same entry, the MCMC field) and Parameter
(taken from column
names of the samples).
byMCMC metrics are initialized to a data.frame
with a column for MCMC.
Method addMetricResult()
Add one set of metric results
Usage
MCMCresult$addMetricResult(metricResult)
Arguments
metricResultA list with possible elements
byParameter,byMCMC, andother. These are typically returned from a metric function called viaaddMetric. Each is combined with previous metrics already in the corresponding elements ofmetrics.
Method clone()
The objects of this class are cloneable with this method.
Usage
MCMCresult$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.
See Also
renameMCMC to change the name of an MCMC
method throughout the structure of a list of MCMCresult
objects.