Skip to content

Commit 8dc1dc9

Browse files
authored
Merge branch 'master' into docs/data-functions-vignette-435
2 parents cc7f64f + 617650b commit 8dc1dc9

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

NEWS.md

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

33
* Added vignette sections demonstrating `*_data()` companion functions for building custom ggplot2 visualizations (#435)
4+
* Extract `drop_singleton_values()` helper in `mcmc_nuts_treedepth()` to remove duplicated filtering logic.
45
* Eliminate redundant data processing in `mcmc_areas_data()` by reusing the prepared MCMC array for both interval and density computation.
56
* Validate equal chain lengths in `validate_df_with_chain()`, reject missing chain labels, and renumber data-frame chain labels internally when converting to arrays.
67
* Added unit tests for previously untested edge cases in `param_range()`, `param_glue()`, and `tidyselect_parameters()` (no-match, partial-match, and negation behavior).

R/mcmc-diagnostics-nuts.R

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,7 @@ mcmc_nuts_treedepth <- function(x, lp, chain = NULL, ...) {
369369
yaxis_ticks(FALSE)
370370

371371
violin_lp_data <- data.frame(treedepth, lp = lp$Value)
372-
373-
# Only keep treedepth values that occur more than once for violin plot
374-
value_counts <- table(violin_lp_data$Value)
375-
keep_values <- names(value_counts[value_counts > 1])
376-
violin_lp_data <- violin_lp_data[violin_lp_data$Value %in% keep_values, ]
372+
violin_lp_data <- drop_singleton_values(violin_lp_data, "Value")
377373

378374
violin_lp <-
379375
ggplot(violin_lp_data, aes(x = factor(.data$Value), y = .data$lp)) +
@@ -382,11 +378,7 @@ mcmc_nuts_treedepth <- function(x, lp, chain = NULL, ...) {
382378
bayesplot_theme_get()
383379

384380
violin_accept_stat_data <- data.frame(treedepth, as = accept_stat$Value)
385-
386-
# Only keep treedepth values that occur more than once for violin plot
387-
value_counts <- table(violin_accept_stat_data$Value)
388-
keep_values <- names(value_counts[value_counts > 1])
389-
violin_accept_stat_data <- violin_accept_stat_data[violin_accept_stat_data$Value %in% keep_values, ]
381+
violin_accept_stat_data <- drop_singleton_values(violin_accept_stat_data, "Value")
390382

391383
violin_accept_stat <-
392384
ggplot(violin_accept_stat_data, aes(x = factor(.data$Value), y = .data$as)) +
@@ -572,3 +564,11 @@ chain_violin <-
572564
alpha = alpha
573565
)
574566
}
567+
568+
# Drop rows whose value in `col` appears only once (singletons cannot
569+
# produce a violin density estimate).
570+
drop_singleton_values <- function(df, col) {
571+
counts <- table(df[[col]])
572+
keep <- names(counts[counts > 1])
573+
df[df[[col]] %in% keep, ]
574+
}

0 commit comments

Comments
 (0)