Skip to content

Commit

Permalink
summary: don't show misleading convergence diagnostics for brm_multip…
Browse files Browse the repository at this point in the history
…le models
  • Loading branch information
paul-buerkner committed Oct 1, 2024
1 parent c6def16 commit d978f47
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions R/summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,15 @@ summary.brmsfit <- function(object, priors = FALSE, prob = 0.95,
}
measures$Est.Error <- sd
}
c(measures) <- list(
quantiles = .quantile,
Rhat = posterior::rhat,
Bulk_ESS = posterior::ess_bulk,
Tail_ESS = posterior::ess_tail
)
c(measures) <- list(quantiles = .quantile)
if (!is.brmsfit_multiple(object)) {
# TODO: add a viable post-processing solution for brm_multiple models
c(measures) <- list(
Rhat = posterior::rhat,
Bulk_ESS = posterior::ess_bulk,
Tail_ESS = posterior::ess_tail
)
}
out <- do.call(summarize_draws, c(list(draws), measures))
out <- as.data.frame(out)
rownames(out) <- out$variable
Expand All @@ -119,15 +122,9 @@ summary.brmsfit <- function(object, priors = FALSE, prob = 0.95,
}

full_summary <- .summary(draws, variables, probs, robust)
out$has_rhat <- "Rhat" %in% colnames(full_summary)
if (algorithm(object) == "sampling") {
if (is.brmsfit_multiple(object)) {
# TODO: replace with a viable post-processing solution
warning2(
"The displayed Rhat and ESS estimates should not be trusted for ",
"brm_multiple models. Please see ?brm_multiple for how ",
"to assess convergence of such models."
)
} else {
if (out$has_rhat) {
Rhats <- full_summary[, "Rhat"]
if (any(Rhats > 1.05, na.rm = TRUE)) {
warning2(
Expand Down Expand Up @@ -328,13 +325,21 @@ print.brmssummary <- function(x, digits = 2, ...) {
if (!short) {
cat(paste0("Draws were sampled using ", x$sampler, ". "))
if (x$algorithm == "sampling") {
cat(paste0(
"For each parameter, Bulk_ESS\n",
"and Tail_ESS are effective sample size measures, ",
"and Rhat is the potential\n",
"scale reduction factor on split chains ",
"(at convergence, Rhat = 1)."
))
if (isTRUE(x$has_rhat)) {
cat(paste0(
"For each parameter, Bulk_ESS\n",
"and Tail_ESS are effective sample size measures, ",
"and Rhat is the potential\n",
"scale reduction factor on split chains ",
"(at convergence, Rhat = 1)."
))
} else {
cat(paste0(
"Standard Rhat and ESS estimates\n",
"should not be trusted for brm_multiple models and are hence not displayed.\n",
"Please see ?brm_multiple for how to assess convergence of such models."
))
}
}
cat("\n")
}
Expand Down

0 comments on commit d978f47

Please sign in to comment.