Skip to content

Commit

Permalink
Rename the seed parameter for loo_R2() and add docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcol committed Dec 17, 2024
1 parent 37b7c28 commit ce8694f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 5 additions & 3 deletions R/loo_predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ E_loo_value <- function(x, psis_object, type = "mean", probs = 0.5) {
#' @aliases loo_R2
#'
#' @inheritParams bayes_R2.brmsfit
#' @param seed Optional integer used to initialize the random number
#' generator.
#' @param ... Further arguments passed to
#' \code{\link[brms:posterior_epred.brmsfit]{posterior_epred}} and
#' \code{\link[brms:log_lik.brmsfit]{log_lik}},
Expand Down Expand Up @@ -214,7 +216,7 @@ E_loo_value <- function(x, psis_object, type = "mean", probs = 0.5) {
#' @export
loo_R2.brmsfit <- function(object, resp = NULL, summary = TRUE,
robust = FALSE, probs = c(0.025, 0.975),
brms_seed = NULL, ...) {
seed = NULL, ...) {
contains_draws(object)
object <- restructure(object)
resp <- validate_resp(resp, object)
Expand Down Expand Up @@ -242,12 +244,12 @@ loo_R2.brmsfit <- function(object, resp = NULL, summary = TRUE,
}

# set the random seed if required
if (!is.null(brms_seed)) {
if (!is.null(seed)) {
if (exists(".Random.seed", envir = .GlobalEnv)) {
rng_state_old <- get(".Random.seed", envir = .GlobalEnv)
on.exit(assign(".Random.seed", rng_state_old, envir = .GlobalEnv))
}
set.seed(brms_seed)
set.seed(seed)
}

args_y <- list(object, warn = TRUE, ...)
Expand Down
5 changes: 4 additions & 1 deletion man/loo_R2.brmsfit.Rd

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

0 comments on commit ce8694f

Please sign in to comment.