Skip to content

Commit 21855dd

Browse files
Merge pull request #134 from InsightRX/fix-rate
Fix handling of rate in regimen_to_nm() function for iv + bioavailability
2 parents 73da416 + b5b0d33 commit 21855dd

6 files changed

Lines changed: 26 additions & 14 deletions

File tree

R/regimen_to_nm.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#' Convert PKPDsim regimen to NONMEM table (doses only)
22
#'
3+
#' Note: when bioavailability is used for insusions: NONMEM behaves differently from PKPDsim and Monolix,
4+
#' in that rates are not automatically recomputed for infusions where bioavailabiliy also applies.
5+
#' In PKPDsim/Monolix, for a bioavailability of 50%, an AMT of 100 mg and rate of 100mg/hr would be recalculated
6+
#' to 50 mg and 50 mg/hour, respectively, to keep the infusion length the same. This is not the case
7+
#' in NONMEM. Therefore, the easiest way to work around this is for the user to compute the rate manually
8+
#' in NONMEM using custom code. Therefore, we set the `RATE` column to `-1` for such infusions.
9+
#'
310
#' @param reg `PKPDsim` regimen, created using `new_regimen()` function
411
#' @param dose_cmt dosing compartment, if not specified in `reg` object
512
#' @param n_ind repeat for `n_ind` subjects
@@ -43,8 +50,8 @@ regimen_to_nm <- function(
4350
}
4451
bioav_dose[is.na(bioav_dose)] <- 1
4552
}
46-
dat$RATE <- dat$RATE * bioav_dose
47-
message("Recalculating infusion rates to reflect bioavailability for infusion.")
53+
dat$RATE <- -1
54+
message("Setting rate to be handled in NONMEM model using R parameters.")
4855
}
4956
}
5057
if(!is.null(t_obs)) {

man/adherence_binomial.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/adherence_markov.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/new_adherence.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/regimen_to_nm.Rd

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test_regimen_to_nm.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ test_that("regimen with infusion correctly recalculates rates when bioavailabili
2525
bioav = 0.5
2626
)
2727
},
28-
"Recalculating infusion rates"
28+
"Setting rate to be handled in NONMEM model"
2929
)
3030
expect_warning(
3131
regimen_to_nm(
@@ -46,7 +46,7 @@ test_that("regimen with infusion correctly recalculates rates when bioavailabili
4646
"RATE"
4747
)
4848
expect_true(all(expected_cols %in% colnames(b)))
49-
expect_equal(b$RATE, c(5, 0, 0, 0, 5, 5, 5, 5))
49+
expect_equal(b$RATE, c(-1, 0, 0, 0, -1, -1, -1, -1))
5050
})
5151

5252
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", {
6565
bioav = 0.5
6666
)
6767
},
68-
"Recalculating infusion rates"
68+
"Setting rate to be handled in NONMEM model"
6969
)
7070
expect_message(
7171
{
@@ -76,7 +76,7 @@ test_that("rate is calculated for any regimen with an infusion length", {
7676
bioav = c(0.5, 1)
7777
)
7878
},
79-
"Recalculating infusion rates"
79+
"Setting rate to be handled in NONMEM model"
8080
)
8181
expected_cols <- c(
8282
"ID",
@@ -90,9 +90,9 @@ test_that("rate is calculated for any regimen with an infusion length", {
9090
)
9191
expect_true(all(expected_cols %in% colnames(b)))
9292
expect_true(all(expected_cols %in% colnames(c)))
93-
# in NONMEM, oral doses have a RATE of zero, which indicates a bolus dose
94-
expect_equal(b$RATE, c(0, 0, 0, 0, 0, 10, 10, 0))
95-
expect_equal(c$RATE, c(0, 0, 0, 0, 0, 10, 20, 0))
93+
# RATE is set to -1 for doses when bioav is specified, to let NONMEM handle rate calculation
94+
expect_equal(b$RATE, c(-1, 0, 0, 0, -1, -1, -1, -1))
95+
expect_equal(c$RATE, c(-1, 0, 0, 0, -1, -1, -1, -1))
9696
})
9797

9898
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
109109
t_obs = c(1, 2, 3),
110110
bioav = c("Fi", 1)
111111
)
112-
}, "Recalculating infusion rates")
112+
}, "Setting rate to be handled in NONMEM model")
113113
a2 <- new_regimen(
114114
amt = 10,
115115
time = c(1, 2, 3, 4),

0 commit comments

Comments
 (0)