Skip to content

Commit 6c1e4e3

Browse files
committed
Simplify diagnostic scale naming to neff_ratio
1 parent 6144672 commit 6c1e4e3

3 files changed

Lines changed: 13 additions & 39 deletions

File tree

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Fixed test in `test-ppc-distributions.R` that incorrectly used `ppc_dens()` instead of `ppd_dens()` when testing PPD functions
1111
* New functions `mcmc_dots` and `mcmc_dots_by_chain` for dot plots of MCMC draws by @behramulukir (#402)
1212
* Default to `quantiles=100` for all dot plots by @behramulukir (#402)
13-
* Make diagnostic color scale helpers handle `"neff"` and `"neff_ratio"` explicitly, avoiding reliance on partial matching.
13+
* Use `"neff_ratio"` consistently in diagnostic color scale helpers to avoid relying on partial matching of `"neff"`.
1414

1515
# bayesplot 1.15.0
1616

R/mcmc-diagnostics.R

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ mcmc_neff <- function(ratio, ..., size = NULL) {
255255
linetype = 2,
256256
linewidth = 0.25) +
257257
labs(y = NULL, x = expression(N[eff]/N)) +
258-
scale_fill_diagnostic("neff") +
259-
scale_color_diagnostic("neff") +
258+
scale_fill_diagnostic("neff_ratio") +
259+
scale_color_diagnostic("neff_ratio") +
260260
scale_x_continuous(
261261
breaks = breaks,
262262
# as.character truncates trailing zeroes, while ggplot default does not
@@ -287,8 +287,8 @@ mcmc_neff_hist <- function(ratio, ..., binwidth = NULL, bins = NULL, breaks = NU
287287
binwidth = binwidth,
288288
bins = bins,
289289
breaks = breaks) +
290-
scale_color_diagnostic("neff") +
291-
scale_fill_diagnostic("neff") +
290+
scale_color_diagnostic("neff_ratio") +
291+
scale_fill_diagnostic("neff_ratio") +
292292
labs(x = expression(N[eff]/N), y = NULL) +
293293
dont_expand_y_axis(c(0.005, 0)) +
294294
yaxis_title(FALSE) +
@@ -424,27 +424,19 @@ diagnostic_points <- function(size = NULL) {
424424

425425
# Functions wrapping around scale_color_manual() and scale_fill_manual(), used to
426426
# color the intervals by rhat value
427-
scale_color_diagnostic <- function(diagnostic = c("rhat", "neff")) {
428-
d <- match.arg(diagnostic, choices = c("rhat", "neff", "neff_ratio"))
427+
scale_color_diagnostic <- function(diagnostic = c("rhat", "neff_ratio")) {
428+
d <- match.arg(diagnostic)
429429
diagnostic_color_scale(d, aesthetic = "color")
430430
}
431431

432-
scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff")) {
433-
d <- match.arg(diagnostic, choices = c("rhat", "neff", "neff_ratio"))
432+
scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff_ratio")) {
433+
d <- match.arg(diagnostic)
434434
diagnostic_color_scale(d, aesthetic = "fill")
435435
}
436436

437-
normalize_diagnostic_name <- function(diagnostic) {
438-
diagnostic <- match.arg(diagnostic, choices = c("rhat", "neff", "neff_ratio"))
439-
if (diagnostic == "neff") {
440-
diagnostic <- "neff_ratio"
441-
}
442-
diagnostic
443-
}
444-
445437
diagnostic_color_scale <- function(diagnostic = c("rhat", "neff_ratio"),
446438
aesthetic = c("color", "fill")) {
447-
diagnostic <- normalize_diagnostic_name(diagnostic)
439+
diagnostic <- match.arg(diagnostic)
448440
aesthetic <- match.arg(aesthetic)
449441
dc <- diagnostic_colors(diagnostic, aesthetic)
450442
do.call(
@@ -460,7 +452,7 @@ diagnostic_color_scale <- function(diagnostic = c("rhat", "neff_ratio"),
460452

461453
diagnostic_colors <- function(diagnostic = c("rhat", "neff_ratio"),
462454
aesthetic = c("color", "fill")) {
463-
diagnostic <- normalize_diagnostic_name(diagnostic)
455+
diagnostic <- match.arg(diagnostic)
464456
aesthetic <- match.arg(aesthetic)
465457
color_levels <- c("light", "mid", "dark")
466458
if (diagnostic == "neff_ratio") {

tests/testthat/test-mcmc-diagnostics.R

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,28 +79,10 @@ test_that("'description' & 'rating' columns are correct (#176)", {
7979
expect_equal(df$description, expected_descriptions)
8080
})
8181

82-
test_that("diagnostic color helpers handle neff names explicitly", {
83-
# wrappers accept both aliases
84-
expect_no_error(scale_color_diagnostic("neff"))
85-
expect_no_error(scale_fill_diagnostic("neff"))
82+
test_that("diagnostic color helpers use neff_ratio consistently", {
8683
expect_no_error(scale_color_diagnostic("neff_ratio"))
8784
expect_no_error(scale_fill_diagnostic("neff_ratio"))
88-
89-
# aliases map to equivalent scales
90-
color_neff <- scale_color_diagnostic("neff")
91-
color_neff_ratio <- scale_color_diagnostic("neff_ratio")
92-
expect_equal(color_neff$palette(3), color_neff_ratio$palette(3))
93-
expect_equal(color_neff$labels, color_neff_ratio$labels)
94-
95-
fill_neff <- scale_fill_diagnostic("neff")
96-
fill_neff_ratio <- scale_fill_diagnostic("neff_ratio")
97-
expect_equal(fill_neff$palette(3), fill_neff_ratio$palette(3))
98-
expect_equal(fill_neff$labels, fill_neff_ratio$labels)
99-
100-
base_neff <- diagnostic_color_scale("neff", aesthetic = "color")
101-
base_neff_ratio <- diagnostic_color_scale("neff_ratio", aesthetic = "color")
102-
expect_equal(base_neff$palette(3), base_neff_ratio$palette(3))
103-
expect_equal(base_neff$labels, base_neff_ratio$labels)
85+
expect_no_error(diagnostic_color_scale("neff_ratio", aesthetic = "color"))
10486
})
10587

10688
test_that("mcmc_acf & mcmc_acf_bar return a ggplot object", {

0 commit comments

Comments
 (0)