Skip to content

Commit 1061003

Browse files
authored
Merge pull request #538 from utkarshpawade/fix/131/density-defaults
Unify density-control argument defaults
2 parents fce2074 + f29887d commit 1061003

10 files changed

Lines changed: 64 additions & 46 deletions

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# bayesplot (development version)
22

3+
* Unified density-control argument defaults (`bw`, `adjust`, `kernel`, `n_dens`) to use `NULL` with internal fallbacks. No change in user-facing behavior.
34
* `prepare_mcmc_array()` now warns instead of erroring on `NA`s in the input.
45
* Fixed `validate_chain_list()` colnames check to compare all chains, not just the first two.
56
* Added test verifying `legend_move("none")` behaves equivalently to `legend_none()`.

R/ppc-distributions.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ ppc_dens_overlay <-
170170
size = 0.25,
171171
alpha = 0.7,
172172
trim = FALSE,
173-
bw = "nrd0",
174-
adjust = 1,
175-
kernel = "gaussian",
173+
bw = NULL,
174+
adjust = NULL,
175+
kernel = NULL,
176176
bounds = NULL,
177-
n_dens = 1024) {
177+
n_dens = NULL) {
178178
check_ignored_arguments(...)
179+
bw <- bw %||% "nrd0"
180+
adjust <- adjust %||% 1
181+
kernel <- kernel %||% "gaussian"
182+
n_dens <- n_dens %||% 1024
179183
bounds <- validate_density_bounds(bounds)
180184

181185
data <- ppc_data(y, yrep)
@@ -224,11 +228,11 @@ ppc_dens_overlay_grouped <- function(y,
224228
size = 0.25,
225229
alpha = 0.7,
226230
trim = FALSE,
227-
bw = "nrd0",
228-
adjust = 1,
229-
kernel = "gaussian",
231+
bw = NULL,
232+
adjust = NULL,
233+
kernel = NULL,
230234
bounds = NULL,
231-
n_dens = 1024) {
235+
n_dens = NULL) {
232236
check_ignored_arguments(...)
233237

234238
p_overlay <- ppc_dens_overlay(

R/ppc-loo.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,16 @@ ppc_loo_pit_overlay <- function(y,
181181
alpha = 0.7,
182182
boundary_correction = TRUE,
183183
grid_len = 512,
184-
bw = "nrd0",
184+
bw = NULL,
185185
trim = FALSE,
186-
adjust = 1,
187-
kernel = "gaussian",
188-
n_dens = 1024) {
186+
adjust = NULL,
187+
kernel = NULL,
188+
n_dens = NULL) {
189189
check_ignored_arguments(..., ok_args = list("moment_match"))
190+
bw <- bw %||% "nrd0"
191+
adjust <- adjust %||% 1
192+
kernel <- kernel %||% "gaussian"
193+
n_dens <- n_dens %||% 1024
190194

191195
data <-
192196
ppc_loo_pit_data(

R/ppd-distributions.R

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,23 @@ ppd_data <- function(ypred, group = NULL) {
3939
#' @rdname PPD-distributions
4040
#' @export
4141
ppd_dens_overlay <-
42-
function(ypred,
43-
show_marginal = FALSE,
44-
...,
45-
size = 0.25,
46-
alpha = 0.7,
47-
trim = FALSE,
48-
bw = "nrd0",
49-
adjust = 1,
50-
kernel = "gaussian",
51-
bounds = NULL,
52-
n_dens = 1024) {
53-
check_ignored_arguments(...)
54-
bounds <- validate_density_bounds(bounds)
42+
function(ypred,
43+
show_marginal = FALSE,
44+
...,
45+
size = 0.25,
46+
alpha = 0.7,
47+
trim = FALSE,
48+
bw = NULL,
49+
adjust = NULL,
50+
kernel = NULL,
51+
bounds = NULL,
52+
n_dens = NULL) {
53+
check_ignored_arguments(...)
54+
bw <- bw %||% "nrd0"
55+
adjust <- adjust %||% 1
56+
kernel <- kernel %||% "gaussian"
57+
n_dens <- n_dens %||% 1024
58+
bounds <- validate_density_bounds(bounds)
5559

5660
data <- ppd_data(ypred)
5761
p <- ggplot(data, mapping = aes(x = .data$value)) +
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#' @param bw,adjust,kernel,n_dens,bounds Optional arguments passed to
22
#' [stats::density()] (and `bounds` to [ggplot2::stat_density()]) to override
33
#' default kernel density estimation parameters or truncate the density
4-
#' support. `n_dens` defaults to `1024`.
4+
#' support. If `NULL` (default), `bw` is set to `"nrd0"`, `adjust` to `1`,
5+
#' `kernel` to `"gaussian"`, and `n_dens` to `1024`.

man/MCMC-distributions.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/MCMC-intervals.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-distributions.Rd

Lines changed: 10 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPC-loo.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/PPD-distributions.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)