Skip to content

Commit

Permalink
generic method consistency rhat
Browse files Browse the repository at this point in the history
  • Loading branch information
beckyfisher committed Mar 27, 2023
1 parent 3ab93e0 commit afb1057
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions R/rhat.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#'
#' Extract Rhat statistic that can be used to diagnose sampling behaviour
#' of the algorithms applied by 'Stan' at the back-end of 'brms'.
#' \code{object} should be of class
#' \code{x} should be of class
#' \code{\link{bayesnecfit}} or \code{\link{bayesmanecfit}}.
#'
#' @name rhat
#' @order 1
#'
#' @param object An object of class \code{\link{bayesnecfit}} or
#' @param x An object of class \code{\link{bayesnecfit}} or
#' \code{\link{bayesmanecfit}}.
#' @param rhat_cutoff A \code{\link[base]{numeric}} vector indicating the Rhat
#' cut-off used to test for model convergence.
Expand Down Expand Up @@ -38,14 +38,14 @@ NULL
#' @importFrom chk chk_numeric
#'
#' @export
rhat.bayesnecfit <- function(object, rhat_cutoff = 1.05, ...) {
rhat.bayesnecfit <- function(x, rhat_cutoff = 1.05, ...) {
chk_numeric(rhat_cutoff)
rhat_vals <- pull_brmsfit(object) |>
rhat_vals <- pull_brmsfit(x) |>
rhat() |>
clean_rhat_names()
failed <- any(rhat_vals > rhat_cutoff)
out <- list(list(rhat_vals = rhat_vals, failed = failed))
names(out) <- object$model
names(out) <- x$model
out
}

Expand All @@ -59,12 +59,12 @@ rhat.bayesnecfit <- function(object, rhat_cutoff = 1.05, ...) {
#' @importFrom brms rhat
#'
#' @export
rhat.bayesmanecfit <- function(object, rhat_cutoff = 1.05, ...) {
out <- sapply(object$success_models, function(x, object, ...) {
pull_out(object, model = x) |>
rhat.bayesmanecfit <- function(x, rhat_cutoff = 1.05, ...) {
out <- sapply(x$success_models, function(m, x, ...) {
pull_out(x, model = m) |>
suppressMessages() |>
rhat(...)
}, object = object, rhat_cutoff = rhat_cutoff, USE.NAMES = FALSE)
}, x = x, rhat_cutoff = rhat_cutoff, USE.NAMES = FALSE)
failed <- sapply(out, "[[", "failed")
if (all(failed)) {
message("All models failed the rhat_cutoff of ", rhat_cutoff)
Expand Down
8 changes: 4 additions & 4 deletions man/rhat.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit afb1057

Please sign in to comment.