From 399acbfa3cb3de158de94c471597bf6ab28b6622 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Fri, 30 Jan 2026 22:25:54 +0000 Subject: [PATCH 1/3] fix rate issue --- R/regimen_to_nm.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/regimen_to_nm.R b/R/regimen_to_nm.R index eb91a83f..d6a69ced 100644 --- a/R/regimen_to_nm.R +++ b/R/regimen_to_nm.R @@ -43,8 +43,10 @@ regimen_to_nm <- function( } bioav_dose[is.na(bioav_dose)] <- 1 } - dat$RATE <- dat$RATE * bioav_dose - message("Recalculating infusion rates to reflect bioavailability for infusion.") + # dat$RATE <- dat$RATE * bioav_dose + dat$RATE <- -1 + message("Setting rate to be handled in NONMEM model using R parameters.") + # message("Recalculating infusion rates to reflect bioavailability for infusion.") } } if(!is.null(t_obs)) { From f0d70e1ad477a42ad842064aa4b451f1fa982d61 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Wed, 11 Feb 2026 23:25:41 +0000 Subject: [PATCH 2/3] update function description --- R/regimen_to_nm.R | 9 +++++++-- man/adherence_binomial.Rd | 2 +- man/adherence_markov.Rd | 2 +- man/new_adherence.Rd | 2 +- man/regimen_to_nm.Rd | 7 ++++++- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/R/regimen_to_nm.R b/R/regimen_to_nm.R index d6a69ced..6a47bd58 100644 --- a/R/regimen_to_nm.R +++ b/R/regimen_to_nm.R @@ -1,5 +1,12 @@ #' Convert PKPDsim regimen to NONMEM table (doses only) #' +#' Note: when bioavailability is used for insusions: NONMEM behaves differently from PKPDsim and Monolix, +#' in that rates are not automatically recomputed for infusions where bioavailabiliy also applies. +#' In PKPDsim/Monolix, for a bioavailability of 50%, an AMT of 100 mg and rate of 100mg/hr would be recalculated +#' to 50 mg and 50 mg/hour, respectively, to keep the infusion length the same. This is not the case +#' in NONMEM. Therefore, the easiest way to work around this is for the user to compute the rate manually +#' in NONMEM using custom code. Therefore, we set the `RATE` column to `-1` for such infusions. +#' #' @param reg `PKPDsim` regimen, created using `new_regimen()` function #' @param dose_cmt dosing compartment, if not specified in `reg` object #' @param n_ind repeat for `n_ind` subjects @@ -43,10 +50,8 @@ regimen_to_nm <- function( } bioav_dose[is.na(bioav_dose)] <- 1 } - # dat$RATE <- dat$RATE * bioav_dose dat$RATE <- -1 message("Setting rate to be handled in NONMEM model using R parameters.") - # message("Recalculating infusion rates to reflect bioavailability for infusion.") } } if(!is.null(t_obs)) { diff --git a/man/adherence_binomial.Rd b/man/adherence_binomial.Rd index 4db80908..a51977d6 100644 --- a/man/adherence_binomial.Rd +++ b/man/adherence_binomial.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/adherence.R +% Please edit documentation in R/new_adherence.R \name{adherence_binomial} \alias{adherence_binomial} \title{Binomial adherence} diff --git a/man/adherence_markov.Rd b/man/adherence_markov.Rd index ae42af06..e144ec8d 100644 --- a/man/adherence_markov.Rd +++ b/man/adherence_markov.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/adherence.R +% Please edit documentation in R/new_adherence.R \name{adherence_markov} \alias{adherence_markov} \title{Markov adherence model} diff --git a/man/new_adherence.Rd b/man/new_adherence.Rd index a5295424..45925c6c 100644 --- a/man/new_adherence.Rd +++ b/man/new_adherence.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/adherence.R +% Please edit documentation in R/new_adherence.R \name{new_adherence} \alias{new_adherence} \title{Probabilistically model adherence} diff --git a/man/regimen_to_nm.Rd b/man/regimen_to_nm.Rd index da77c3e4..1cc17c28 100644 --- a/man/regimen_to_nm.Rd +++ b/man/regimen_to_nm.Rd @@ -30,5 +30,10 @@ regimen_to_nm( Data frame containing doses } \description{ -Convert PKPDsim regimen to NONMEM table (doses only) +Note: when bioavailability is used for insusions: NONMEM behaves differently from PKPDsim and Monolix, +in that rates are not automatically recomputed for infusions where bioavailabiliy also applies. +In PKPDsim/Monolix, for a bioavailability of 50\%, an AMT of 100 mg and rate of 100mg/hr would be recalculated +to 50 mg and 50 mg/hour, respectively, to keep the infusion length the same. This is not the case +in NONMEM. Therefore, the easiest way to work around this is for the user to compute the rate manually +in NONMEM using custom code. Therefore, we set the \code{RATE} column to \code{-1} for such infusions. } From b5b0d33cb1f7a6d76eaec8560253442631ea27b4 Mon Sep 17 00:00:00 2001 From: Ron Keizer Date: Wed, 11 Feb 2026 18:35:41 -0800 Subject: [PATCH 3/3] update tests --- tests/testthat/test_regimen_to_nm.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test_regimen_to_nm.R b/tests/testthat/test_regimen_to_nm.R index 6f37b0ac..ce0b2d93 100644 --- a/tests/testthat/test_regimen_to_nm.R +++ b/tests/testthat/test_regimen_to_nm.R @@ -25,7 +25,7 @@ test_that("regimen with infusion correctly recalculates rates when bioavailabili bioav = 0.5 ) }, - "Recalculating infusion rates" + "Setting rate to be handled in NONMEM model" ) expect_warning( regimen_to_nm( @@ -46,7 +46,7 @@ test_that("regimen with infusion correctly recalculates rates when bioavailabili "RATE" ) expect_true(all(expected_cols %in% colnames(b))) - expect_equal(b$RATE, c(5, 0, 0, 0, 5, 5, 5, 5)) + expect_equal(b$RATE, c(-1, 0, 0, 0, -1, -1, -1, -1)) }) test_that("rate is calculated for any regimen with an infusion length", { @@ -65,7 +65,7 @@ test_that("rate is calculated for any regimen with an infusion length", { bioav = 0.5 ) }, - "Recalculating infusion rates" + "Setting rate to be handled in NONMEM model" ) expect_message( { @@ -76,7 +76,7 @@ test_that("rate is calculated for any regimen with an infusion length", { bioav = c(0.5, 1) ) }, - "Recalculating infusion rates" + "Setting rate to be handled in NONMEM model" ) expected_cols <- c( "ID", @@ -90,9 +90,9 @@ test_that("rate is calculated for any regimen with an infusion length", { ) expect_true(all(expected_cols %in% colnames(b))) expect_true(all(expected_cols %in% colnames(c))) - # in NONMEM, oral doses have a RATE of zero, which indicates a bolus dose - expect_equal(b$RATE, c(0, 0, 0, 0, 0, 10, 10, 0)) - expect_equal(c$RATE, c(0, 0, 0, 0, 0, 10, 20, 0)) + # RATE is set to -1 for doses when bioav is specified, to let NONMEM handle rate calculation + expect_equal(b$RATE, c(-1, 0, 0, 0, -1, -1, -1, -1)) + expect_equal(c$RATE, c(-1, 0, 0, 0, -1, -1, -1, -1)) }) test_that("throws warning when bioav specified as model parameter and need to convert RATE, but not when not needed", { @@ -109,7 +109,7 @@ test_that("throws warning when bioav specified as model parameter and need to co t_obs = c(1, 2, 3), bioav = c("Fi", 1) ) - }, "Recalculating infusion rates") + }, "Setting rate to be handled in NONMEM model") a2 <- new_regimen( amt = 10, time = c(1, 2, 3, 4),