Skip to content

interval_add_secondary() links per-subject intervals to their own subject - #714

Open
billdenney wants to merge 40 commits into
mainfrom
fix/interval-add-secondary-generated
Open

billdenney wants to merge 40 commits into
mainfrom
fix/interval-add-secondary-generated

Conversation

@billdenney

Copy link
Copy Markdown
Member

interval_add_secondary() failed on automatically generated intervals, which have one row per subject: reference = data.frame(start = 0, end = 12) matched one reference row per subject, the reference was chosen by time alone, and the call stopped with pknca_error_secondary_ref_ambiguous_spec. It also warned "Unknown or uninitialised column: interval_id" on tibble intervals.

Fix

Candidate references are first narrowed to those sharing the test row's values in the columns that reference and ref_vary do not name (the engine reads the group values of the reference row a pointer names), falling back to all candidates when none share them. Reads of a possibly absent interval_id use [[.

Tests

The generated per-subject case links each subject to its own reference with no warnings, and pk.nca() gives ratio.auclast 94/70 and 94/130; a crossover with ref_vary = "period" picks each subject's own reference in another period (cmax ratios 6/10 and 9/20).

🤖 Generated with Claude Code

billdenney and others added 30 commits November 9, 2026 18:31
…n subject

Automatically generated intervals have one row per subject, so a reference
such as data.frame(start = 0, end = 12) matched one row per subject.  The
reference was chosen by time alone, so every later interval matched several
references and the helper stopped with
pknca_error_secondary_ref_ambiguous_spec.  The candidate references are now
first narrowed to those sharing the test row's values in the columns that
`reference` and `ref_vary` do not name.

Reads of a possibly absent interval_id column use [[ ]], so tibble intervals
no longer warn about an unknown column.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When units differ between groups (a subject without a dose, or unit
columns), the units table keeps the group columns, holding their values
as character.  pknca_unit_conversion() joined the results to it with
dplyr::left_join(), which stops on an integer, numeric, or date group
column ("Can't join ... due to incompatible types") and turns a factor
group column into character.  left_join_by_value() matches the keys as
character and restores the key columns of the results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With unit columns and a preferred unit, a unit set already in the
preferred units got a table without PPSTRESU and conversion_factor,
while the sets that convert had them.  Composing the secondary
parameter units read the missing columns as zero-length and stopped
with "arguments imply differing number of rows: 1, 0".  Every unit set
now has the standardization columns when any has them, with the set's
own units and a factor of 1 where it does not convert, as
pknca_units_table() does within one set.

The comment that preferred units only apply to scalar units was wrong:
pknca_set_units() keeps them for unit columns too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
clr.last.dn, clr.obs.dn, and clr.pred.dn were registered like the other
dose-normalized parameters, as pk.calc.dn(parameter, dose).  They are
secondary (they depend on a renal clearance), and secondary parameters
are calculated from NCA parameter values only, so the dose source
argument stopped every request with "has arguments not covered by
formalsmap (dose)".

The dose-normalized form of a secondary parameter is now a secondary
parameter of its own:  the base parameter's inputs and reference, with
the dose from totdose (as bioavailability takes it), calculated by
pk.calc.clr.dn().  Explicit links, the parameter's own _ref column, and
automatic references work, and its units are composed from the urine
and plasma groups like renal clearance.  The classification of the three
parameters is unchanged.

New tests calculate every registered secondary parameter through a
linked reference interval and check every dose-normalized parameter's
registration against its base parameter.

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

The dose-normalized renal clearance is now clr.inf.obs.dn and
clr.inf.pred.dn, with clr.obs.dn and clr.pred.dn as their deprecated
names; a deprecated dose-normalized name is checked against the base of
its replacement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Renal clearance divided by the dose is not a parameter used in the
pharmacokinetic literature (CDISC has a code for it, RENALCLD, but no
publication reports it), so this stack does not make clr.*.dn
calculable.  This reverts the changes of fix/clr-dn-formalsmap, which
leaves the stack.

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

This branch has not been deployed

No deployments
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.

1 participant