-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
function for rethinking style posterior list
- Loading branch information
1 parent
8df4553
commit 106cc38
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#' Extract samples (draws) from a fitted \code{coevfit} object | ||
#' | ||
#' @param object An object of class \code{coevfit} | ||
#' | ||
#' @return Samples in 'rethinking' style list format | ||
#' @export | ||
#' | ||
coev_extract_samples <- function(object) { | ||
# stop if object is not of class coevfit | ||
if (!methods::is(object, "coevfit")) { | ||
stop2( | ||
paste0( | ||
"Argument 'object' must be a fitted coevolutionary model ", | ||
"of class coevfit." | ||
) | ||
) | ||
} | ||
# stop if rethinking package not installed | ||
if (!requireNamespace("rethinking", quietly = TRUE)) { | ||
stop2( | ||
paste0( | ||
"'rethinking' package must be installed to use this function. See https://github.com/rmcelreath/rethinking" | ||
) | ||
) | ||
} | ||
vars <- object$fit$metadata()$stan_variables | ||
draws <- posterior::as_draws_rvars(object$fit$draws()) | ||
|
||
return(lapply(vars, \(var_name){ | ||
posterior::draws_of(draws[[var_name]], with_chains = FALSE) | ||
}) |> setNames(vars)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.