Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix glance() for brmsfit #146

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 2 additions & 6 deletions R/brms_tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,9 @@ tidy.brmsfit <- function(x, parameters = NA,
#' @importFrom stats quantile
#' @export
sigma.brmsfit <- function (object, ...) {
if (!("sigma" %in% names(object$fit)))
if (!("sigma" %in% brms::variables(object)))
return(1)
if (!requireNamespace("rstanarm")) {
warning("need to install rstanarm to use extract sigma from brms fits")
return(NA)
}
stats::quantile(as.data.frame(object$fit)[["sigma"]], probs=0.5)
stats::quantile(brms::as_draws_array(object, "sigma"), probs=0.5)
}

#' @rdname brms_tidiers
Expand Down
6 changes: 3 additions & 3 deletions R/rstanarm_tidiers.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ glance_stan <- function(x, looic = FALSE, ..., type) {

if (algo != "optimizing") {
pss <- sim$n_save
if (algo == "sampling") {
pss <- sum(pss - sim$warmup2)
if (algo %in% c("sample", "sampling")) {
pss <- pss - sim$warmup2
}
ret <- dplyr::mutate(ret, pss = pss)
ret <- dplyr::mutate(ret, pss = sum(pss))
}

ret <- mutate(ret, nobs = stats::nobs(x))
Expand Down
Loading