Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions R/regimen_to_nm.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion man/adherence_binomial.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/adherence_markov.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/new_adherence.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/regimen_to_nm.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions tests/testthat/test_regimen_to_nm.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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", {
Expand All @@ -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(
{
Expand All @@ -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",
Expand All @@ -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", {
Expand All @@ -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),
Expand Down