| MCMC-distributions {bayesplot} | R Documentation |
Various types of histograms and kernel density plots of MCMC draws. See the Plot Descriptions section, below, for details.
mcmc_hist(x, pars = character(), regex_pars = character(), transformations = list(), facet_args = list(), ..., binwidth = NULL, freq = TRUE) mcmc_dens(x, pars = character(), regex_pars = character(), transformations = list(), facet_args = list(), ..., trim = FALSE) mcmc_hist_by_chain(x, pars = character(), regex_pars = character(), transformations = list(), facet_args = list(), ..., binwidth = NULL, freq = TRUE) mcmc_dens_overlay(x, pars = character(), regex_pars = character(), transformations = list(), facet_args = list(), ..., trim = FALSE) mcmc_violin(x, pars = character(), regex_pars = character(), transformations = list(), facet_args = list(), ..., probs = c(0.1, 0.5, 0.9))
x |
A 3-D array, matrix, list of matrices, or data frame of MCMC draws. The MCMC-overview page provides details on how to specify each these allowed inputs. |
pars |
An optional character vector of parameter names. If neither
|
regex_pars |
An optional regular expression to use for
parameter selection. Can be specified instead of |
transformations |
Optionally, transformations to apply to parameters
before plotting. If |
facet_args |
A named list of arguments (other than |
... |
Currently ignored. |
binwidth |
An optional value used as the |
freq |
For histograms, |
trim |
A logical scalar passed to |
probs |
A numeric vector passed to |
A ggplot object that can be further customized using the ggplot2 package.
mcmc_histHistograms of posterior draws with all chains merged.
mcmc_densKernel density plots of posterior draws with all chains merged.
mcmc_hist_by_chainHistograms of posterior draws with chains separated via faceting.
mcmc_dens_overlayKernel density plots of posterior draws with chains separated but overlaid on a single plot.
mcmc_violinThe density estimate of each chain is plotted as a violin with horizontal lines at notable quantiles.
Other MCMC: MCMC-combos,
MCMC-diagnostics,
MCMC-intervals, MCMC-nuts,
MCMC-overview, MCMC-parcoord,
MCMC-recover,
MCMC-scatterplots,
MCMC-traces
# some parameter draws to use for demonstration
x <- example_mcmc_draws()
dim(x)
dimnames(x)
##################
### Histograms ###
##################
# histograms of all parameters
color_scheme_set("brightblue")
mcmc_hist(x)
# histograms of some parameters
color_scheme_set("pink")
mcmc_hist(x, pars = c("alpha", "beta[2]"))
mcmc_hist(x, pars = "sigma", regex_pars = "beta")
# example of using 'transformations' argument to plot log(sigma),
# and parsing facet labels (e.g. to get greek letters for parameters)
mcmc_hist(x, transformations = list(sigma = "log"),
facet_args = list(labeller = ggplot2::label_parsed)) +
facet_text(size = 15)
# instead of list(sigma = "log"), you could specify the transformation as
# list(sigma = log) or list(sigma = function(x) log(x)), but then the
# label for the transformed sigma is 't(sigma)' instead of 'log(sigma)'
mcmc_hist(x, transformations = list(sigma = log))
# separate histograms by chain
color_scheme_set("pink")
mcmc_hist_by_chain(x, regex_pars = "beta")
#################
### Densities ###
#################
mcmc_dens(x, pars = c("sigma", "beta[2]"),
facet_args = list(nrow = 2))
# separate and overlay chains
color_scheme_set("mix-teal-pink")
mcmc_dens_overlay(x, pars = c("sigma", "beta[2]"),
facet_args = list(nrow = 2)) +
facet_text(size = 14)
# separate chains as violin plots
color_scheme_set("green")
mcmc_violin(x) + panel_bg(color = "gray20", size = 2, fill = "gray30")