diff --git a/R/regimen_to_nm.R b/R/regimen_to_nm.R index eb91a83..6a47bd5 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,8 +50,8 @@ 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 <- -1 + message("Setting rate to be handled in NONMEM model using R parameters.") } } if(!is.null(t_obs)) { diff --git a/man/adherence_binomial.Rd b/man/adherence_binomial.Rd index 4db8090..a51977d 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 ae42af0..e144ec8 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 a529542..45925c6 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 da77c3e..1cc17c2 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. } diff --git a/tests/testthat/test_regimen_to_nm.R b/tests/testthat/test_regimen_to_nm.R index 6f37b0a..ce0b2d9 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),