From 2b81b98e69b93dc79e895b80e8fa7703c23267eb Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Sun, 12 Apr 2026 12:14:38 +0530 Subject: [PATCH 1/4] Unify density-control argument defaults --- NEWS.md | 1 + R/mcmc-intervals.R | 3 +++ R/ppc-distributions.R | 20 ++++++++++++-------- R/ppd-distributions.R | 12 ++++++++---- man-roxygen/args-density-controls.R | 3 ++- man/MCMC-distributions.Rd | 3 ++- man/MCMC-intervals.Rd | 3 ++- man/PPC-distributions.Rd | 19 ++++++++++--------- man/PPD-distributions.Rd | 11 ++++++----- 9 files changed, 46 insertions(+), 29 deletions(-) diff --git a/NEWS.md b/NEWS.md index fceb6a8f..95319e3f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # bayesplot (development version) +* Changed `bw`, `adjust`, `kernel`, and `n_dens` defaults to `NULL` in `ppc_dens_overlay()`, `ppc_dens_overlay_grouped()`, and `ppd_dens_overlay()`. * `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated. * Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`. * Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`. diff --git a/R/mcmc-intervals.R b/R/mcmc-intervals.R index 2dd4fd72..361d831d 100644 --- a/R/mcmc-intervals.R +++ b/R/mcmc-intervals.R @@ -805,6 +805,9 @@ compute_column_density <- function(df, group_vars, value_var, ...) { compute_interval_density <- function(x, interval_width = 1, n_dens = 1024, bw = NULL, adjust = NULL, kernel = NULL, bounds = NULL) { + bw <- bw %||% "nrd0" + adjust <- adjust %||% 1 + kernel <- kernel %||% "gaussian" n_dens <- n_dens %||% 1024 tail_width <- (1 - interval_width) / 2 diff --git a/R/ppc-distributions.R b/R/ppc-distributions.R index 7ab9ffb8..70a7cb10 100644 --- a/R/ppc-distributions.R +++ b/R/ppc-distributions.R @@ -170,12 +170,16 @@ ppc_dens_overlay <- size = 0.25, alpha = 0.7, trim = FALSE, - bw = "nrd0", - adjust = 1, - kernel = "gaussian", + bw = NULL, + adjust = NULL, + kernel = NULL, bounds = NULL, - n_dens = 1024) { + n_dens = NULL) { check_ignored_arguments(...) + bw <- bw %||% "nrd0" + adjust <- adjust %||% 1 + kernel <- kernel %||% "gaussian" + n_dens <- n_dens %||% 1024 bounds <- validate_density_bounds(bounds) data <- ppc_data(y, yrep) @@ -224,11 +228,11 @@ ppc_dens_overlay_grouped <- function(y, size = 0.25, alpha = 0.7, trim = FALSE, - bw = "nrd0", - adjust = 1, - kernel = "gaussian", + bw = NULL, + adjust = NULL, + kernel = NULL, bounds = NULL, - n_dens = 1024) { + n_dens = NULL) { check_ignored_arguments(...) p_overlay <- ppc_dens_overlay( diff --git a/R/ppd-distributions.R b/R/ppd-distributions.R index fca2d5ee..f2e76860 100644 --- a/R/ppd-distributions.R +++ b/R/ppd-distributions.R @@ -42,12 +42,16 @@ ppd_dens_overlay <- size = 0.25, alpha = 0.7, trim = FALSE, - bw = "nrd0", - adjust = 1, - kernel = "gaussian", + bw = NULL, + adjust = NULL, + kernel = NULL, bounds = NULL, - n_dens = 1024) { + n_dens = NULL) { check_ignored_arguments(...) + bw <- bw %||% "nrd0" + adjust <- adjust %||% 1 + kernel <- kernel %||% "gaussian" + n_dens <- n_dens %||% 1024 bounds <- validate_density_bounds(bounds) data <- ppd_data(ypred) diff --git a/man-roxygen/args-density-controls.R b/man-roxygen/args-density-controls.R index b560ed2a..c01c789b 100644 --- a/man-roxygen/args-density-controls.R +++ b/man-roxygen/args-density-controls.R @@ -1,4 +1,5 @@ #' @param bw,adjust,kernel,n_dens,bounds Optional arguments passed to #' [stats::density()] (and `bounds` to [ggplot2::stat_density()]) to override #' default kernel density estimation parameters or truncate the density -#' support. `n_dens` defaults to `1024`. +#' support. `bw` defaults to `"nrd0"`, `adjust` to `1`, `kernel` to +#' `"gaussian"`, and `n_dens` to `1024`. diff --git a/man/MCMC-distributions.Rd b/man/MCMC-distributions.Rd index 71be98d7..7ce61cc9 100644 --- a/man/MCMC-distributions.Rd +++ b/man/MCMC-distributions.Rd @@ -210,7 +210,8 @@ function.)} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{n_dens} defaults to \code{1024}.} +support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to +\code{"gaussian"}, and \code{n_dens} to \code{1024}.} \item{color_chains}{Option for whether to separately color chains.} diff --git a/man/MCMC-intervals.Rd b/man/MCMC-intervals.Rd index b98f835e..eb7bda20 100644 --- a/man/MCMC-intervals.Rd +++ b/man/MCMC-intervals.Rd @@ -186,7 +186,8 @@ the ridgelines.} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{n_dens} defaults to \code{1024}.} +support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to +\code{"gaussian"}, and \code{n_dens} to \code{1024}.} } \value{ The plotting functions return a ggplot object that can be further diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index b02cc26c..95823bcb 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -27,11 +27,11 @@ ppc_dens_overlay( size = 0.25, alpha = 0.7, trim = FALSE, - bw = "nrd0", - adjust = 1, - kernel = "gaussian", + bw = NULL, + adjust = NULL, + kernel = NULL, bounds = NULL, - n_dens = 1024 + n_dens = NULL ) ppc_dens_overlay_grouped( @@ -42,11 +42,11 @@ ppc_dens_overlay_grouped( size = 0.25, alpha = 0.7, trim = FALSE, - bw = "nrd0", - adjust = 1, - kernel = "gaussian", + bw = NULL, + adjust = NULL, + kernel = NULL, bounds = NULL, - n_dens = 1024 + n_dens = NULL ) ppc_ecdf_overlay( @@ -172,7 +172,8 @@ the predictive distributions.} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{n_dens} defaults to \code{1024}.} +support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to +\code{"gaussian"}, and \code{n_dens} to \code{1024}.} \item{discrete}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} The \code{discrete} argument is deprecated. The ECDF is a step function by definition, so \code{geom_step()} is diff --git a/man/PPD-distributions.Rd b/man/PPD-distributions.Rd index 7517ec25..127f0b7f 100644 --- a/man/PPD-distributions.Rd +++ b/man/PPD-distributions.Rd @@ -21,11 +21,11 @@ ppd_dens_overlay( size = 0.25, alpha = 0.7, trim = FALSE, - bw = "nrd0", - adjust = 1, - kernel = "gaussian", + bw = NULL, + adjust = NULL, + kernel = NULL, bounds = NULL, - n_dens = 1024 + n_dens = NULL ) ppd_ecdf_overlay( @@ -87,7 +87,8 @@ the predictive distributions.} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{n_dens} defaults to \code{1024}.} +support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to +\code{"gaussian"}, and \code{n_dens} to \code{1024}.} \item{discrete}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} The \code{discrete} argument is deprecated. The ECDF is a step function by definition, so \code{geom_step()} is From 8012e75d2c7d32acb7cfa96e2864f90055a78c13 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Sun, 12 Apr 2026 13:50:24 +0530 Subject: [PATCH 2/4] Clarify NULL default wording in args-density-controls template --- man-roxygen/args-density-controls.R | 4 ++-- man/MCMC-distributions.Rd | 4 ++-- man/MCMC-intervals.Rd | 4 ++-- man/PPC-distributions.Rd | 4 ++-- man/PPD-distributions.Rd | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/man-roxygen/args-density-controls.R b/man-roxygen/args-density-controls.R index c01c789b..b194c05f 100644 --- a/man-roxygen/args-density-controls.R +++ b/man-roxygen/args-density-controls.R @@ -1,5 +1,5 @@ #' @param bw,adjust,kernel,n_dens,bounds Optional arguments passed to #' [stats::density()] (and `bounds` to [ggplot2::stat_density()]) to override #' default kernel density estimation parameters or truncate the density -#' support. `bw` defaults to `"nrd0"`, `adjust` to `1`, `kernel` to -#' `"gaussian"`, and `n_dens` to `1024`. +#' support. If `NULL` (default), `bw` is set to `"nrd0"`, `adjust` to `1`, +#' `kernel` to `"gaussian"`, and `n_dens` to `1024`. diff --git a/man/MCMC-distributions.Rd b/man/MCMC-distributions.Rd index 7ce61cc9..bfddd876 100644 --- a/man/MCMC-distributions.Rd +++ b/man/MCMC-distributions.Rd @@ -210,8 +210,8 @@ function.)} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to -\code{"gaussian"}, and \code{n_dens} to \code{1024}.} +support. If \code{NULL} (default), \code{bw} is set to \code{"nrd0"}, \code{adjust} to \code{1}, +\code{kernel} to \code{"gaussian"}, and \code{n_dens} to \code{1024}.} \item{color_chains}{Option for whether to separately color chains.} diff --git a/man/MCMC-intervals.Rd b/man/MCMC-intervals.Rd index eb7bda20..b17e851a 100644 --- a/man/MCMC-intervals.Rd +++ b/man/MCMC-intervals.Rd @@ -186,8 +186,8 @@ the ridgelines.} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to -\code{"gaussian"}, and \code{n_dens} to \code{1024}.} +support. If \code{NULL} (default), \code{bw} is set to \code{"nrd0"}, \code{adjust} to \code{1}, +\code{kernel} to \code{"gaussian"}, and \code{n_dens} to \code{1024}.} } \value{ The plotting functions return a ggplot object that can be further diff --git a/man/PPC-distributions.Rd b/man/PPC-distributions.Rd index 95823bcb..82501a66 100644 --- a/man/PPC-distributions.Rd +++ b/man/PPC-distributions.Rd @@ -172,8 +172,8 @@ the predictive distributions.} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to -\code{"gaussian"}, and \code{n_dens} to \code{1024}.} +support. If \code{NULL} (default), \code{bw} is set to \code{"nrd0"}, \code{adjust} to \code{1}, +\code{kernel} to \code{"gaussian"}, and \code{n_dens} to \code{1024}.} \item{discrete}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} The \code{discrete} argument is deprecated. The ECDF is a step function by definition, so \code{geom_step()} is diff --git a/man/PPD-distributions.Rd b/man/PPD-distributions.Rd index 127f0b7f..13eccdfa 100644 --- a/man/PPD-distributions.Rd +++ b/man/PPD-distributions.Rd @@ -87,8 +87,8 @@ the predictive distributions.} \item{bw, adjust, kernel, n_dens, bounds}{Optional arguments passed to \code{\link[stats:density]{stats::density()}} (and \code{bounds} to \code{\link[ggplot2:geom_density]{ggplot2::stat_density()}}) to override default kernel density estimation parameters or truncate the density -support. \code{bw} defaults to \code{"nrd0"}, \code{adjust} to \code{1}, \code{kernel} to -\code{"gaussian"}, and \code{n_dens} to \code{1024}.} +support. If \code{NULL} (default), \code{bw} is set to \code{"nrd0"}, \code{adjust} to \code{1}, +\code{kernel} to \code{"gaussian"}, and \code{n_dens} to \code{1024}.} \item{discrete}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} The \code{discrete} argument is deprecated. The ECDF is a step function by definition, so \code{geom_step()} is From 1e0c49d2aced197fb7793cd17d7db1f498b5c1e8 Mon Sep 17 00:00:00 2001 From: Utkarsh Date: Thu, 16 Apr 2026 11:50:38 +0530 Subject: [PATCH 3/4] rever computer interval density() and update ppc_loo_pit_overlay() to use NULL defaults --- NEWS.md | 3 ++- R/mcmc-intervals.R | 3 --- R/ppc-loo.R | 12 ++++++++---- man/PPC-loo.Rd | 8 ++++---- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index 7777736d..6e535265 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,8 @@ # bayesplot (development version) -* Changed `bw`, `adjust`, `kernel`, and `n_dens` defaults to `NULL` in `ppc_dens_overlay()`, `ppc_dens_overlay_grouped()`, and `ppd_dens_overlay()`. +* Unified density-control argument defaults (bw, adjust, kernel, n_dens) to use `NULL` with internal fallbacks. No change in user-facing behavior. * New `show_marginal` argument to `ppd_*()` functions to show the PPD - the marginal predictive distribution by @mattansb (#425) +* Unified density-control argument defaults (bw, adjust, kernel, n_dens) to use `NULL` with internal fallbacks. No change in user-facing behavior. * `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated. * Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`. * Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`. diff --git a/R/mcmc-intervals.R b/R/mcmc-intervals.R index 361d831d..2dd4fd72 100644 --- a/R/mcmc-intervals.R +++ b/R/mcmc-intervals.R @@ -805,9 +805,6 @@ compute_column_density <- function(df, group_vars, value_var, ...) { compute_interval_density <- function(x, interval_width = 1, n_dens = 1024, bw = NULL, adjust = NULL, kernel = NULL, bounds = NULL) { - bw <- bw %||% "nrd0" - adjust <- adjust %||% 1 - kernel <- kernel %||% "gaussian" n_dens <- n_dens %||% 1024 tail_width <- (1 - interval_width) / 2 diff --git a/R/ppc-loo.R b/R/ppc-loo.R index 2f91c5b5..76a5e34f 100644 --- a/R/ppc-loo.R +++ b/R/ppc-loo.R @@ -181,12 +181,16 @@ ppc_loo_pit_overlay <- function(y, alpha = 0.7, boundary_correction = TRUE, grid_len = 512, - bw = "nrd0", + bw = NULL, trim = FALSE, - adjust = 1, - kernel = "gaussian", - n_dens = 1024) { + adjust = NULL, + kernel = NULL, + n_dens = NULL) { check_ignored_arguments(..., ok_args = list("moment_match")) + bw <- bw %||% "nrd0" + adjust <- adjust %||% 1 + kernel <- kernel %||% "gaussian" + n_dens <- n_dens %||% 1024 data <- ppc_loo_pit_data( diff --git a/man/PPC-loo.Rd b/man/PPC-loo.Rd index 6c57dc5c..0c077d64 100644 --- a/man/PPC-loo.Rd +++ b/man/PPC-loo.Rd @@ -23,11 +23,11 @@ ppc_loo_pit_overlay( alpha = 0.7, boundary_correction = TRUE, grid_len = 512, - bw = "nrd0", + bw = NULL, trim = FALSE, - adjust = 1, - kernel = "gaussian", - n_dens = 1024 + adjust = NULL, + kernel = NULL, + n_dens = NULL ) ppc_loo_pit_data( From b06f6f3f84eb99cf481156678b7faa4e476ba01f Mon Sep 17 00:00:00 2001 From: Utkarsh Pawade Date: Thu, 16 Apr 2026 12:06:14 +0530 Subject: [PATCH 4/4] Update NEWS.md --- NEWS.md | 1 - 1 file changed, 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 6e535265..fd5b762c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,6 @@ * Unified density-control argument defaults (bw, adjust, kernel, n_dens) to use `NULL` with internal fallbacks. No change in user-facing behavior. * New `show_marginal` argument to `ppd_*()` functions to show the PPD - the marginal predictive distribution by @mattansb (#425) -* Unified density-control argument defaults (bw, adjust, kernel, n_dens) to use `NULL` with internal fallbacks. No change in user-facing behavior. * `ppc_ecdf_overlay()`, `ppc_ecdf_overlay_grouped()`, and `ppd_ecdf_overlay()` now always use `geom_step()`. The `discrete` argument is deprecated. * Fixed missing `drop = FALSE` in `nuts_params.CmdStanMCMC()`. * Replace `apply()` with `storage.mode()` for integer-to-numeric matrix conversion in `validate_predictions()`.