Skip to content

118: fix factor label collision in robin_surv() - #121

Merged
danielinteractive merged 12 commits into
mainfrom
118_fix_factor_label_collision
Sep 22, 2026
Merged

danielinteractive merged 12 commits into
mainfrom
118_fix_factor_label_collision

Conversation

@danielinteractive

Copy link
Copy Markdown
Collaborator

closes #118

  • Added regression tests for user facing bugs
  • Added generic h_joint_strata()
  • 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

- 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`
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

badge

Code Coverage Summary

Filename                     Stmts    Miss  Cover    Missing
-------------------------  -------  ------  -------  -------------
R/bias.R                        34       0  100.00%
R/find_data.R                    3       0  100.00%
R/predict_couterfactual.R       77       0  100.00%
R/prediction_cf.R               22       0  100.00%
R/robin_glm.R                   49       1  97.96%   40
R/robin_lm.R                    28       0  100.00%
R/surv_effect.R                 67       0  100.00%
R/survival_cov_adj.R           146       0  100.00%
R/survival_score.R             293       0  100.00%
R/survival.R                   345       0  100.00%
R/treatment_effect.R           101       1  99.01%   53
R/utils.R                      218       3  98.62%   121, 153, 157
R/variance_anhecova.R           44       0  100.00%
R/variance_hc.R                 10       0  100.00%
TOTAL                         1437       5  99.65%

Diff against main

Filename              Stmts    Miss  Cover
------------------  -------  ------  --------
R/survival_score.R       -1       0  +100.00%
R/survival.R              0      -1  +0.29%
R/utils.R               +14       0  +0.09%
TOTAL                   +13      -1  +0.07%

Results for commit: d749e31

Minimum allowed coverage is 80%

♻️ This comment has been updated with latest results

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Unit Tests Summary

  1 files   13 suites   13s ⏱️
148 tests 102 ✅ 46 💤 0 ❌
376 runs  312 ✅ 64 💤 0 ❌

Results for commit d749e31.

♻️ This comment has been updated with latest results.

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Unit Test Performance Difference

Additional test case details
Test Suite $Status$ Time on main $±Time$ Test Case
survival 👶 $+0.17$ robin_surv_gives_the_same_result_for_strata_when_the_labels_differ
survival 👶 $+0.05$ robin_surv_gives_warning_also_with_special_strata_labels
survival 👶 $+0.06$ robin_surv_works_as_expected_when_some_strata_are_NA
utils 👶 $+0.01$ h_joint_strata_derives_identity_from_level_codes
utils 👶 $+0.01$ h_joint_strata_fails_when_there_are_missing_values
utils 👶 $+0.09$ h_joint_strata_matches_interaction_when_labels_do_not_collide

Results for commit e1fea34

♻️ This comment has been updated with latest results.

@clarkliming

Copy link
Copy Markdown
Collaborator

review in progress and take some time, please forgive me cause busy with work these days

@danielinteractive
danielinteractive requested a lite review from Copilot September 22, 2026 07:40
@danielinteractive

Copy link
Copy Markdown
Collaborator Author

@clarkliming I am merging this now (after AI review), otherwise it is difficult to work on the next issue that also is about robin_surv. I think the risk is reasonably low here. We can always revisit the details if you find something later. Thanks!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 High severity · 1 Medium severity

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 in R/survival_score.R for 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.

Comment thread data-raw/create_glm_data.R
Comment thread R/utils.R
@danielinteractive
danielinteractive merged commit 57505d3 into main Sep 22, 2026
22 of 23 checks passed
@danielinteractive
danielinteractive deleted the 118_fix_factor_label_collision branch September 22, 2026 08:56
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.

robin_surv(): factor label collision silently merges distinct joint strata, corrupting estimates

3 participants