Test summary.imugap_predict (#73)#77
Merged
Merged
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
pearsonca
approved these changes
Jun 1, 2026
Member
pearsonca
left a comment
There was a problem hiding this comment.
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") | ||
| } |
Member
There was a problem hiding this comment.
this may be incomplete / incorrectly implemented in predict itself, but: we're going to want draws to be iterations x chains x variables
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)targetcolumns (obs_c_id,loc_id,age,cohort,dose) are carried through.probs = c(.025, .5, .975)producesmean+q2_5/q50/q97_5; customprobsswap them (e.g.q10/q90).meanand quantiles match a manualcolMeans/quantilereduction of$draws.imugap_predictinput is rejected.object$targetis not mutated.Uses a small synthetic
imugap_predictobject (adrawsmatrix +targetdata.table) rather than running the sampler, so the test is fast and deterministic. Verified passing (13 assertions) against the currentmainsource.Remaining #73 items (predict edge cases, checker error branches, options/canonicalize failure paths) are left for follow-up slices.
Refs #73