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

posted by Aceto81 – Belgium, 2008-08-13 13:19 (5727 d 15:57 ago) – Posting: # 2176
Views: 32,645

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,987 posts in 4,824 threads, 1,669 registered users;
74 visitors (0 registered, 74 guests [including 3 identified bots]).
Forum time: 05:17 CEST (Europe/Vienna)

The only way to comprehend what mathematicians mean by Infinity
is to contemplate the extent of human stupidity.    Voltaire

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