Time above MIC (R function) [🇷 for BE/BA]

posted by Aceto81 – Belgium, 2008-08-13 13:19 (5706 d 02:32 ago) – Posting: # 2176
Views: 32,415

Dear Helmut,

I changed the function radically, so here is version 2, with the data you provided (BLQ was changed to NA):

dat <- structure(list(time = c(0, 0.5167, 1, 1.5, 2, 2.5, 3, 3.5, 4,
                               4.5, 5, 6, 9, 12.0333, 16.0167, 24.05),
                      conc = c(NA, NA, 1.144, 2.399, 3.226, 3.236, 2.943,
                               2.776, 3.393, 4.536, 3.934, 3.387, 1.643,
                               0.717, 0.231, NA)),
                      .Names = c("time", "conc"),
                      class = "data.frame", row.names = c(NA, -16L))
f2 <- function(dat,th,logarithmic=FALSE) {
  above = 0
  w <- dat$conc > th
  w[w == FALSE] <- 0
  w[w == TRUE] <- 1
  w2 <- which(abs(diff(w)) == 1)
  if (logarithmic == FALSE) {
    for (i in w2) {
      n1 <- diff(w)[i] * -1*(dat$time[i+1] + ((dat$time[i]-dat$time[i+1]) *
            (th-dat$conc[i+1])/(dat$conc[i]-dat$conc[i+1])))
      above <- above + n1
    }
  }
  if (logarithmic == TRUE) {
    for (i in w2) {
      if (diff(w)[i] == 1) {
        n1 <- (dat$time[i+1] + ((dat$time[i]-dat$time[i+1]) *
              (th-dat$conc[i+1])/(dat$conc[i]-dat$conc[i+1])))
        above <- above - n1
      }
      if (diff(w)[i] == -1) {
        n1 <- (dat$time[i+1] + ((dat$time[i]-dat$time[i+1]) *
              (log(th)-log(dat$conc[i+1]))/(log(dat$conc[i])-log(dat$conc[i+1]))))
        above <- above + n1
      }
    }
  }
  return(above)
}

f2(dat, th = 2.268, logarithmic = TRUE)


Best regards

Ace

Complete thread:

UA Flag
Activity
 Admin contact
22,957 posts in 4,819 threads, 1,638 registered users;
82 visitors (0 registered, 82 guests [including 9 identified bots]).
Forum time: 14:51 CET (Europe/Vienna)

Nothing shows a lack of mathematical education more
than an overly precise calculation.    Carl Friedrich Gauß

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5