diff --git a/R/r2_bayes.R b/R/r2_bayes.R index cbdec33d5..1db20f827 100644 --- a/R/r2_bayes.R +++ b/R/r2_bayes.R @@ -33,7 +33,9 @@ #' @examples #' library(performance) #' if (require("rstanarm") && require("rstantools")) { -#' model <- stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) +#' model <- suppressWarnings( +#' stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) +#' ) #' r2_bayes(model) #' #' model <- stan_lmer( @@ -424,10 +426,10 @@ as.data.frame.r2_bayes <- function(x, ...) { residuals.BFBayesFactor <- function(object, ...) { everything_we_need <- .get_bfbf_predictions(object, verbose = FALSE) - everything_we_need[["y"]] - apply(everything_we_need[["y_pred"]], 2, mean) + everything_we_need[["y"]] - colMeans(everything_we_need[["y_pred"]]) } #' @export fitted.BFBayesFactor <- function(object, ...) { - apply(.get_bfbf_predictions(object, verbose = FALSE)[["y_pred"]], 2, mean) + colMeans(.get_bfbf_predictions(object, verbose = FALSE)[["y_pred"]]) } diff --git a/R/r2_loo.R b/R/r2_loo.R index 1460d21d9..c62d39c25 100644 --- a/R/r2_loo.R +++ b/R/r2_loo.R @@ -20,9 +20,9 @@ #' leave-one-out-adjusted posterior distribution. This is conceptually similar #' to an adjusted/unbiased R2 estimate in classical regression modeling. See #' [r2_bayes()] for an "unadjusted" R2. -#' \cr \cr +#' #' Mixed models are not currently fully supported. -#' \cr \cr +#' #' `r2_loo_posterior()` is the actual workhorse for `r2_loo()` and #' returns a posterior sample of LOO-adjusted Bayesian R2 values. #' @@ -31,7 +31,9 @@ #' #' @examples #' if (require("rstanarm")) { -#' model <- stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) +#' model <- suppressWarnings( +#' stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) +#' ) #' r2_loo(model) #' } #' @export diff --git a/man/r2_bayes.Rd b/man/r2_bayes.Rd index 9f1531225..298792930 100644 --- a/man/r2_bayes.Rd +++ b/man/r2_bayes.Rd @@ -64,7 +64,9 @@ returns a posterior sample of Bayesian R2 values. \examples{ library(performance) if (require("rstanarm") && require("rstantools")) { - model <- stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) + model <- suppressWarnings( + stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) + ) r2_bayes(model) model <- stan_lmer( diff --git a/man/r2_loo.Rd b/man/r2_loo.Rd index 18d8b106e..cd28fb483 100644 --- a/man/r2_loo.Rd +++ b/man/r2_loo.Rd @@ -45,15 +45,17 @@ Compute LOO-adjusted R2. leave-one-out-adjusted posterior distribution. This is conceptually similar to an adjusted/unbiased R2 estimate in classical regression modeling. See \code{\link[=r2_bayes]{r2_bayes()}} for an "unadjusted" R2. -\cr \cr + Mixed models are not currently fully supported. -\cr \cr + \code{r2_loo_posterior()} is the actual workhorse for \code{r2_loo()} and returns a posterior sample of LOO-adjusted Bayesian R2 values. } \examples{ if (require("rstanarm")) { - model <- stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) + model <- suppressWarnings( + stan_glm(mpg ~ wt + cyl, data = mtcars, chains = 1, iter = 500, refresh = 0) + ) r2_loo(model) } }