CDCgov / CDCgov/PyRenew

add meaningful unit test for right truncation

Open
#719 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
29
Forks
9
Avg merge
9d 9h
Merged PRs (30d)
8

Description

Problem

The right-truncation tutorial (docs/tutorials/right_truncation.qmd) demonstrates the key behavioral property of right-truncation: when two otherwise identical observation processes are sampled — one with and one without a right_truncation_rv — their predicted values agree for early timepoints and diverge for recent ones. This is the property that matters most for correctness: right-truncation is a multiplicative adjustment that leaves fully-reported timepoints untouched while depressing recent ones proportionally to the reporting delay CDF.

The existing unit tests in TestRightTruncation (test/test_observation_counts.py) do not test this comparative property. They check absolute predicted values at specific positions using a trivial single-element delay PMF ([1.0]), which bypasses the delay convolution entirely. There is no test that:

  1. Uses a multi-element delay PMF (so the delay convolution is exercised).
  2. Constructs both a truncated and non-truncated Counts process with the same parameters.
  3. Samples both with the same seed and infections.
  4. Asserts that early predicted values are identical between the two.
  5. Asserts that recent predicted values in the truncated process are strictly less.
  6. Verifies that the ratio of truncated to non-truncated predicted values equals the proportion already reported from compute_prop_already_reported.

Proposed test

Create a test that mirrors the tutorial's comparison: construct two Counts processes sharing the same delay PMF, ascertainment rate, and noise model, differing only in right_truncation_rv. Sample both with the same infections array. Assert:

  • Early agreement: for timepoints where prop_already_reported == 1.0, the predicted values match exactly.
  • Late divergence: for recent timepoints, the truncated predicted values are strictly less.
  • Correct ratio: predicted_truncated / predicted_non_truncated == prop_already_reported for all post-initialization timepoints.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with TestRightTruncation in test/test_observation_counts.py and compare it with the right-truncation example in docs/tutorials/right_truncation.qmd. Construct matching truncated and non-truncated Counts processes using a multi-element delay PMF, then sample both with the same infections and seed. Done means early values match, recent truncated values are lower, and their ratio matches compute_prop_already_reported.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.