Skip to content

Commit

Permalink
Expose quantiles for summarization
Browse files Browse the repository at this point in the history
  • Loading branch information
zsusswein committed Oct 8, 2024
1 parent c80c8cf commit b8c352e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions R/write_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ post_process_and_merge <- function(
#'
#' @param fit An EpiNow2 fit object with posterior estimates.
#' @param disease,geo_value,model Metadata for downstream processing.
#' @param quantiles A vector of quantiles to base to [tidybayes::median_qi()]
#'
#' @return A data.table of posterior draws or quantiles, merged and processed.
#'
Expand All @@ -265,7 +266,12 @@ process_samples <- function(fit, geo_value, model, disease) {

#' @rdname sample_processing_functions
#' @export
process_quantiles <- function(fit, geo_value, model, disease) {
process_quantiles <- function(
fit,
geo_value,
model,
disease,
quantiles) {
# Step 1: Extract the draws
draws_list <- extract_draws_from_fit(fit)

Expand All @@ -274,7 +280,7 @@ process_quantiles <- function(fit, geo_value, model, disease) {
summarized_draws <- draws_list$stan_draws |>
dplyr::group_by(.variable, time) |>
tidybayes::median_qi(
.width = c(0.5, 0.95),
.width = quantiles,
) |>
data.table::as.data.table()

Expand Down
4 changes: 3 additions & 1 deletion man/sample_processing_functions.Rd

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

8 changes: 7 additions & 1 deletion tests/testthat/test-write_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,13 @@ test_that("process_quantiles works as expected", {
fit <- readRDS(test_path("data", "sample_fit.rds"))

# Run the function on the fit object
result <- process_quantiles(fit, "test_geo", "test_model", "test_disease")
result <- process_quantiles(
fit,
"test_geo",
"test_model",
"test_disease",
c(0.5, 0.95)
)

# Test 1: Check if the result is a data.table
expect_true(
Expand Down

0 comments on commit b8c352e

Please sign in to comment.