Skip to content
Open
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
17 changes: 17 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,23 @@ the generated intervals:

## Bug fixes

* `aucint.inf.obs`, `aucint.inf.pred`, `aumcint.inf.obs`, and
`aumcint.inf.pred` now give a `pknca_warning_aucint_halflife_missing`
warning, naming the parameter, whenever they need the half-life and it is
missing (#450, @billdenney). No value changes:
* over a finite interval that ends after Tlast, the value is that of
`aucint.all` (or `aumcint.all`), as it has been since the AUCall fallback
of #508; it equals the AUClast-based value unless a concentration below
the limit of quantification follows Tlast;
* over an interval to infinity, the value is `NA`, as before, because there
is no finite fallback;
* when the interval starts at a dose without a concentration measured
there, the concentration at the start is past the Tlast of the profile
before the dose and would be extrapolated with the half-life; without
one, the value is the one it was.
An interval that ends at or before Tlast and needs no concentration from the
profile before a dose does not need the half-life and gives no warning.

* Preferred units (`concu_pref`, `doseu_pref`, and the others) with unit
columns whose units differ between groups no longer stop `PKNCAdata()` with
"arguments imply differing number of rows: 1, 0" when some groups are
Expand Down
201 changes: 165 additions & 36 deletions R/aucint.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#' \item{`AUCinf`}{is extrapolated with `lambda.z` (in other words, with the
#' half-life), always using the logarithmic trapezoidal rule to align with
#' the exponential decay that the half-life describes. When `lambda.z` is
#' not estimable and the interval is finite, `AUCall` is used instead.}
#' not estimable and the interval is finite, `AUCall` is used instead;
#' over an interval to infinity there is no finite fallback, and the
#' result is `NA`.}
#' }
#'
#' When the interval ends at or before Tlast, no extrapolation happens and
Expand All @@ -43,6 +45,13 @@
#' ends. The extrapolation that was used is reported in the method (`PPANMETH`)
#' column.
#'
#' Whenever `AUCinf` needs `lambda.z` and it is not estimable (after Tlast, over
#' an interval to infinity, or for that concentration at `start`), a
#' `pknca_warning_aucint_halflife_missing` warning says so; the
#' `aucint.inf.*` and `aumcint.inf.*` parameters give it with their own name.
#' Their value is that of `aucint.all` (or `aumcint.all`) over a finite
#' interval, and `NA` over an interval to infinity.
#'
#' # The time origin of the AUMC
#'
#' The AUMC is weighted by the time since `start`, which is what `aumclast`
Expand Down Expand Up @@ -175,10 +184,12 @@ pk.calc.auxcint <- function(conc, time,
} else if (is.na(lambda.z)) {
if (is.infinite(interval[2])) {
# Without a half-life there is no finite tail to fall back to
aucint_signal_halflife_missing("infinite")
return(structure(NA_real_, exclude = "the half-life is NA"))
}
# With no estimable half-life, the tail of the interval is the AUCall
# triangle instead (#508)
aucint_signal_halflife_missing("after_tlast")
auc_type_calc <- "AUCall"
} else {
lambda_z_used <- TRUE
Expand Down Expand Up @@ -260,6 +271,12 @@ pk.calc.auxcint <- function(conc, time,
...
)
mask_start <- missing_times == interval[1]
if (auc.type %in% "AUCinf" && !extrapolates && is.na(lambda.z) &&
"Extrapolation" %in% attr(missing_conc, "Method")[mask_start]) {
# The concentration at `start` is past the Tlast of the profile before
# the dose, where the half-life would extrapolate it (below)
aucint_signal_halflife_missing("start")
}
if (auc.type %in% "AUCinf" && !extrapolates && !is.na(lambda.z) && any(mask_start)) {
# The concentration at `start` may be extrapolated from the profile
# before a dose (the trough before the dose that starts the interval).
Expand Down Expand Up @@ -364,7 +381,7 @@ pk.calc.auxcint <- function(conc, time,
} else if (!extrapolates) {
"none"
} else if (auc.type %in% "AUCinf") {
"AUCall (half-life not estimable)"
pknca_extrap_method_halflife_missing
} else {
auc.type
}
Expand Down Expand Up @@ -394,6 +411,84 @@ pk.calc.auxcint <- function(conc, time,
# spelling it out.
pknca_extrap_method_prefix <- "Extrapolation: "
pknca_extrap_method_halflife <- "half-life"
# An AUCinf-based AUCint whose interval reaches past Tlast without a half-life:
# the region after Tlast is the AUCall one
pknca_extrap_method_halflife_missing <- "AUCall (half-life not estimable)"

#' Say that an AUCinf-based AUCint needed the half-life and it is missing
#'
#' [pk.calc.aumcint()] gives the warning again for the AUMC, and the
#' `aucint.inf.*` and `aumcint.inf.*` parameters give it again with their own
#' name (see `aucint_rename_halflife_missing()`).
#'
#' @param reason Where the half-life was needed: `"after_tlast"` (a finite
#' interval past Tlast, which is then calculated as the AUCall-based one
#' is), `"infinite"`
#' (an interval to infinity, which is then `NA`), or `"start"` (the
#' concentration at the start of the interval, past the Tlast of the profile
#' before the dose)
#' @returns `NULL`, after a `pknca_warning_aucint_halflife_missing` warning
#' whose `halflife_missing` field is `reason`
#' @keywords Internal
#' @noRd
aucint_signal_halflife_missing <- function(reason) {
rlang::warn(
aucint_halflife_missing_message(reason = reason, parameter = "The AUCinf-based AUCint", parameter_all = "the AUCall-based one"),
class = "pknca_warning_aucint_halflife_missing",
halflife_missing = reason
)
}

#' The message of a `pknca_warning_aucint_halflife_missing` warning
#'
#' @inheritParams aucint_signal_halflife_missing
#' @param parameter,parameter_all The parameter calculated and the AUCall-based
#' one it is then calculated as
#' @returns The message. The `"after_tlast"` message says how the value is
#' calculated, not what it is: the warning is given before the value is
#' known, and the value can still be `NA` for another reason (for example a
#' concentration at the start of the interval that cannot be estimated).
#' @keywords Internal
#' @noRd
aucint_halflife_missing_message <- function(reason, parameter, parameter_all) {
switch(
reason,
after_tlast =
sprintf(
"%s: the half-life is missing, so the part of the interval after Tlast is not extrapolated with it, and the result is calculated as %s is",
parameter, parameter_all
),
infinite =
sprintf(
"%s: the half-life is missing, and an interval to infinity has no finite fallback, so NA is returned",
parameter
),
start =
sprintf(
"%s: the half-life is missing, so the concentration at the start of the interval (past the Tlast of the profile before the dose) is not extrapolated with the half-life",
parameter
)
)
}

#' Give a `pknca_warning_aucint_halflife_missing` warning again with the name
#' of the parameter
#'
#' A calling handler for the warning from [pk.calc.auxcint()].
#'
#' @param cnd The warning
#' @inheritParams aucint_halflife_missing_message
#' @returns Nothing: the warning is muffled after it is given again
#' @keywords Internal
#' @noRd
aucint_rename_halflife_missing <- function(cnd, parameter, parameter_all) {
rlang::warn(
aucint_halflife_missing_message(reason = cnd$halflife_missing, parameter = parameter, parameter_all = parameter_all),
class = "pknca_warning_aucint_halflife_missing",
halflife_missing = cnd$halflife_missing
)
invokeRestart("muffleWarning")
}

#' @describeIn pk.calc.auxcint Calculate AUC over an interval
#' @export
Expand Down Expand Up @@ -451,13 +546,20 @@ pk.calc.aucint.inf.obs <- function(conc, time, start=NULL, end=NULL, time.dose,
..., options=list()) {
if (missing(time.dose))
time.dose <- NULL
pk.calc.aucint(conc=conc, time=time,
start=start, end=end,
time.dose=time.dose,
route=route, duration.dose=duration.dose,
lambda.z=lambda.z, clast=clast.obs,
options=options, ...,
auc.type="AUCinf")
withCallingHandlers(
pk.calc.aucint(
conc = conc, time = time,
start = start, end = end,
time.dose = time.dose,
route = route, duration.dose = duration.dose,
lambda.z = lambda.z, clast = clast.obs,
options = options, ...,
auc.type = "AUCinf"
),
pknca_warning_aucint_halflife_missing = function(cnd) {
aucint_rename_halflife_missing(cnd, parameter = "aucint.inf.obs", parameter_all = "aucint.all")
}
)
}

pknca_concept(pk.calc.aucint.inf.obs) <- "auc"
Expand All @@ -470,13 +572,20 @@ pk.calc.aucint.inf.pred <- function(conc, time, start=NULL, end=NULL, time.dose,
if (missing(time.dose)) {
time.dose <- NULL
}
pk.calc.aucint(conc=conc, time=time,
start=start, end=end,
time.dose=time.dose,
route=route, duration.dose=duration.dose,
lambda.z=lambda.z, clast=clast.pred,
options=options, ...,
auc.type="AUCinf")
withCallingHandlers(
pk.calc.aucint(
conc = conc, time = time,
start = start, end = end,
time.dose = time.dose,
route = route, duration.dose = duration.dose,
lambda.z = lambda.z, clast = clast.pred,
options = options, ...,
auc.type = "AUCinf"
),
pknca_warning_aucint_halflife_missing = function(cnd) {
aucint_rename_halflife_missing(cnd, parameter = "aucint.inf.pred", parameter_all = "aucint.all")
}
)
}

pknca_concept(pk.calc.aucint.inf.pred) <- "auc"
Expand Down Expand Up @@ -544,12 +653,18 @@ add.interval.col("aucint.inf.pred",
#' @describeIn pk.calc.auxcint Calculate AUMC over an interval
#' @export
pk.calc.aumcint <- function(conc, time, ..., options=list()) {
pk.calc.auxcint(
conc = conc, time = time, ...,
options = options,
fun_linear = aumcintegrate_linear,
fun_log = aumcintegrate_log,
fun_inf = aumcintegrate_inf
# pk.calc.auxcint() names the AUC in its warning; this is the AUMC
withCallingHandlers(
pk.calc.auxcint(
conc = conc, time = time, ...,
options = options,
fun_linear = aumcintegrate_linear,
fun_log = aumcintegrate_log,
fun_inf = aumcintegrate_inf
),
pknca_warning_aucint_halflife_missing = function(cnd) {
aucint_rename_halflife_missing(cnd, parameter = "The AUMCinf-based AUMCint", parameter_all = "the AUMCall-based one")
}
)
}

Expand Down Expand Up @@ -599,13 +714,20 @@ pk.calc.aumcint.inf.obs <- function(conc, time, start=NULL, end=NULL, time.dose,
..., options=list()) {
if (missing(time.dose))
time.dose <- NULL
pk.calc.aumcint(conc=conc, time=time,
start=start, end=end,
time.dose=time.dose,
route=route, duration.dose=duration.dose,
lambda.z=lambda.z, clast=clast.obs,
options=options, ...,
auc.type="AUCinf")
withCallingHandlers(
pk.calc.aumcint(
conc = conc, time = time,
start = start, end = end,
time.dose = time.dose,
route = route, duration.dose = duration.dose,
lambda.z = lambda.z, clast = clast.obs,
options = options, ...,
auc.type = "AUCinf"
),
pknca_warning_aucint_halflife_missing = function(cnd) {
aucint_rename_halflife_missing(cnd, parameter = "aumcint.inf.obs", parameter_all = "aumcint.all")
}
)
}

pknca_concept(pk.calc.aumcint.inf.obs) <- "aumc"
Expand All @@ -618,13 +740,20 @@ pk.calc.aumcint.inf.pred <- function(conc, time, start=NULL, end=NULL, time.dose
..., options=list()) {
if (missing(time.dose))
time.dose <- NULL
pk.calc.aumcint(conc=conc, time=time,
start=start, end=end,
time.dose=time.dose,
route=route, duration.dose=duration.dose,
lambda.z=lambda.z, clast=clast.pred,
options=options, ...,
auc.type="AUCinf")
withCallingHandlers(
pk.calc.aumcint(
conc = conc, time = time,
start = start, end = end,
time.dose = time.dose,
route = route, duration.dose = duration.dose,
lambda.z = lambda.z, clast = clast.pred,
options = options, ...,
auc.type = "AUCinf"
),
pknca_warning_aucint_halflife_missing = function(cnd) {
aucint_rename_halflife_missing(cnd, parameter = "aumcint.inf.pred", parameter_all = "aumcint.all")
}
)
}

pknca_concept(pk.calc.aumcint.inf.pred) <- "aumc"
Expand Down
11 changes: 10 additions & 1 deletion man/pk.calc.auxcint.Rd

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

Loading
Loading