Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RXR-1926 implement infusion duration scaling #92

Merged
merged 12 commits into from
Apr 3, 2024
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(advan)
export(advan_create_data)
export(advan_parse_output)
export(advan_process_infusion_doses)
export(apply_duration_scale)
export(apply_lagtime)
export(calc_auc_analytic)
export(calc_ss_analytic)
Expand Down
47 changes: 47 additions & 0 deletions R/apply_duration_scale.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#' Apply infusion duration scale to a regimen
#'
#' E.g. see Centanni et al. Clin Pharmacokinet 2024. An estimated scaling factor
#' for the length of the infusion was applied there in a model for vincristine.
#' This is likely most relevant for very short infusions.
#'
#' Implementation is similar to handling of `lagtime`, i.e. the regimen that is the
#' input for the simulation function is updated.
#'
#' @param regimen PKPDsim regimen
#' @param duration_scale infusion length scale.
#' @param parameters parameter list, required if the duration scale is
#' specified as a parameter.
#'
#' @export
#'
#' @return Original regimen with infusion lengths scaled by a factor
#'
apply_duration_scale <- function(
regimen,
duration_scale = NULL,
parameters = NULL
) {
if(is.null(regimen$t_inf) || all(regimen$t_inf == 0)) {
warning("`duration_scale` is only relevant for infusion regimens with an infusion length > 0.")
return(regimen)
}
if(!is.null(duration_scale)) {
if(class(duration_scale) %in% c("numeric", "integer")) {
if(length(duration_scale) == 1) {
regimen$t_inf <- regimen$t_inf * duration_scale
} else {
regimen$t_inf <- regimen$t_inf * duration_scale[regimen$cmt]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
regimen$t_inf <- regimen$t_inf * duration_scale[regimen$cmt]
regimen$t_inf <- regimen$t_inf * duration_scale[regimen$type]

does it make more sense to use the type argument since i think that is how we tend to differentiate doses of different types (which go to different compartments)

Copy link
Contributor Author

@roninsightrx roninsightrx Apr 2, 2024

Choose a reason for hiding this comment

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

Sorry, I misread my earlier code. That 5 lines of code I removed is actually useful, at least when we're using a vector of duration scales that matches cmts, which we do. The removed code ensures there is always a cmt in the regimen, even when not specified by the user. So will bring that code back. I think it is OK where it is, and doesn't need to go on top of the function, since we only want to make a modification to the regimen if its actually needed, IMO.

Regarding your 2nd question whether we should link it to type rather than cmt: I think it's less consistent to link it to type: we now have "lagtime" also linked to a specific cmt, not to an observation type. I see lagtime and duration scale as two very similar features. Also in NONMEM durations and infusion lengths are linked to compartments, so for most users more intuitive. An option for a future ticket could be that lagtime and duration_scale could also be specified as a list, where they then indeed can be mapped to observation types.

}
} else if(class(duration_scale) %in% c("character")) {
if(length(duration_scale) == 1) {
regimen$t_inf <- regimen$t_inf * parameters[[duration_scale]]
} else {
par_tmp <- parameters
regimen$t_inf <- regimen$t_inf + as.numeric(unlist(par_tmp[duration_scale[regimen$cmt]]))
}
}
} else {
warning("Please specify `duration_scale` to apply to regimen.")
}
return(regimen)
}
1 change: 1 addition & 0 deletions R/new_ode_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ new_ode_model <- function (model = NULL,
"\\[COVS\\]", covs,
"\\[FIXED\\]", fixed,
"\\[LAGTIME\\]", lagtime,
"\\[DURATION_SCALE\\]", deparse(dose$duration_scale),
"\\[USE_IOV\\]", as.character(use_iov),
"\\[IOV\\]", PKPDsim::print_list(iov, FALSE),
"\\[DEVELOPMENT\\]", print_list(development, FALSE),
Expand Down
8 changes: 8 additions & 0 deletions R/sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ sim <- function (ode = NULL,
if(!is.null(lagtime)) {
regimen <- apply_lagtime(regimen, lagtime, parameters, attr(ode, "cmt_mapping"))
}
if(!is.null(attr(ode, "dose")$duration_scale)) {
regimen <- apply_duration_scale(
regimen,
attr(ode, "dose")$duration_scale,
parameters,
attr(ode, "cmt_mapping")
jasmineirx marked this conversation as resolved.
Show resolved Hide resolved
)
}
if(t_init != 0) regimen$dose_times <- regimen$dose_times + t_init
p <- as.list(parameters)
if(!is.null(t_obs)) {
Expand Down
7 changes: 6 additions & 1 deletion inst/template/R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ model <- function(mod = NULL) {
attr(ret, "cpp") <- TRUE
attr(ret, "size") <- [N_COMP]
attr(ret, "obs") <- list("cmt" = [OBS_COMP], "scale" = "[OBS_SCALE]", "variable" = [OBS_VARIABLE])
attr(ret, "dose") <- list("cmt" = [DOSE_COMP], "bioav" = [DOSE_BIOAV], "duplicate" = [DOSE_DUPLICATE] )
attr(ret, "dose") <- list(
"cmt" = [DOSE_COMP],
"bioav" = [DOSE_BIOAV],
"duplicate" = [DOSE_DUPLICATE],
"duration_scale" = [DURATION_SCALE]
)
attr(ret, "code") <- "[CODE]"
attr(ret, "pk_code") <- "[PK_CODE]"
attr(ret, "state_init") <- [STATE_INIT]
Expand Down
28 changes: 28 additions & 0 deletions man/apply_duration_scale.Rd

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

49 changes: 49 additions & 0 deletions tests/testthat/test_apply_duration_scale.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
reg_oral <- new_regimen(
amt = 1000,
n = 12,
interval = 12,
type = "oral"
)
reg_iv <- new_regimen(
amt = 1000,
n = 12,
interval = 12,
type = "infusion",
t_inf = 1
)

## null / error checks
test_that("infusion length NULL warning", {
expect_warning(
dur0 <- apply_duration_scale(
regimen = reg_oral
)
)
expect_equal(dur0, reg_oral)
})
test_that("duration scale NULL warning", {
expect_warning(
dur1 <- apply_duration_scale(
regimen = reg_iv
)
)
expect_equal(dur1, reg_iv)
})

## Check functionality
test_that("infusion length scaled", {
dur2 <- apply_duration_scale(
regimen = reg_iv,
duration_scale = 1.5
)
expect_equal(dur2$t_inf, rep(1.5, 12))
})

test_that("infusion length scaled using parameter", {
dur3 <- apply_duration_scale(
regimen = reg_iv,
duration_scale = "SCALE",
parameters = list(CL = 5, V = 50, SCALE = 1.6)
)
expect_equal(dur3$t_inf, rep(1.6, 12))
})
Loading