| Title: | Facilitates Bayesian Analysis using STAN with CmdStanR |
|---|---|
| Description: | Facilitates Bayesian Analysis using STAN with CmdStanR. This builds on smbr, which uses rstan. |
| Authors: | Seb Dalgarno [aut, cre] (ORCID: <https://orcid.org/0000-0002-3658-4517>) |
| Maintainer: | Seb Dalgarno <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.0.9001 |
| Built: | 2026-10-13 19:38:59 UTC |
| Source: | https://github.com/poissonconsulting/smbr2 |
Generic function for diagnosing analysis objects.
See documentation for specific methods:
diagnose(x, ...)diagnose(x, ...)
x |
An analysis object. |
... |
Additional arguments passed to methods. |
Diagnostic output (format depends on the analysis type).
Provides diagnostic information for CmdStan MCMC analysis objects.
For more details on diagnostics and how to address issues see:
https://mc-stan.org/docs/cmdstan-guide/diagnose.html
## S3 method for class 'cmdstan_mcmc_analysis' diagnose(x, ...)## S3 method for class 'cmdstan_mcmc_analysis' diagnose(x, ...)
x |
A cmdstan_mcmc_analysis object. |
... |
Additional arguments (unused). |
Output from CmdStan's diagnostic function.
Provides diagnostic information for CmdStan Pathfinder analysis objects.
For more details on diagnostics and how to address issues see:
https://mc-stan.org/docs/cmdstan-guide/diagnose.html
## S3 method for class 'cmdstan_pathfinder_analysis' diagnose(x, ...)## S3 method for class 'cmdstan_pathfinder_analysis' diagnose(x, ...)
x |
A cmdstan_pathfinder_analysis object. |
... |
Additional arguments (unused). |
Output from CmdStan's diagnostic function.
Provides diagnostic information for CmdStan Variational analysis objects.
For more details on diagnostics and how to address issues see:
https://mc-stan.org/docs/cmdstan-guide/diagnose.html
## S3 method for class 'cmdstan_variational_analysis' diagnose(x, ...)## S3 method for class 'cmdstan_variational_analysis' diagnose(x, ...)
x |
A cmdstan_variational_analysis object. |
... |
Additional arguments (unused). |
Output from CmdStan's diagnostic function.
Provides a one-row summary of Laplace approximation analysis results.
## S3 method for class 'cmdstan_laplace_analysis' glance(x, ...)## S3 method for class 'cmdstan_laplace_analysis' glance(x, ...)
x |
A |
... |
Additional arguments (unused). |
Diagnostic interpretation:
return_code: Should be 0. Non-zero values indicate the optimizer failed to find the posterior mode, invalidating the Laplace approximation.
A tibble with one row containing:
Number of observations in the dataset
Number of parameters
Logical indicating optimization convergence
Optimization return code for mode finding. Problem indicators: Non-zero values indicate mode-finding issues
Provides a one-row summary of key diagnostics for MCMC analysis results.
## S3 method for class 'cmdstan_mcmc_analysis' glance( x, ..., max_perc_divergent = getOption("mb.prop_divergent", 0.002) * 100 )## S3 method for class 'cmdstan_mcmc_analysis' glance( x, ..., max_perc_divergent = getOption("mb.prop_divergent", 0.002) * 100 )
x |
A |
... |
Additional arguments (unused). |
max_perc_divergent |
A percentage indicating the maximum number of
divergent transitions allowed for determining if the model converged.
Generally set via |
Diagnostic interpretation:
Divergent transitions: Should ideally be 0. Any divergent transitions indicate the sampler had numerical issues and results may be unreliable.
Max treedepth: Should ideally be 0 or very low. High values suggest the sampler is working hard and may benefit from reparameterization. Increasing max treedepth is also an option but it is generally discouraged since it increases model fitting times without addressing the underlying issue. High max treedepth does not necessarily indicate convergence issues.
E-BFMI: Should be > 0.2. Values < 0.2 suggest poor adaptation, often requiring longer warmup or model reparameterization.
However, the sensitivity to problematic diagnostics depends on the analysis
mode set via embr::set_analysis_mode(). The 'paper' mode is the only
mode that requires divergent transitions to be 0% – all other modes accept
some level of tolerance.
A tibble with one row containing:
Number of observations in the dataset
Number of parameters
Number of MCMC chains
Number of iterations per chain (post-warmup)
Thinning interval
Logical indicating convergence.
TRUE if:
max(rhat) is less than or equal to its threshold,
min(ESS) is greater than or equal to its threshold, and
perc_divergent is less than or euqal to its threshold.
Thresholds are determined by the analysis mode set by embr::set_analysis_mode().
Percentage of divergent transitions across all chains. Problem indicators: Any value > 0% indicates sampling issues
Percentage of transitions that hit maximum tree depth. Problem indicators: Values > 0% may indicate inefficient sampling
Minimum Energy Bayesian Fraction of Missing Information across chains. Problem indicators: Values < 0.2 indicate poor adaptation/warmup
Provides a one-row summary of optimization analysis results.
## S3 method for class 'cmdstan_optimize_analysis' glance(x, ...)## S3 method for class 'cmdstan_optimize_analysis' glance(x, ...)
x |
A |
... |
Additional arguments (unused). |
Diagnostic interpretation:
return_code: Should be 0. Non-zero values indicate the optimizer encountered issues (e.g., 1 = max iterations reached, 2 = convergence issues).
A tibble with one row containing:
Number of observations in the dataset
Number of parameters
Logical indicating optimization convergence
Optimization return code. Problem indicators: Non-zero values indicate optimization issues
Provides a one-row summary of key diagnostics for Pathfinder analysis results.
## S3 method for class 'cmdstan_pathfinder_analysis' glance(x, ...)## S3 method for class 'cmdstan_pathfinder_analysis' glance(x, ...)
x |
A |
... |
Additional arguments (unused). |
Diagnostic interpretation:
return_code: Should be 0. Non-zero values indicate pathfinder failed to find a good approximation.
A tibble with one row containing:
Number of observations in the dataset
Number of parameters
Logical indicating pathfinder convergence
Pathfinder return code. Problem indicators: Non-zero values indicate pathfinder issues
Provides a one-row summary of variational inference analysis results.
## S3 method for class 'cmdstan_variational_analysis' glance(x, ...)## S3 method for class 'cmdstan_variational_analysis' glance(x, ...)
x |
A |
... |
Additional arguments (unused). |
Diagnostic interpretation:
return_code: Should be 0. Non-zero values indicate the variational algorithm failed to converge to a stable ELBO (Evidence Lower BOund).
A tibble with one row containing:
Number of observations in the dataset
Number of parameters
Logical indicating ELBO convergence
Optimization return code. Problem indicators: Non-zero values indicate convergence issues
Tests whether x is an object of class 'cmdstan_analysis'
is.cmdstan_analysis(x)is.cmdstan_analysis(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Tests whether x is an object of class 'cmdstan_mcmc_analysis'
is.cmdstan_mcmc_analysis(x)is.cmdstan_mcmc_analysis(x)
x |
The object to test. |
A flag indicating whether the test was positive.
Print Method for CmdStan MCMC Diagnostics
## S3 method for class 'cmdstan_diagnostics' print(x, ...)## S3 method for class 'cmdstan_diagnostics' print(x, ...)
x |
A cmdstan_mcmc_diagnostics object. |
... |
Additional arguments (currently unused). |