Skip to content

Commit

Permalink
examples
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 29, 2023
1 parent ca62b91 commit 8a19dce
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 103 deletions.
2 changes: 2 additions & 0 deletions R/looic.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#' @return A list with four elements, the ELPD, LOOIC and their standard errors.
#'
#' @examplesIf require("rstanarm")
#' \donttest{
#' model <- suppressWarnings(rstanarm::stan_glm(
#' mpg ~ wt + cyl,
#' data = mtcars,
Expand All @@ -20,6 +21,7 @@
#' refresh = 0
#' ))
#' looic(model)
#' }
#' @export
looic <- function(model, verbose = TRUE) {
insight::check_if_installed("loo")
Expand Down
98 changes: 47 additions & 51 deletions R/r2_bayes.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,63 @@
#' `r2_posterior()` is the actual workhorse for `r2_bayes()` and
#' returns a posterior sample of Bayesian R2 values.
#'
#' @examples
#' @examplesIf require("rstanarm") && require("rstantools") && require("BayesFactor") && require("brms")
#' library(performance)
#' if (require("rstanarm") && require("rstantools")) {
#' model <- suppressWarnings(stan_glm(
#' mpg ~ wt + cyl,
#' data = mtcars,
#' chains = 1,
#' iter = 500,
#' refresh = 0,
#' show_messages = FALSE
#' ))
#' r2_bayes(model)
#' \donttest{
#' model <- suppressWarnings(rstanarm::stan_glm(
#' mpg ~ wt + cyl,
#' data = mtcars,
#' chains = 1,
#' iter = 500,
#' refresh = 0,
#' show_messages = FALSE
#' ))
#' r2_bayes(model)
#'
#' model <- suppressWarnings(stan_lmer(
#' Petal.Length ~ Petal.Width + (1 | Species),
#' data = iris,
#' chains = 1,
#' iter = 500,
#' refresh = 0
#' ))
#' r2_bayes(model)
#' model <- suppressWarnings(rstanarm::stan_lmer(
#' Petal.Length ~ Petal.Width + (1 | Species),
#' data = iris,
#' chains = 1,
#' iter = 500,
#' refresh = 0
#' ))
#' r2_bayes(model)
#' }
#'
#' if (require("BayesFactor")) {
#' BFM <- generalTestBF(mpg ~ qsec + gear, data = mtcars, progress = FALSE)
#' FM <- lmBF(mpg ~ qsec + gear, data = mtcars)
#' BFM <- BayesFactor::generalTestBF(mpg ~ qsec + gear, data = mtcars, progress = FALSE)
#' FM <- BayesFactor::lmBF(mpg ~ qsec + gear, data = mtcars)
#'
#' r2_bayes(FM)
#' r2_bayes(BFM[3])
#' r2_bayes(BFM, average = TRUE) # across all models
#' r2_bayes(FM)
#' r2_bayes(BFM[3])
#' r2_bayes(BFM, average = TRUE) # across all models
#'
#' # with random effects:
#' mtcars$gear <- factor(mtcars$gear)
#' model <- lmBF(
#' mpg ~ hp + cyl + gear + gear:wt,
#' mtcars,
#' progress = FALSE,
#' whichRandom = c("gear", "gear:wt")
#' )
#' # with random effects:
#' mtcars$gear <- factor(mtcars$gear)
#' model <- BayesFactor::lmBF(
#' mpg ~ hp + cyl + gear + gear:wt,
#' mtcars,
#' progress = FALSE,
#' whichRandom = c("gear", "gear:wt")
#' )
#'
#' r2_bayes(model)
#' }
#' r2_bayes(model)
#'
#' \donttest{
#' if (require("brms")) {
#' model <- suppressWarnings(brms::brm(
#' mpg ~ wt + cyl,
#' data = mtcars,
#' silent = 2,
#' refresh = 0
#' ))
#' r2_bayes(model)
#' model <- suppressWarnings(brms::brm(
#' mpg ~ wt + cyl,
#' data = mtcars,
#' silent = 2,
#' refresh = 0
#' ))
#' r2_bayes(model)
#'
#' model <- suppressWarnings(brms::brm(
#' Petal.Length ~ Petal.Width + (1 | Species),
#' data = iris,
#' silent = 2,
#' refresh = 0
#' ))
#' r2_bayes(model)
#' }
#' model <- suppressWarnings(brms::brm(
#' Petal.Length ~ Petal.Width + (1 | Species),
#' data = iris,
#' silent = 2,
#' refresh = 0
#' ))
#' r2_bayes(model)
#' }
#' @references
#' Gelman, A., Goodrich, B., Gabry, J., and Vehtari, A. (2018).
Expand Down
2 changes: 2 additions & 0 deletions man/looic.Rd

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

102 changes: 50 additions & 52 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 8a19dce

Please sign in to comment.