Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

bayes_R2

Generic function and default method for Bayesian R-squared


Description

Generic function and default method for Bayesian version of R-squared for regression models. A generic for LOO-adjusted R-squared is also provided. See the bayes_R2.stanreg() method in the rstanarm package for an example of defining a method.

Usage

bayes_R2(object, ...)

## Default S3 method:
bayes_R2(object, y, ...)

loo_R2(object, ...)

Arguments

object

The object to use.

...

Arguments passed to methods. See the methods in the rstanarm package for examples.

y

For the default method, a vector of y values the same length as the number of columns in the matrix used as object.

Value

bayes_R2() and loo_R2() methods should return a vector of length equal to the posterior sample size.

The default bayes_R2() method just takes object to be a matrix of y-hat values (one column per observation, one row per posterior draw) and y to be a vector with length equal to ncol(object).

References

Andrew Gelman, Ben Goodrich, Jonah Gabry, and Aki Vehtari (2018). R-squared for Bayesian regression models. The American Statistician, to appear. DOI: 10.1080/00031305.2018.1549100. (Preprint, Notebook)

See Also

  • Guidelines and recommendations for developers of R packages interfacing with Stan and a demonstration getting a simple package working can be found in the vignettes included with rstantools and at mc-stan.org/rstantools/articles.


rstantools

Tools for Developing R Packages Interfacing with 'Stan'

v2.1.1
GPL (>= 3)
Authors
Jonah Gabry [aut, cre], Ben Goodrich [aut], Martin Lysy [aut], Stefan Siegert [ctb], Trustees of Columbia University [cph]
Initial release
2020-07-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.