Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bayesplot (development version)


* Fixed `validate_chain_list()` colnames check to compare all chains, not just the first two.
* New `show_marginal` argument to `ppd_*()` functions to show the PPD - the marginal predictive distribution by @mattansb (#425)
* `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()`.
Expand Down
8 changes: 2 additions & 6 deletions R/helpers-mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,8 @@ validate_chain_list <- function(x) {
abort("Each chain should have the same number of iterations.")
}

cnames <- sapply(x, colnames)
if (is.array(cnames)) {
same_params <- identical(cnames[, 1], cnames[, 2])
} else {
same_params <- length(unique(cnames)) == 1
}
cnames <- lapply(x, colnames)
same_params <- all(vapply(cnames[-1], identical, logical(1), cnames[[1]]))
Comment thread
utkarshpawade marked this conversation as resolved.
if (!same_params) {
abort(paste(
"The parameters for each chain should be in the same order",
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-helpers-mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ test_that("validate_chain_list works", {
"Each chain should have the same number of iterations")
})

test_that("validate_chain_list detects colnames mismatch in chain 3+", {
ch <- matrix(rnorm(20), nrow = 2, dimnames = list(NULL, c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j")))
chain3_bad <- ch
colnames(chain3_bad)[1] <- "z"
chains_ok <- list(ch, ch, ch)
chains_bad <- list(ch, ch, chain3_bad)

expect_identical(validate_chain_list(chains_ok), chains_ok)
expect_error(validate_chain_list(chains_bad), "parameters for each chain")
})

test_that("chain_list2array works", {
expect_mcmc_array(chain_list2array(chainlist))
expect_mcmc_array(chain_list2array(chainlist1))
Expand Down
Loading