V1.7.0 of bayesplot released

v1.7.0 of the bayesplot R package is now on CRAN! There are a bunch of new features (including ‘tidy’ parameter selection, new plots, new colors) and several fixes in this release. Release notes are copied below but are best viewed at mc-stan.org/bayesplot/news.


After CRAN binaries are built (usually a few days) just use install.packages("bayesplot"). Before binaries are available the update can be installed from CRAN using

install.packages("bayesplot", type = "source", repos = "https://cran.rstudio.com/")

or from GitHub using

# note: setting build_vignettes=TRUE will be much slower and you can always access 
# the vignettes online at mc-stan.org/bayesplot/articles/
devtools::install_github("stan-dev/bayesplot", ref = "v1.7.0", build_vignettes = FALSE) 

Release notes

(GitHub issue/PR numbers in parenthesis)

  • The pars argument of all MCMC plotting functions now supports tidy variable selection. See help("tidy-params", package="bayesplot") or https://mc-stan.org/bayesplot/reference/tidy-params.html for details and examples. (#161, #183, #188)

  • Two new MCMC diagnostic plots have been added for inspecting the distribution of ranks.
    Rank histograms were introduced by the Stan team’s
    new paper on MCMC diagnostics. (#178, #179)

    • mcmc_rank_hist(): A traditional traceplot (mcmc_trace()) visualizes how
      sampled values the MCMC chains mix over the course of sampling. A rank
      histogram (mcmc_rank_hist()) visualizes how the ranks of values from the
      chains mix together. An ideal plot would show the ranks mixing or overlapping
      in a uniform distribution.

    • mcmc_rank_overlay(): Instead of drawing each chain’s histogram in a separate
      panel, this plot draws the top edge of the chains’ histograms in a single panel.

  • Added mcmc_trace_data(), which returns the data used for plotting the trace plots and rank histograms. (Advances #97)

  • ColorBrewer palettes are now available as color schemes via color_scheme_set().
    For example, color_scheme_set("brewer-Spectral") will use the Spectral
    palette. (#177, #190)

  • MCMC plots now also accept objects with an as.array() method as
    input (e.g., stanfit objects). (#175, #184)

  • mcmc_trace() gains an argument iter1 which can be used to label the traceplot starting
    from the first iteration after warmup. (#14, #155, @mcol)

  • mcmc_areas() gains an argument area_method which controls how to draw the density
    curves. The default "equal area" constrains the heights so that the curves
    have the same area. As a result, a narrow interval will appear as a spike
    of density, while a wide, uncertain interval is spread thin over the x axis.
    Alternatively "equal height" will set the maximum height on each curve to
    the same value. This works well when the intervals are about the same width.
    Otherwise, that wide, uncertain interval will dominate the visual space
    compared to a narrow, less uncertain interval. A compromise between the two is
    "scaled height" which scales the curves from "equal height" using
    height * sqrt(height). (#163, #169)

  • mcmc_areas() correctly plots density curves where the point estimate
    does not include the highest point of the density curve.
    (#168, #169, @jtimonen)

  • mcmc_areas_ridges() draws the vertical line at x = 0 over the curves so
    that it is always visible.

  • mcmc_intervals() and mcmc_areas() raise a warning if prob_outer is ever
    less than prob. It sorts these two values into the correct order. (#138)

  • MCMC parameter names are now always converted to factors prior to
    plotting. We use factors so that the order of parameters in a plot matches
    the order of the parameters in the original MCMC data. This change fixes a
    case where factor-conversion failed. (#162, #165, @wwiecek)

  • The examples in ?ppc_loo_pit_overlay() now work as expected. (#166, #167)

  • Added "viridisD" as an alternative name for "viridis" to the supported colors.

  • Added "viridisE" (the cividis version of viridis) to the supported colors.

  • ppc_bars() and ppc_bars_grouped() now allow negative integers as input. (#172, @jeffpollock9)


Here is a brief demo of the new plots, two of the new color schemes, and the changes to mcmc_areas().

#> This is bayesplot version 1.7.0
#> - Online documentation and vignettes at mc-stan.org/bayesplot
#> - bayesplot theme set to bayesplot::theme_default()
#>    * Does _not_ affect other ggplot2 plots
#>    * See ?bayesplot_theme_set for details on theme setting

x <- example_mcmc_draws(params = 5)

# Simulate a bad chain
x_bad <- x
x_bad[, "chain:1", "beta[1]"] <- rnorm(250, .6, .1)

# New plot
mcmc_rank_hist(x, c("alpha")) + 
  ggtitle("basic rank histogram")

mcmc_rank_hist(x_bad, c("beta[1]", "beta[2]"), ref_line = TRUE) + 
  ggtitle("rank histogram with 2 parameters, reference line")

# New color scheme

# New plot
mcmc_rank_overlay(x_bad, c("beta[1]", "beta[2]")) + 
  ggtitle("rank overlay and spectral color scheme")

# New color scheme

# New options for MCMC areas
mcmc_areas(x, vars(starts_with("beta")), area_method = "equal area") + 
  ggtitle("Density curves with same area")

mcmc_areas(x, vars(starts_with("beta")), area_method = "equal height") + 
  ggtitle("Density curves with same max height")

mcmc_areas(x, vars(starts_with("beta")), area_method = "scaled height") + 
  ggtitle("Density curves with height scaled to `height * sqrt(height)`")

Created on 2019-05-24 by the reprex package (v0.3.0)


Way to go @jonah that tidy parameter selection is pretty cool!


Credit to @tjmahr too. Definitely a joint effort.

1 Like