118: fix factor label collision in robin_surv() - #121
Conversation
- Updated both affected grouping sites in `R/survival_score.R` - Randomization-strata nesting checks - Stratified score and variance calculation - Added helper tests covering: - 200 randomized equivalence cases against `interaction()`. - Colliding labels remaining distinct via level-code identity. - Added a bug-fix entry to `NEWS.md`
Code Coverage SummaryDiff against mainResults for commit: d749e31 Minimum allowed coverage is ♻️ This comment has been updated with latest results |
…a/RobinCar2 into 118_fix_factor_label_collision
Unit Tests Summary 1 files 13 suites 13s ⏱️ Results for commit d749e31. ♻️ This comment has been updated with latest results. |
Unit Test Performance DifferenceAdditional test case details
Results for commit e1fea34 ♻️ This comment has been updated with latest results. |
|
review in progress and take some time, please forgive me cause busy with work these days |
|
@clarkliming I am merging this now (after AI review), otherwise it is difficult to work on the next issue that also is about |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
h_joint_strata() currently errors on NA inputs (regression vs interaction()), and data-raw/create_glm_data.R has a pipeline syntax error plus uses |> despite the package declaring R (>= 3.6).
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (2)
What changed in this PR
This PR addresses #118 by preventing robin_surv() from collapsing distinct joint strata when factor labels collide (e.g., "a.b" + "c" vs "a" + "b.c"), by introducing a code-based joint-strata helper and using it in the stratified survival score logic.
Changes:
- Added
h_joint_strata()to build joint strata based on factor level codes (not pasted labels) and applied it inR/survival_score.Rfor both nesting checks and stratified splitting. - Added regression tests covering label-renaming invariance and warning behavior with “special” (collision-prone) labels, plus helper-level tests for equivalence to
interaction()when safe. - Miscellaneous maintenance/formatting updates (implicit return,
seq_along(), argument formatting, NEWS entry, and a data-raw script refactor).
| File | Description |
|---|---|
| vignettes/articles/robincar-validate.Rmd | Small boolean operator tweak inside validation vignette code. |
| tests/testthat/test-utils.R | Adds unit tests for h_joint_strata() behavior and collision handling. |
| tests/testthat/test-survival.R | Adds regression tests for the strata-collision bug and warning behavior. |
| R/variance_anhecova.R | Minor internal cleanup (seq_along(), implicit return). |
| R/utils.R | Introduces h_joint_strata() helper (core of the fix). |
| R/treatment_effect.R | Formatting/indentation changes only. |
| R/survival_score.R | Replaces label-based interaction()/split() usage with h_joint_strata() at both affected sites. |
| NEWS.md | Adds a bug-fix entry for the strata-collision issue. |
| man/h_joint_strata.Rd | Generated documentation for the new internal helper. |
| data-raw/create_glm_data.R | Refactors pipeline syntax in data generation script. |
Files not reviewed (1)
- man/h_joint_strata.Rd: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.


closes #118