|
1 | 1 | #' Generic function and default method for Bayesian R-squared
|
2 | 2 | #'
|
3 | 3 | #' Generic function and default method for Bayesian version of R-squared for
|
4 |
| -#' regression models. See \code{bayes_R2.stanreg} in the |
5 |
| -#' \pkg{\link[rstanarm]{rstanarm}} package for an example of defining a method. |
| 4 | +#' regression models. A generic for LOO-adjusted R-squared is also provided. See |
| 5 | +#' \code{bayes_R2.stanreg} in the \pkg{\link[rstanarm]{rstanarm}} package for an |
| 6 | +#' example of defining a method. |
6 | 7 | #'
|
7 | 8 | #' @export
|
8 | 9 | #' @template args-object
|
9 | 10 | #' @template args-dots
|
10 | 11 | #'
|
11 |
| -#' @return \code{bayes_R2} methods should return a vector of length equal to the |
12 |
| -#' posterior sample size. |
| 12 | +#' @return \code{bayes_R2} and \code{loo_R2} methods should return a vector of |
| 13 | +#' length equal to the posterior sample size. |
13 | 14 | #'
|
14 |
| -#' The default method just takes \code{object} to be a matrix of y-hat values |
| 15 | +#' The default \code{bayes_R2} method just takes \code{object} to be a matrix of y-hat values |
15 | 16 | #' (one column per observation, one row per posterior draw) and \code{y} to be
|
16 | 17 | #' a vector with length equal to \code{ncol(object)}.
|
17 | 18 | #'
|
| 19 | +#' |
| 20 | +#' @references |
| 21 | +#' Andrew Gelman, Ben Goodrich, Jonah Gabry, and Aki Vehtari (2018). R-squared |
| 22 | +#' for Bayesian regression models. \emph{The American Statistician}, to appear. |
| 23 | +#' \href{http://www.stat.columbia.edu/~gelman/research/published/bayes_R2_v3.pdf}{Preprint}, |
| 24 | +#' \href{https://avehtari.github.io/bayes_R2/bayes_R2.html}{Notebook}. |
| 25 | +#' |
| 26 | +#' |
18 | 27 | #' @template seealso-rstanarm-pkg
|
19 | 28 | #' @template seealso-dev-guidelines
|
20 | 29 | #'
|
@@ -42,3 +51,9 @@ bayes_R2.default <-
|
42 | 51 | var_ypred / (var_ypred + var_e)
|
43 | 52 | }
|
44 | 53 |
|
| 54 | + |
| 55 | +#' @rdname bayes_R2 |
| 56 | +#' @export |
| 57 | +loo_R2 <- function(object, ...) { |
| 58 | + UseMethod("loo_R2") |
| 59 | +} |
0 commit comments