hmclearn-plots {hmclearn}R Documentation

Plotting for MCMC visualization and diagnostics provided by bayesplot package

Description

Plots of Rhat statistics, ratios of effective sample size to total sample size, and autocorrelation of MCMC draws.

Usage

mcmc_intervals(object, ...)

## S3 method for class 'hmclearn'
mcmc_intervals(object, burnin = NULL, ...)

mcmc_areas(object, ...)

## S3 method for class 'hmclearn'
mcmc_areas(object, burnin = NULL, ...)

mcmc_hist(object, ...)

## S3 method for class 'hmclearn'
mcmc_hist(object, burnin = NULL, ...)

mcmc_hist_by_chain(object, ...)

## S3 method for class 'hmclearn'
mcmc_hist_by_chain(object, burnin = NULL, ...)

mcmc_dens(object, ...)

## S3 method for class 'hmclearn'
mcmc_dens(object, burnin = NULL, ...)

mcmc_scatter(object, ...)

## S3 method for class 'hmclearn'
mcmc_scatter(object, burnin = NULL, ...)

mcmc_hex(object, ...)

## S3 method for class 'hmclearn'
mcmc_hex(object, burnin = NULL, ...)

mcmc_pairs(object, ...)

## S3 method for class 'hmclearn'
mcmc_pairs(object, burnin = NULL, ...)

mcmc_acf(object, ...)

## S3 method for class 'hmclearn'
mcmc_acf(object, burnin = NULL, ...)

mcmc_acf_bar(object, ...)

## S3 method for class 'hmclearn'
mcmc_acf_bar(object, burnin = NULL, ...)

mcmc_trace(object, ...)

## S3 method for class 'hmclearn'
mcmc_trace(object, burnin = NULL, ...)

mcmc_rhat(object, ...)

## S3 method for class 'hmclearn'
mcmc_rhat(object, burnin = NULL, ...)

mcmc_rhat_hist(object, ...)

## S3 method for class 'hmclearn'
mcmc_rhat_hist(object, burnin = NULL, ...)

mcmc_neff(object, ...)

## S3 method for class 'hmclearn'
mcmc_neff(object, burnin = NULL, lagmax = NULL, ...)

mcmc_neff_hist(object, ...)

## S3 method for class 'hmclearn'
mcmc_neff_hist(object, burnin = NULL, lagmax = NULL, ...)

mcmc_neff_data(object, ...)

## S3 method for class 'hmclearn'
mcmc_neff_data(object, burnin = NULL, lagmax = NULL, ...)

mcmc_violin(object, ...)

## S3 method for class 'hmclearn'
mcmc_violin(object, burnin = NULL, ...)

Arguments

object

an object of class hmclearn, usually a result of a call to mh or hmc

...

optional additional arguments to pass to the bayesplot functions

burnin

optional numeric parameter for the number of initial MCMC samples to omit from the summary

lagmax

maximum lag to extract for determining effective sample sizes

Value

These functions call various plotting functions from the bayesplot package, which returns a list including ggplot2 objects.

Plot Descriptions from the bayesplot package documentation

'mcmc_hist(object, burnin=NULL, ...)'

Default plot called by 'plot' function. Histograms of posterior draws with all chains merged.

'mcmc_dens(object, burnin=NULL, ...)'

Kernel density plots of posterior draws with all chains merged.

'mcmc_hist_by_chain(object, burnin=NULL, ...)'

Histograms of posterior draws with chains separated via faceting.

'mcmc_dens_overlay(object, burnin=NULL, ...)'

Kernel density plots of posterior draws with chains separated but overlaid on a single plot.

'mcmc_violin(object, burnin=NULL, ...)'

The density estimate of each chain is plotted as a violin with horizontal lines at notable quantiles.

'mcmc_dens_chains(object, burnin=NULL, ...)'

Ridgeline kernel density plots of posterior draws with chains separated but overlaid on a single plot. In 'mcmc_dens_overlay()' parameters appear in separate facets; in 'mcmc_dens_chains()' they appear in the same panel and can overlap vertically.

