Skip to content

Commit 47b573e

Browse files
committed
Make diagnostic color matching explicit for neff
1 parent 306c92e commit 47b573e

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* New functions `mcmc_dots` and `mcmc_dots_by_chain` for dot plots of MCMC draws by @behramulukir (#402)
44
* Default to `quantiles=100` for all dot plots by @behramulukir (#402)
5+
* Make diagnostic color scale helpers handle `"neff"` and `"neff_ratio"` explicitly, avoiding reliance on partial matching.
56

67
# bayesplot 1.15.0
78

R/mcmc-diagnostics.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,10 @@ scale_fill_diagnostic <- function(diagnostic = c("rhat", "neff")) {
429429

430430
diagnostic_color_scale <- function(diagnostic = c("rhat", "neff_ratio"),
431431
aesthetic = c("color", "fill")) {
432-
diagnostic <- match.arg(diagnostic)
432+
diagnostic <- match.arg(diagnostic, choices = c("rhat", "neff", "neff_ratio"))
433+
if (diagnostic == "neff") {
434+
diagnostic <- "neff_ratio"
435+
}
433436
aesthetic <- match.arg(aesthetic)
434437
dc <- diagnostic_colors(diagnostic, aesthetic)
435438
do.call(
@@ -445,7 +448,10 @@ diagnostic_color_scale <- function(diagnostic = c("rhat", "neff_ratio"),
445448

446449
diagnostic_colors <- function(diagnostic = c("rhat", "neff_ratio"),
447450
aesthetic = c("color", "fill")) {
448-
diagnostic <- match.arg(diagnostic)
451+
diagnostic <- match.arg(diagnostic, choices = c("rhat", "neff", "neff_ratio"))
452+
if (diagnostic == "neff") {
453+
diagnostic <- "neff_ratio"
454+
}
449455
aesthetic <- match.arg(aesthetic)
450456
color_levels <- c("light", "mid", "dark")
451457
if (diagnostic == "neff_ratio") {

tests/testthat/test-mcmc-diagnostics.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ 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+
expect_no_error(scale_color_diagnostic("neff"))
84+
expect_no_error(scale_fill_diagnostic("neff"))
85+
expect_no_error(diagnostic_color_scale("neff", aesthetic = "color"))
86+
expect_no_error(diagnostic_color_scale("neff_ratio", aesthetic = "color"))
87+
})
88+
8289
test_that("mcmc_acf & mcmc_acf_bar return a ggplot object", {
8390
expect_gg(mcmc_acf(arr, pars = "beta[1]", regex_pars = "x\\:[2,5]"))
8491
expect_gg(mcmc_acf_bar(arr, pars = "beta[1]", regex_pars = "x\\:[2,5]"))

0 commit comments

Comments
 (0)