Skip to content

add meaningful unit test for right truncation #719

@cdc-mitzimorris

Description

@cdc-mitzimorris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions