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

posted by Aceto81 – Belgium, 2008-08-13 13:19 (5957 d 13:59 ago) – Posting: # 2176
Views: 34,582

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,332 posts in 4,899 threads, 1,660 registered users;
21 visitors (0 registered, 21 guests [including 7 identified bots]).
Forum time: 02:19 CET (Europe/Vienna)

I don’t write drafts.
I write from the beginning to the end,
and when it’s finished, it’s done.    Clifford Geertz

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