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

Feature request: New logslope & c1 impute_start methods #350 #351

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Gero1999
Copy link
Contributor

@Gero1999 Gero1999 commented Jan 3, 2025

New PKNCA_method_start functions that could perhaps be default/standard. Feel free to give them a look and merge them if they are useful!

Closes #350

# Imputes a start concentration based on the logslope method for IV bolus
PKNCA_impute_method_start_logslope <- function(conc, time, start, end, ..., options = list()) { # nolint

  ret <- data.frame(conc = conc, time = time)
  mask_start <- time %in% start
  if (!any(mask_start)) {
    all_concs <- conc[time >= start  &  time <= end]
    all_times <- time[time >= start  &  time <= end]
    if (!all(is.na(all_concs))) {
      c0 <- PKNCA::pk.calc.c0(all_concs, all_times, method = "logslope")
      if (!is.na(c0)) {
        ret <- rbind(ret, data.frame(time = start, conc = c0))
        ret <- ret[order(ret$time), ]
      }
    }
  }
  ret
}

# Imputes a start concentration using the first available concentration measure
PKNCA_impute_method_start_c1 <- function(conc, time, start, end, ..., options = list()) { # nolint
  ret <- data.frame(conc = conc, time = time)
  mask_start <- time %in% start
  if (!any(mask_start)) {
    all_concs <- conc[time >= start  &  time <= end]
    all_times <- time[time >= start  &  time <= end]
    if (!all(is.na(all_concs))) {
      c1 <- all_concs[which.min(all_times)]
      ret <- rbind(ret, data.frame(time = start, conc = c1))
      ret <- ret[order(ret$time), ]
    }
  }
  ret
}

@Gero1999 Gero1999 marked this pull request as ready for review January 3, 2025 17:03
all_concs <- conc[time >= start & time <= end]
all_times <- time[time >= start & time <= end]
if (!all(is.na(all_concs))) {
c0 <- PKNCA::pk.calc.c0(all_concs, all_times, method = "logslope")
Copy link
Owner

Choose a reason for hiding this comment

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

Since this is within PKNCA, please switch to the pk.calc.c0.method.logslope function directly rather than using pk.calc.c0.

@@ -120,6 +120,46 @@ PKNCA_impute_method_start_predose <- function(conc, time, start, end, conc.group
ret
}

#' @describeIn PKNCA_impute_method Imputes based on a logarithmic slope on the
#' first points a time zero concentration (usually in IV bolus at dose time)
Copy link
Owner

Choose a reason for hiding this comment

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

Please add an additional part to the description: "If this imputation is used for NCA calculations, back-extrapolation percent will not be calculated or will be calculated as zero."

}

#' @describeIn PKNCA_impute_method Shift the following concentration to a start
#' to become the time zero concentration (rarely used; non-monodecay IV bolus)
Copy link
Owner

Choose a reason for hiding this comment

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

Please add an additional part to the description: "If this imputation is used for NCA calculations, back-extrapolation percent will not be calculated or will be calculated as zero."

all_concs <- conc[time >= start & time <= end]
all_times <- time[time >= start & time <= end]
if (!all(is.na(all_concs))) {
c0 <- PKNCA::pk.calc.c0(all_concs, all_times, method = "logslope")
Copy link
Owner

Choose a reason for hiding this comment

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

Please set time.dose = start in case the intended start time is not 0. Please add a test for this case as well.

ret <- data.frame(conc = conc, time = time)
mask_start <- time %in% start
if (!any(mask_start)) {
all_concs <- conc[time >= start & time <= end]
Copy link
Owner

Choose a reason for hiding this comment

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

Please use pk.calc.c0.method.c1. That way, you don't need to filter all_concs, all_times, and your is.na() test below can be on c1. That will also ensure that c1 is consistently calculated anywhere it is used within PKNCA.

data.frame(conc = c(3, 3, 1), time = 1:3),
ignore_attr = TRUE
)
})
Copy link
Owner

Choose a reason for hiding this comment

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

Please add tests for:

  1. All concentrations are NA
  2. All times are NA
  3. All concentrations are 0

(I see that list of tests is needed for the other imputation methods, too. I just added an issue, #361, to add those after this PR is merged.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: New logslope & c1 impute_start methods
2 participants