Skip to content

Test summary.imugap_predict (#73)#77

Merged
WestonVoglesonger merged 1 commit into
mainfrom
test-73-summary
Jun 2, 2026
Merged

Test summary.imugap_predict (#73)#77
WestonVoglesonger merged 1 commit into
mainfrom
test-73-summary

Conversation

@WestonVoglesonger
Copy link
Copy Markdown
Contributor

First targeted slice of #73: summary.imugap_predict (added with the draws-compatible predict refactor in #70) had no dedicated test.

Coverage added (tests/testthat/test-summary.R)

  • Output shape — one row per target observation; the target columns (obs_c_id, loc_id, age, cohort, dose) are carried through.
  • Quantile columns — default probs = c(.025, .5, .975) produces mean + q2_5/q50/q97_5; custom probs swap them (e.g. q10/q90).
  • Correctnessmean and quantiles match a manual colMeans / quantile reduction of $draws.
  • Error branch — non-imugap_predict input is rejected.
  • Copy semanticsobject$target is not mutated.

Uses a small synthetic imugap_predict object (a draws matrix + target data.table) rather than running the sampler, so the test is fast and deterministic. Verified passing (13 assertions) against the current main source.

Remaining #73 items (predict edge cases, checker error branches, options/canonicalize failure paths) are left for follow-up slices.

Refs #73

summary.imugap_predict (added in #70) had no dedicated test. Covers:
- output shape: one row per target obs, target columns carried through
- default probs -> mean + q2_5/q50/q97_5 columns; custom probs swap them
- statistics match a manual colMeans/quantile reduction of the draws
- error branch on non-imugap_predict input
- copy semantics (does not mutate object$target)

Uses a synthetic imugap_predict (draws matrix + target dt) rather than running
the sampler, so the test is fast and deterministic.

Refs #73
@WestonVoglesonger WestonVoglesonger self-assigned this Jun 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@pearsonca pearsonca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for predict as is - but: can you also circle back to predict and have it instead provide in the draws array style structure: https://cran.r-project.org/web/packages/posterior/vignettes/posterior.html#draws-formats (and update all the contingent items accordingly)?

It'll be a pretty common ask to trim off the burn-in period, and draws array makes that simplest.

Comment on lines +7 to +20
make_pred <- function(seed = 1L) {
set.seed(seed)
n_draws <- 100L
n_obs <- 3L
draws <- matrix(runif(n_draws * n_obs), nrow = n_draws, ncol = n_obs)
target <- data.table::data.table(
obs_c_id = 1:3,
loc_id = c("a", "b", "c"),
age = c(5L, 5L, 5L),
cohort = c(1L, 1L, 1L),
dose = c(2L, 2L, 2L)
)
structure(list(draws = draws, target = target), class = "imugap_predict")
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may be incomplete / incorrectly implemented in predict itself, but: we're going to want draws to be iterations x chains x variables

@WestonVoglesonger WestonVoglesonger merged commit 1a0167f into main Jun 2, 2026
15 checks passed
@WestonVoglesonger WestonVoglesonger deleted the test-73-summary branch June 2, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants