Skip to content

Conversation

@roninsightrx
Copy link
Contributor

@roninsightrx roninsightrx commented Jul 8, 2025

Previously, it was not possible to estimate lagtime as a parameter, since it was incorporated in the static event tables that were input to PKPDsim. We have now pulled this out of the event table and it is now handled dynamically within PKPDsim's core function. In principle, it requires just a few minor updates to PKPDmap to support estimation of the parameter: just passing the lagtime vector as argument.

However, it does introduce a second problem we need to solve, in that lagtimes are step-functions and hence introduce inconcistencies that make estimation of the parameter difficult / impossible with gradient-based optimization methods like BFGS. In practice, if the initial estimate of lagtime is lower than the data suggests, it will never be able to recover because the initial gradients are zero for TLAG. The issue can however be solved fairly easily by switching to a non-gradient-based optimization method like Nelder-Mead. I've chosen not to make this a forced or automatic switch, but to leave it to the user. I have left some info in documentation and code comments.

Related PR in PKPDsim

CI WILL ONLY PASS AFTER THE PKPDsim PR HAS BEEN MERGED

t_init = 0,
calc_ofv,
regimen,
lagtime = c(0),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the default for PKPDsim. It needs to be non-NULL. If we pass a NULL value it will also be converted to c(0) in PKPDsim.

@@ -0,0 +1,10 @@
mod_1cmt_oral_lagtime <- PKPDsim::new_ode_model(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this out of the single test, so it can be re-used.

## check that fit works for vector of lagtimes
lagtimes <- c(0.25, 0.5, 0.75, 1.0, 2.0)
est <- c()
for(i in seq(lagtimes)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

loop over a range of lagtime estimates (true value is 0.83). Should give estimate for all values. This in contrast to the default optimization method (BGFS) which will error for values lower than ~0.85.

@roninsightrx roninsightrx merged commit b943d26 into master Jul 13, 2025
1 check passed
@roninsightrx roninsightrx deleted the RXR-2394-lagtime branch July 13, 2025 21:07
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.

3 participants