R/nca_trapezoid.R

Defines functions nca_trapezoid

Documented in nca_trapezoid

#' NCA core function to perform log-linear trapezoid calculations for post-infusion
#'
#' @param data dataset passed from nca() with `time` and `dv` columns
#'
nca_trapezoid <- function(data) {
  data <- data[!duplicated(data$time),]
  enum <- diff(data$time) * (diff(data$dv))
  denom <- log(data$dv[2:length(data$dv)] / data$dv[1:(length(data$dv)-1)])
  if(any(denom == 0)) {
    idx <- denom != 0
    data$dt <- c(diff(data$time), 0)
    sum(enum[idx] / denom[idx]) + sum(data$dv[!idx] * data$dt[!idx])
  } else {
    sum(enum / denom)
  }
}

Try the clinPK package in your browser

Any scripts or data that you put into this service are public.

clinPK documentation built on May 9, 2022, 9:06 a.m.