'mcmc_intervals(object, burnin=NULL, ...)'

Plots of uncertainty intervals computed from posterior draws with all chains merged.

'mcmc_areas(object, burnin=NULL, ...)'

Density plots computed from posterior draws with all chains merged, with uncertainty intervals shown as shaded areas under the curves.

'mcmc_scatter(object, burnin=NULL, ...)'

Bivariate scatterplot of posterior draws. If using a very large number of posterior draws then 'mcmc_hex()' may be preferable to avoid overplotting.

'mcmc_hex(object, burnin=NULL, ...)'

Hexagonal heatmap of 2-D bin counts. This plot is useful in cases where the posterior sample size is large enough that 'mcmc_scatter()' suffers from overplotting.

'mcmc_pairs(object, burnin=NULL, ...)'

A square plot matrix with univariate marginal distributions along the diagonal (as histograms or kernel density plots) and bivariate distributions off the diagonal (as scatterplots or hex heatmaps).

For the off-diagonal plots, the default is to split the chains so that (roughly) half are displayed above the diagonal and half are below (all chains are always merged together for the plots along the diagonal). Other possibilities are available by setting the 'condition' argument.

'mcmc_rhat(object, burnin=NULL, ...)', 'mcmc_rhat_hist(object, burnin=NULL, ...)'

Rhat values as either points or a histogram. Values are colored using different shades (lighter is better). The chosen thresholds are somewhat arbitrary, but can be useful guidelines in practice. * _light_: below 1.05 (good) * _mid_: between 1.05 and 1.1 (ok) * _dark_: above 1.1 (too high)

'mcmc_neff(object, burnin=NULL, ...)', 'mcmc_neff_hist(object, burnin=NULL, ...)'

Ratios of effective sample size to total sample size as either points or a histogram. Values are colored using different shades (lighter is better). The chosen thresholds are somewhat arbitrary, but can be useful guidelines in practice. * _light_: between 0.5 and 1 (high) * _mid_: between 0.1 and 0.5 (good) * _dark_: below 0.1 (low)

'mcmc_acf(object, burnin=NULL, ...)', 'mcmc_acf_bar(object, burnin=NULL, ...)'

Grid of autocorrelation plots by chain and parameter. The 'lags' argument gives the maximum number of lags at which to calculate the autocorrelation function. 'mcmc_acf()' is a line plot whereas 'mcmc_acf_bar()' is a barplot.

References

Gabry, Jonah and Mahr, Tristan (2019). bayesplot: Plotting for Bayesian Models. https://mc-stan.org/bayesplot/

Gabry, J., Simpson, D., Vehtari, A., Betancourt, M., and Gelman, A (2019). Visualization in Bayesian Workflow. Journal of the Royal Statistical Society: Series A. Vol 182. Issue 2. p.389-402.

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

Gelman, A., et. al. (2013) Bayesian Data Analysis. Chapman and Hall/CRC.

Examples

# poisson regression example
set.seed(7363)
X <- cbind(1, matrix(rnorm(40), ncol=2))
betavals <- c(0.8, -0.5, 1.1)
lmu <- X %*% betavals
y <- sapply(exp(lmu), FUN = rpois, n=1)

f <- hmc(N = 1000,
          theta.init = rep(0, 3),
          epsilon = c(0.03, 0.02, 0.015),
          L = 10,
          logPOSTERIOR = poisson_posterior,
          glogPOSTERIOR = g_poisson_posterior,
          varnames = paste0("beta", 0:2),
          param = list(y=y, X=X),
          parallel=FALSE, chains=2)

mcmc_trace(f, burnin=100)
mcmc_hist(f, burnin=100)
mcmc_intervals(f, burnin=100)
mcmc_rhat(f, burnin=100)
mcmc_violin(f, burnin=100)

[Package hmclearn version 0.0.5 Index]