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

posted by Aceto81 – Belgium, 2008-08-13 13:19 (6154 d 23:35 ago) – Posting: # 2176
Views: 36,796

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
23,424 posts in 4,927 threads, 1,676 registered users;
38 visitors (1 registered, 37 guests [including 9 identified bots]).
Forum time: 12:54 CEST (Europe/Vienna)

Complex, statistically improbable things are by their nature
more difficult to explain than
simple, statistically probable things.    Richard Dawkins

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