Skip to content

Commit

Permalink
Make extract_samples a method of coevfit
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikRingen committed Aug 7, 2024
1 parent 106cc38 commit fd0e063
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ URL: https://github.com/ScottClaessens/coevolve
BugReports: https://github.com/ScottClaessens/coevolve/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
knitr,
rmarkdown,
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Generated by roxygen2: do not edit by hand

S3method(extract_samples,coevfit)
S3method(print,coevfit)
S3method(print,coevsummary)
S3method(summary,coevfit)
export(coev_calculate_delta_theta)
export(coev_calculate_theta)
export(coev_extract_samples)
export(coev_fit)
export(coev_make_stancode)
export(coev_make_standata)
Expand All @@ -14,4 +14,5 @@ export(coev_plot_flowfield)
export(coev_plot_predictive_check)
export(coev_plot_selection_gradient)
export(coev_simulate_coevolution)
export(extract_samples)
importFrom(rlang,.data)
32 changes: 0 additions & 32 deletions R/coev_extract_samples.R

This file was deleted.

19 changes: 19 additions & 0 deletions R/extract_samples.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#' 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
extract_samples <- function(object) {
UseMethod("extract_samples")
}

#' @export
extract_samples.coevfit <- function(object) {
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))
}
8 changes: 4 additions & 4 deletions man/coev_extract_samples.Rd → man/extract_samples.Rd

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

0 comments on commit fd0e063

Please sign in to comment.