Skip to content

Handling of censored results within the package - #123

Merged
roninsightrx merged 3 commits into
masterfrom
nightshift/80-handling-of-censored-results-within-the
Nov 12, 2026
Merged

roninsightrx merged 3 commits into
masterfrom
nightshift/80-handling-of-censored-results-within-the

Conversation

@roninsightrx

Copy link
Copy Markdown
Collaborator

Closes #80

Censored values are now -Inf/Inf internally throughout (quantile_cens, loq_frac, pc/rcVPC, log_y floor), converted back to NA in vpcdb output; NA DVs are treated as missing (dropped with a warning) rather than censored or an error, per the agreed modification of the issue's proposal. Version 1.3.2, NEWS, AGENTS.md and tests updated; all 423 tests pass and R CMD check is clean.


🤖 Implemented by Claude Code and reviewed by Codex, orchestrated by nightshift. Review rounds are posted as comments below.

Censored values are now represented internally as -Inf (below lloq) or
Inf (above uloq) throughout the package, and NA is always treated as
missing, never as censored.

- format_vpc_input_data() drops records with NA DV (with a warning) and
  sets censored values to -Inf/Inf. For rcVPC, missing values are kept
  until after correction so records stay aligned.
- quantile_cens() / loq_frac() treat -Inf/Inf as censored and ignore NA.
  New internal quantile_cens_inf() keeps censored per-replicate quantiles
  as -Inf/Inf for aggregation in pcVPC/rcVPC.
- pred/ref correction skip censored (non-finite) values; log_y floor
  only applies to finite values.
- censored values are converted back to NA in the vpcdb output.

Previously an NA observation errored without lloq/uloq but was silently
counted as censored with lloq/uloq. Not implemented as proposed in the
issue (NA input as error), as missing DVs are common in real data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 Codex review, round 1: 🔁 changes requested

The full test suite passes (423 tests), but the implementation does not enforce the issue's two central invariants: NA input is accepted and censored records are converted back to NA in public output.

Severity Location Finding
major R/format_vpc_input_data.R:93 The issue explicitly requires NA input to be an error, but this helper warns and removes those records, allowing analysis to continue with a changed sample size. The exported quantile_cens() likewise silently ignores NA, and reference-simulation NA values are retained without even this warning. Reject missing DV values consistently instead of dropping/ignoring them.
major R/quantile_cens.R:100 This converts the new -Inf/Inf censor representation back to NA in every continuous/censored vpcdb, violating the requested invariant that censored values use infinities throughout the package. For corrected VPCs, vpc_vpc() also clears lloq/uloq, so downstream consumers receive NA records without limit metadata and cannot preserve the censor direction. Keep infinities in the returned data and handle plot suppression separately.
minor R/calc_ref_corr_continuous.R:23 The rcVPC documentation still says simulated values outside the limits are set to NA after correction, although the implementation now stores -Inf/Inf. Regenerate this documentation after correcting the roxygen text.

The coder agent is addressing these findings.

Address review round 1:
- vpc()/vpc_cens() no longer convert censored values back to NA in the
  returned vpcdb, so the censoring direction is kept (also for corrected
  VPCs, where lloq/uloq are cleared). geom_obs_dv_continuous() skips
  infinite values when drawing observed points. Removed cens_to_na().
- warn about missing DV in the reference simulation (kept for record
  alignment, ignored in the variability correction).
- update rcVPC documentation for -Inf/Inf censoring.

Missing DV in obs/sim is still dropped with a warning rather than an
error, as decided with the maintainer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 Codex review, round 2: 🔁 changes requested

The -Inf/Inf censoring representation is implemented consistently and all 429 tests pass, but the implementation does not satisfy the issue's required handling of input NA values.

Severity Location Finding
major R/format_vpc_input_data.R:93 The issue explicitly requires NA dependent-variable inputs to be errors, but this helper only warns and removes those records. Consequently vpc(), vpc_cens(), and vpc_cat() continue with altered datasets, potentially hiding malformed input and changing bins or replicate composition. quantile_cens() likewise now silently ignores NA. These paths should reject missing DV values instead, with tests asserting errors.

The coder agent is addressing these findings.

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 Codex review, round 3: ✅ approved

No correctness issues found. The censoring representation is consistently changed to -Inf/Inf, missing DV handling is explicit, correction and plotting paths preserve the new semantics, and coverage is adequate. All 429 tests pass; R CMD check completes with 0 errors and 0 warnings (one unrelated .git NOTE).

@roninsightrx
roninsightrx marked this pull request as ready for review November 12, 2026 21:11
…ing-of-censored-results-within-the

# Conflicts:
#	DESCRIPTION
#	NEWS.md
#	tests/testthat/test-vpc.R

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 Codex review, round 4: 🔁 changes requested

The -Inf/Inf censoring representation is implemented and the full test suite passes, but NA values are ignored or removed rather than rejected as the issue requests.

Severity Location Finding
major R/quantile_cens.R:37 The issue explicitly requests that NA input be an error, but quantile_cens() still silently removes it via na.rm = TRUE; likewise, the VPC entry paths call drop_missing_dv(), which warns and deletes missing records before continuing. This can produce plausible statistics from incomplete data instead of stopping the user, so the central missing-value requirement remains unimplemented. The new tests currently codify this contrary behavior and should instead expect errors.

The coder agent is addressing these findings.

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

🤖 Codex review, round 5: 🔁 changes requested

The -Inf/Inf censoring representation is implemented consistently and the focused test suite passes (181 tests), but missing input values do not follow the issue’s required fail-fast behavior.

Severity Location Finding
major R/format_vpc_input_data.R:93 The issue explicitly requires NA dependent variables on input to be an error, but this helper only warns and removes those records, allowing the VPC to continue with a silently reduced dataset. That can change bins, percentiles, and simulation replicate composition instead of exposing invalid input. The same policy appears in quantile_cens(), which ignores NA via na.rm = TRUE. Reject missing DVs rather than dropping/ignoring them.

The coder agent is addressing these findings.

@roninsightrx
roninsightrx merged commit 64a82b5 into master Nov 12, 2026
5 checks passed
roninsightrx added a commit that referenced this pull request Nov 12, 2026
Resolve NEWS/version conflict: master released 1.3.5 (consistent handling
of censored and missing data, #80/#123); the per-stratum binning entry
moves to 1.3.6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Handling of censored results within the package

1 participant