Skip to content

Covariate named in upper case is not resolved against a lower-case column when the frame is passed, though the same model fits from file - #45

Merged
roninsightrx merged 3 commits into
mainfrom
nightshift/43-covariate-named-in-upper-case-is-not
Nov 14, 2026
Merged

roninsightrx merged 3 commits into
mainfrom
nightshift/43-covariate-named-in-upper-case-is-not

Conversation

@roninsightrx

Copy link
Copy Markdown
Contributor

Closes #43

anonymize_dataset() now adds a [data] rename (e.g. CONC0 = conc0) to the simulation copy of the model when the model names a covariate in a different case than its column. It checks the model's covariate references before sampling: ambiguous case matches stop with an error, and references to columns left out of covariates raise a warning. Tests added (including one that runs real ferx), version bumped to 0.0.0.9047, NEWS updated.


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

FeRx matches covariate references to data columns case-sensitively, so a
model that spells a covariate `CONC0` failed to simulate on an anonymized
frame carrying `conc0` unless the `[data]` block mapped it, and the
E_MISSING_COVARIATE error only surfaced from inside ferx_rust_simulate().

The simulation copy of `model_file` now gets an added `[data]` rename
(`CONC0 = conc0`) for each covariate the model references under a spelling
that differs only by case from an unmapped covariate column (a `[data]`
block is appended if the model has none). The model's references are
checked before sampling: ambiguous case matches error with the columns
named, and references to columns of `data` left out of `covariates` warn.

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

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Contributor 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 intended CONC0/conc0 bridge works and focused tests pass, but the heuristic identifier scanner can rename valid covariates away when their names differ only by case from FeRx syntax tokens.

Severity Location Finding
major R/anonymize_dataset.R:1244 ferx_model_identifiers() treats the bare FeRx pk structural keyword as a candidate covariate because it is not followed directly by (. For a valid model that also uses an uppercase PK covariate, the exact PK reference is filtered out while the false lowercase pk reference remains, causing prepare_simulation_model_file() to inject pk = PK. This renames the real column away: direct FeRx simulation succeeds, but the prepared model fails with E_MISSING_COVARIATE for PK and reports only pk as available. Exclude FeRx grammar tokens from candidate references (and test this collision); similar false positives exist for ODE syntax and state names.

The coder agent is addressing these findings.

The identifier scan read the bare `pk` structural keyword as a covariate
reference, so a model using an upper-case `PK` covariate got a `pk = PK`
rename that moved the real column away and broke the simulation.

- Exclude FeRx grammar words (pk, ode, d/dt, if/else, [covariates] type
  words, literals) from candidate references.
- Treat ODE state names (`states = [...]`, `d/dt(X)`, `obs_cmt = X`) as
  defined, not referenced.
- Never rename a column that the model references under its exact
  spelling; a case-variant reference to it is skipped instead of bridged
  or reported as ambiguous.

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

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Contributor 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: ✅ approved

The main #43 case is handled and all 162 focused anonymize_dataset tests pass. One edge case involving two genuinely distinct references that differ only by case still bypasses the new upfront diagnostics.

Severity Location Finding
minor R/anonymize_dataset.R:1315 The exact-match suppression hides genuine case-sensitive references. For a model that references both WT and Wt, with only WT retained in covariates, Wt is removed from bridge consideration because WT exists exactly. The later check also uppercases availability, so it emits no warning; simulation still fails inside FeRx with E_MISSING_COVARIATE. Distinct case-sensitive references should remain diagnosable even when one variant has an exact column match.

@roninsightrx
roninsightrx marked this pull request as ready for review November 14, 2026 01:38
…-not

Resolve conflicts in NEWS.md and tests/testthat/test-anonymize_dataset.R
by keeping both sides. Bump the version to 0.0.0.9049 (both sides were at
0.0.0.9048).

Integrate the new `design_cols` argument (#31) with the up-front model
covariate check (#43): design columns are cloned into the anonymized frame
under their own names, so the check now counts them as frame columns (a
model referencing one no longer warns, and a case-only mismatch to one is
bridged), and the warning points at `design_cols` as well as `covariates`.

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

@roninsightrx roninsightrx left a comment

Copy link
Copy Markdown
Contributor 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

The primary case-only bridge works, and both the focused 193-assertion test set and full package suite pass. Two heuristic-scanner edge cases remain, but neither warrants blocking the change.

Severity Location Finding
minor R/anonymize_dataset.R:1379 The exact-match safeguard can hide a genuine unresolved reference. For a model using both WT and wt with only column wt, WT initially qualifies for bridging, but this guard removes it because wt is also in all_refs. No bridge or preflight ambiguity error is produced; simulation later fails with E_MISSING_COVARIATE: WT, recreating the delayed failure this change aims to prevent.
minor R/anonymize_dataset.R:1302 The scanner treats several non-expression FeRx blocks as expressions. Supported syntax such as [event_model] family = weibull, [adaptive_dosing] when signal ..., [covariate_nn] activation = tanh, and indexed scaling assignments like y[CMT=2] = ... produces false references (weibull, when, signal, tanh, y). Matching data columns can therefore trigger incorrect warnings, spurious renames, or ambiguity errors even though the model never references them as covariates.

@roninsightrx
roninsightrx merged commit 598c385 into main Nov 14, 2026
5 checks passed
@roninsightrx
roninsightrx deleted the nightshift/43-covariate-named-in-upper-case-is-not branch November 14, 2026 01:46
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.

Covariate named in upper case is not resolved against a lower-case column when the frame is passed, though the same model fits from file

1 participant