Add predictive_ipred to collected TDMs#40
Merged
roninsightrx merged 3 commits intomainfrom Mar 26, 2026
Merged
Conversation
Simulates a prediction from the estimation model using current parameters (population prior on dose 1, MAP estimates thereafter) and stores it as `predictive_ipred` in the TDM data frame. This supports post-hoc predictive analysis without changing any existing behaviour. Fixes a bug where `tdms_i` was initialised without the `predictive_ipred` column, causing `rbind` to fail on the first accumulation step. Renames the new `est_model_design` parameter to `est_design` to avoid R's partial-argument-matching silently binding `est_model` (a `...` argument) to the formal parameter instead of forwarding it to the dose optimisation method. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a predictive_ipred column to collected TDM data so predictive performance can be assessed post-hoc by simulating an individual prediction from the estimation model/parameters alongside observed TDMs.
Changes:
- Extend
collect_tdms()to optionally simulate and returnpredictive_ipred(orNAwhen not requested). - Plumb estimation design info through
sim_subject()→sample_and_adjust_by_dose()so TDM collection can computepredictive_ipredduring iterative dose adjustment. - Add/extend tests to assert presence and expected population/NA behavior of
predictive_ipred.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
R/collect_tdms.R |
Adds optional estimation-model simulation and appends predictive_ipred to the returned TDM data frame. |
R/sample_and_adjust.R |
Initializes TDM accumulator with predictive_ipred and forwards estimation model/parameters into collect_tdms(). |
R/sim_subject.R |
Passes design$est into sample_and_adjust_by_dose() via new est_design arg. |
tests/testthat/test-collect_tdms.R |
Updates expectations and adds tests for NA vs populated predictive_ipred. |
tests/testthat/test-sample_and_adjust.R |
Adds integration tests for predictive_ipred across dose adjustments and when est_design is absent. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
predictive_ipredcolumn to TDM data frames: simulates a prediction from the estimation model using the current parameter estimates (population prior on dose 1, MAP estimates on subsequent doses) and stores it alongside the observed TDMs — enabling post-hoc predictive performance analysis without changing existing behaviour.claude.mdfileTest plan
test-collect_tdms.R:predictive_ipredisNAwhen noest_modelsupplied; numeric and equal totrue_ywhen same model/params used for both sim and est.test-sample_and_adjust.R:predictive_ipredis populated across multiple dose adjustments (exercises the rbind fix); isNAwhenest_designis not supplied.