diff --git a/DESCRIPTION b/DESCRIPTION index 833e7c99..209c937e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: bayesplot Type: Package Title: Plotting for Bayesian Models -Version: 1.11.1.9000 -Date: 2024-02-14 +Version: 1.12.0 +Date: 2025-04-09 Authors@R: c(person("Jonah", "Gabry", role = c("aut", "cre"), email = "jsg2201@columbia.edu"), person("Tristan", "Mahr", role = "aut"), person("Paul-Christian", "Bürkner", role = "ctb"), @@ -37,6 +37,7 @@ Imports: rlang (>= 0.3.0), stats, tibble (>= 2.0.0), + tidyr, tidyselect, utils Suggests: @@ -55,7 +56,7 @@ Suggests: survival, testthat (>= 2.0.0), vdiffr (>= 1.0.2) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 VignetteBuilder: knitr Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/NEWS.md b/NEWS.md index 04fe30be..d925f84c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,16 @@ -# bayesplot 1.11.1.9000 +# bayesplot 1.12.0 + +* Expand checking workflows to more platforms by @andrjohns (#324) +* Skip tests depending on Suggested dependency rstantools if not installed by @MichaelChirico (#325) +* Skip tests depending on Suggested dependency gridExtra if not installed by @MichaelChirico (#326) +* Fix missing legends for unobserved levels in rhat and neff plots (#328) +* Document problems with `ppc_stat` with `stat="mean"` (#329) +* Ensure rank overlay plot starts at 0 even if not all bins present, thanks @sims1253 (#332) +* Compatibility with ggplot2 3.6.0 by @teunbrand (#337) +* Update GitHub actions workflows (#338) +* Remove deprecated functions from `available_ppc()` (#340) +* Fix missing counts in `ppc_bars_data()` by @TeemuSailynoja, thanks @famuvie (#342) -Items for next release go here # bayesplot 1.11.1 diff --git a/R/mcmc-overview.R b/R/mcmc-overview.R index 923c4aa6..40368641 100644 --- a/R/mcmc-overview.R +++ b/R/mcmc-overview.R @@ -26,7 +26,7 @@ #' an additional column `"Chain"` that contains the chain number (an integer) #' corresponding to each row in the data frame. #' * __draws__: Any of the `draws` formats supported by the -#' \pkg{\link{posterior}} package. +#' \pkg{posterior} package. #' #' __Note__: typically the user should *not* include warmup iterations #' in the object passed to **bayesplot** plotting functions, although for diff --git a/R/mcmc-scatterplots.R b/R/mcmc-scatterplots.R index 8ad5af6f..ccfa4099 100644 --- a/R/mcmc-scatterplots.R +++ b/R/mcmc-scatterplots.R @@ -212,7 +212,7 @@ mcmc_hex <- function(x, #' `alpha`. #' @param grid_args,save_gg_objects For `mcmc_pairs()`, arguments to pass to #' [bayesplot_grid()]. For example, since `mcmc_pairs()` returns -#' more than a single ggplot object, using [ggtitle()] afterwards +#' more than a single ggplot object, using `ggtitle()` afterwards #' will not work. But you you can still add a title to the plot using #' `grid_args = list(top="My title")`. #' diff --git a/R/ppc-discrete.R b/R/ppc-discrete.R index 89f6ee00..199c394b 100644 --- a/R/ppc-discrete.R +++ b/R/ppc-discrete.R @@ -395,6 +395,7 @@ ppc_bars_data <- data <- reshape2::melt(tmp_data, id.vars = "group") %>% count(.data$group, .data$value, .data$variable) %>% + tidyr::complete(.data$group, .data$value, .data$variable, fill = list(n = 0)) %>% group_by(.data$variable, .data$group) %>% mutate(proportion = .data$n / sum(.data$n)) %>% ungroup() %>% diff --git a/man-roxygen/args-mcmc-x.R b/man-roxygen/args-mcmc-x.R index e02a0a5a..921c17ef 100644 --- a/man-roxygen/args-mcmc-x.R +++ b/man-roxygen/args-mcmc-x.R @@ -1,7 +1,7 @@ #' @param x An object containing MCMC draws: #' * A 3-D array, matrix, list of matrices, or data frame. The [MCMC-overview] #' page provides details on how to specify each these. -#' * A `draws` object from the \pkg{\link{posterior}} package (e.g., +#' * A `draws` object from the \pkg{posterior} package (e.g., #' `draws_array`, `draws_rvars`, etc.). #' * An object with an `as.array()` method that returns the same kind of 3-D #' array described on the [MCMC-overview] page. diff --git a/man/MCMC-combos.Rd b/man/MCMC-combos.Rd index 70506180..9f4e1485 100644 --- a/man/MCMC-combos.Rd +++ b/man/MCMC-combos.Rd @@ -12,7 +12,7 @@ mcmc_combo(x, combo = c("dens", "trace"), ..., widths = NULL, gg_theme = NULL) \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/man/MCMC-diagnostics.Rd b/man/MCMC-diagnostics.Rd index 1ca949bb..ae47edac 100644 --- a/man/MCMC-diagnostics.Rd +++ b/man/MCMC-diagnostics.Rd @@ -68,7 +68,7 @@ total sample size. See \code{\link[=neff_ratio]{neff_ratio()}}.} \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/man/MCMC-distributions.Rd b/man/MCMC-distributions.Rd index da157805..deff7e48 100644 --- a/man/MCMC-distributions.Rd +++ b/man/MCMC-distributions.Rd @@ -108,7 +108,7 @@ mcmc_violin( \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/man/MCMC-intervals.Rd b/man/MCMC-intervals.Rd index 10f38c5e..804b5bd4 100644 --- a/man/MCMC-intervals.Rd +++ b/man/MCMC-intervals.Rd @@ -105,7 +105,7 @@ mcmc_areas_ridges_data( \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/man/MCMC-overview.Rd b/man/MCMC-overview.Rd index 54547938..d426d30f 100644 --- a/man/MCMC-overview.Rd +++ b/man/MCMC-overview.Rd @@ -27,7 +27,7 @@ have already been merged), or a data frame with one column per parameter plus an additional column \code{"Chain"} that contains the chain number (an integer) corresponding to each row in the data frame. \item \strong{draws}: Any of the \code{draws} formats supported by the -\pkg{\link{posterior}} package. +\pkg{posterior} package. } \strong{Note}: typically the user should \emph{not} include warmup iterations diff --git a/man/MCMC-parcoord.Rd b/man/MCMC-parcoord.Rd index 176cb9f0..3ea32731 100644 --- a/man/MCMC-parcoord.Rd +++ b/man/MCMC-parcoord.Rd @@ -34,7 +34,7 @@ parcoord_style_np(div_color = "red", div_size = 0.2, div_alpha = 0.2) \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/man/MCMC-recover.Rd b/man/MCMC-recover.Rd index 03700829..de179434 100644 --- a/man/MCMC-recover.Rd +++ b/man/MCMC-recover.Rd @@ -46,7 +46,7 @@ mcmc_recover_hist( \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/man/MCMC-scatterplots.Rd b/man/MCMC-scatterplots.Rd index 9cd2a692..8a67a9f1 100644 --- a/man/MCMC-scatterplots.Rd +++ b/man/MCMC-scatterplots.Rd @@ -76,7 +76,7 @@ pairs_condition(chains = NULL, draws = NULL, nuts = NULL) \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. @@ -179,7 +179,7 @@ treedepth.} \item{grid_args, save_gg_objects}{For \code{mcmc_pairs()}, arguments to pass to \code{\link[=bayesplot_grid]{bayesplot_grid()}}. For example, since \code{mcmc_pairs()} returns -more than a single ggplot object, using \code{\link[=ggtitle]{ggtitle()}} afterwards +more than a single ggplot object, using \code{ggtitle()} afterwards will not work. But you you can still add a title to the plot using \code{grid_args = list(top="My title")}.} diff --git a/man/MCMC-traces.Rd b/man/MCMC-traces.Rd index 1054591b..8d578352 100644 --- a/man/MCMC-traces.Rd +++ b/man/MCMC-traces.Rd @@ -94,7 +94,7 @@ mcmc_trace_data( \itemize{ \item A 3-D array, matrix, list of matrices, or data frame. The \link{MCMC-overview} page provides details on how to specify each these. -\item A \code{draws} object from the \pkg{\link{posterior}} package (e.g., +\item A \code{draws} object from the \pkg{posterior} package (e.g., \code{draws_array}, \code{draws_rvars}, etc.). \item An object with an \code{as.array()} method that returns the same kind of 3-D array described on the \link{MCMC-overview} page. diff --git a/tests/testthat/_snaps/ppc-discrete/ppc-bars-default.svg b/tests/testthat/_snaps/ppc-discrete/ppc-bars-default.svg index 4884ed5f..9e825ec3 100644 --- a/tests/testthat/_snaps/ppc-discrete/ppc-bars-default.svg +++ b/tests/testthat/_snaps/ppc-discrete/ppc-bars-default.svg @@ -29,17 +29,20 @@ + - - + + + - + + diff --git a/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-default.svg b/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-default.svg index 79b7916f..d9158435 100644 --- a/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-default.svg +++ b/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-default.svg @@ -29,17 +29,20 @@ + - - + + + - - + + + @@ -54,16 +57,21 @@ + + + - - + + + - + + diff --git a/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-facet-args-prob-size.svg b/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-facet-args-prob-size.svg index fc093aee..a9372d7a 100644 --- a/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-facet-args-prob-size.svg +++ b/tests/testthat/_snaps/ppc-discrete/ppc-bars-grouped-facet-args-prob-size.svg @@ -29,17 +29,20 @@ + - - + + + - - + + + @@ -54,16 +57,21 @@ + + + - + + - + + diff --git a/tests/testthat/_snaps/ppc-discrete/ppc-bars-prob-0-33-width-size-fatten.svg b/tests/testthat/_snaps/ppc-discrete/ppc-bars-prob-0-33-width-size-fatten.svg index 800dd449..3fd563df 100644 --- a/tests/testthat/_snaps/ppc-discrete/ppc-bars-prob-0-33-width-size-fatten.svg +++ b/tests/testthat/_snaps/ppc-discrete/ppc-bars-prob-0-33-width-size-fatten.svg @@ -29,17 +29,20 @@ + - - + + + - + + diff --git a/tests/testthat/_snaps/ppc-discrete/ppc-bars-width-size-fatten.svg b/tests/testthat/_snaps/ppc-discrete/ppc-bars-width-size-fatten.svg index 9da25a91..c8dbda46 100644 --- a/tests/testthat/_snaps/ppc-discrete/ppc-bars-width-size-fatten.svg +++ b/tests/testthat/_snaps/ppc-discrete/ppc-bars-width-size-fatten.svg @@ -29,17 +29,20 @@ + - - + + + - + + diff --git a/tests/testthat/test-ppc-discrete.R b/tests/testthat/test-ppc-discrete.R index 2a1d5285..a5ddb622 100644 --- a/tests/testthat/test-ppc-discrete.R +++ b/tests/testthat/test-ppc-discrete.R @@ -68,15 +68,15 @@ test_that("ppc_bars_data includes all levels", { # yrep has more unique values than y d2 <- ppc_bars_data(y_ord2, yrep_ord) expect_equal(d2$x, 1:4) - expect_equal(d2$y_obs, c(NA, sum(tab[1:2]), tab[3:4])) + expect_equal(d2$y_obs, c(0, sum(tab[1:2]), tab[3:4])) # y has more unique values than yrep d3 <- ppc_bars_data(y_ord, yrep_ord2) expect_equal(d3$x, 1:4) expect_equal(d3$y_obs, tab) - expect_equivalent(d3$l[2], NA_real_) - expect_equivalent(d3$m[2], NA_real_) - expect_equivalent(d3$h[2], NA_real_) + expect_equivalent(d3$l[2], 0) + expect_equivalent(d3$m[2], 0) + expect_equivalent(d3$h[2], 0) }) diff --git a/vignettes/visual-mcmc-diagnostics.Rmd b/vignettes/visual-mcmc-diagnostics.Rmd index b1358dd3..9e24ec57 100644 --- a/vignettes/visual-mcmc-diagnostics.Rmd +++ b/vignettes/visual-mcmc-diagnostics.Rmd @@ -449,7 +449,7 @@ us diagnose divergences. We may however zoom in to investigate, using the ```{r echo=FALSE} #A check that the chosen window still relevant -n_divergent_in_window <- np_cp %>% filter(Parameter == "divergent__" & Value == 1 & Iteration >= 300 & Iteration <= 500) %>% nrow() +n_divergent_in_window <- np_cp %>% filter(Parameter == "divergent__" & Value == 1 & Iteration >= 400 & Iteration <= 600) %>% nrow() if(n_divergent_in_window < 6) { divergences <- np_cp %>% filter(Parameter == "divergent__" & Value == 1) %>% select(Iteration) %>% get("Iteration", .) %>% sort() %>% paste(collapse = ",") @@ -458,7 +458,7 @@ if(n_divergent_in_window < 6) { ``` ```{r mcmc_trace_zoom} -mcmc_trace(posterior_cp, pars = "tau", np = np_cp, window = c(300,500)) + +mcmc_trace(posterior_cp, pars = "tau", np = np_cp, window = c(200,400)) + xlab("Post-warmup iteration") ```