Skip to content

Commit

Permalink
format docs
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jul 8, 2024
1 parent 88f84d4 commit 06ed6f1
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
15 changes: 8 additions & 7 deletions R/r2.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
#' - Mixed models: [Nakagawa's R2][r2_nakagawa]
#' - Bayesian models: [R2 bayes][r2_bayes]
#'
#' @note If there is no `r2()`-method defined for the given model class,
#' `r2()` tries to return a "generic" r-quared value, calculated as following:
#' `1-sum((y-y_hat)^2)/sum((y-y_bar)^2))`
#' @note
#' If there is no `r2()`-method defined for the given model class, `r2()` tries
#' to return a "generic" r-quared value, calculated as following:
#' `1-sum((y-y_hat)^2)/sum((y-y_bar)^2)`
#'
#' @seealso [`r2_bayes()`], [`r2_coxsnell()`], [`r2_kullback()`],
#' [`r2_loo()`], [`r2_mcfadden()`], [`r2_nagelkerke()`],
#' [`r2_nakagawa()`], [`r2_tjur()`], [`r2_xu()`] and
#' [`r2_zeroinflated()`].
#' @seealso
#' [`r2_bayes()`], [`r2_coxsnell()`], [`r2_kullback()`], [`r2_loo()`],
#' [`r2_mcfadden()`], [`r2_nagelkerke()`], [`r2_nakagawa()`], [`r2_tjur()`],
#' [`r2_xu()`] and [`r2_zeroinflated()`].
#'
#' @examplesIf require("lme4")
#' # Pseudo r-quared for GLM
Expand Down
39 changes: 20 additions & 19 deletions R/r2_bayes.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
#' @title Bayesian R2
#' @name r2_bayes
#'
#' @description Compute R2 for Bayesian models. For mixed models (including a
#' random part), it additionally computes the R2 related to the fixed effects
#' only (marginal R2). While `r2_bayes()` returns a single R2 value,
#' `r2_posterior()` returns a posterior sample of Bayesian R2 values.
#' @description
#' Compute R2 for Bayesian models. For mixed models (including a random part),
#' it additionally computes the R2 related to the fixed effects only (marginal
#' R2). While `r2_bayes()` returns a single R2 value, `r2_posterior()` returns a
#' posterior sample of Bayesian R2 values.
#'
#' @param model A Bayesian regression model (from **brms**,
#' **rstanarm**, **BayesFactor**, etc).
#' **rstanarm**, **BayesFactor**, etc).
#' @param robust Logical, if `TRUE`, the median instead of mean is used to
#' calculate the central tendency of the variances.
#' calculate the central tendency of the variances.
#' @param ci Value or vector of probability of the CI (between 0 and 1) to be
#' estimated.
#' estimated.
#' @param ... Arguments passed to `r2_posterior()`.
#' @inheritParams model_performance.lm
#'
#' @return A list with the Bayesian R2 value. For mixed models, a list with the
#' Bayesian R2 value and the marginal Bayesian R2 value. The standard errors
#' and credible intervals for the R2 values are saved as attributes.
#' Bayesian R2 value and the marginal Bayesian R2 value. The standard errors and
#' credible intervals for the R2 values are saved as attributes.
#'
#' @details `r2_bayes()` returns an "unadjusted" R2 value. See
#' [r2_loo()] to calculate a LOO-adjusted R2, which comes
#' conceptually closer to an adjusted R2 measure.
#' @details
#' `r2_bayes()` returns an "unadjusted" R2 value. See [r2_loo()] to calculate a
#' LOO-adjusted R2, which comes conceptually closer to an adjusted R2 measure.
#'
#' For mixed models, the conditional and marginal R2 are returned. The marginal
#' R2 considers only the variance of the fixed effects, while the conditional
#' R2 takes both the fixed and random effects into account.
#' For mixed models, the conditional and marginal R2 are returned. The marginal
#' R2 considers only the variance of the fixed effects, while the conditional R2
#' takes both the fixed and random effects into account.
#'
#' `r2_posterior()` is the actual workhorse for `r2_bayes()` and
#' returns a posterior sample of Bayesian R2 values.
#' `r2_posterior()` is the actual workhorse for `r2_bayes()` and returns a
#' posterior sample of Bayesian R2 values.
#'
#' @examplesIf require("rstanarm") && require("rstantools") && require("brms")
#' library(performance)
Expand Down Expand Up @@ -71,8 +72,8 @@
#' r2_bayes(model)
#' }
#' @references
#' Gelman, A., Goodrich, B., Gabry, J., and Vehtari, A. (2018).
#' R-squared for Bayesian regression models. The American Statistician, 1–6.
#' Gelman, A., Goodrich, B., Gabry, J., and Vehtari, A. (2018). R-squared for
#' Bayesian regression models. The American Statistician, 1–6.
#' \doi{10.1080/00031305.2018.1549100}
#' @export
r2_bayes <- function(model, robust = TRUE, ci = 0.95, verbose = TRUE, ...) {
Expand Down
13 changes: 6 additions & 7 deletions man/r2.Rd

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

29 changes: 14 additions & 15 deletions man/r2_bayes.Rd

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

0 comments on commit 06ed6f1

Please sign in to comment.