# Wambaugh et al. (2018): Creating All Figures

#### John Wambaugh

#### 2020-09-24

This vignette provides the code used to generate the figures in Wambaugh et al. (2018) “Evaluating In Vitro-In Vivo Extrapolation of Toxicokinetics”

John F Wambaugh, Michael F Hughes, Caroline L Ring, Denise K MacMillan, Jermaine Ford, Timothy R Fennell, Sherry R Black, Rodney W Snyder, Nisha S Sipes, Barbara A Wetmore, Joost Westerhout, R Woodrow Setzer, Robert G Pearce, Jane Ellen Simmons, Russell S Thomas

Toxicological Sciences, Volume 163, Issue 1, May 2018, Pages 152-169,

https://doi.org/10.1093/toxsci/kfy020

## Abstract

Prioritizing the risk posed by thousands of chemicals potentially present in the environment requires exposure, toxicity, and toxicokinetic (TK) data, which are often unavailable. Relatively high throughput, in vitro TK (HTTK) assays and in vitro-to-in vivo extrapolation (IVIVE) methods have been developed to predict TK, but most of the in vivo TK data available to benchmark these methods are from pharmaceuticals. Here we report on new, in vivo rat TK experiments for 26 non-pharmaceutical chemicals with environmental relevance. Both intravenous and oral dosing were used to calculate bioavailability. These chemicals, and an additional 19 chemicals (including some pharmaceuticals) from previously published in vivo rat studies, were systematically analyzed to estimate in vivo TK parameters (e.g., volume of distribution [Vd], elimination rate). For each of the chemicals, rat-specific HTTK data were available and key TK predictions were examined: oral bioavailability, clearance, Vd, and uncertainty. For the non-pharmaceutical chemicals, predictions for bioavailability were not effective. While no pharmaceutical was absorbed at less than 10%, the fraction bioavailable for non-pharmaceutical chemicals was as low as 0.3%. Total clearance was generally more under-estimated for nonpharmaceuticals and Vd methods calibrated to pharmaceuticals may not be appropriate for other chemicals. However, the steady-state, peak, and time-integrated plasma concentrations of non-pharmaceuticals were predicted with reasonable accuracy. The plasma concentration predictions improved when experimental measurements of bioavailability were incorporated. In summary, HTTK and IVIVE methods are adequately robust to be applied to high throughput in vitro toxicity screening data of environmentally relevant chemicals for prioritizing based on human health risks.

To use the code in this vignette, you’ll first need to load a few packages.

    # We love to give warning messages whenever assumptions are used by HTTK,
    # but they will overwhelm the output of this vignette so we turn them
    # off:
    options(warn = -1)
    library(scales)
    library(ggplot2)
    library(data.table)
    library(gdata)
    library(gtools)
    library(httk)
    library(RColorBrewer)
    library(grid)
    library(gplots)

The data we analyze were originally generated with the R package invivoPKfit (https://github.com/USEPA/CompTox-ExpoCast-invivoPKfit), but all the outputs of that analysis are provided with httk >v1.8.

# Plot functions

These functions, which have been cobbled togethe from the internet, are reused in multiple figure to make things look nice.

    # Multiple plot function
    #
    # ggplot objects can be passed in ..., or to plotlist (as a list of ggplot objects)
    # - cols:   Number of columns in layout
    # - layout: A matrix specifying the layout. If present, 'cols' is ignored.
    #
    # If the layout is something like matrix(c(1,2,3,3), nrow=2, byrow=TRUE),
    # then plot 1 will go in the upper left, 2 will go in the upper right, and
    # 3 will go all the way across the bottom.
    #
    multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL, widths=unit(rep_len(1, cols), "null")) {

      # Make a list from the ... arguments and plotlist
      plots <- c(list(...), plotlist)

      numPlots = length(plots)

      # If layout is NULL, then use 'cols' to determine layout
      if (is.null(layout)) {
        # Make the panel
        # ncol: Number of columns of plots
        # nrow: Number of rows needed, calculated from # of cols
        layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                        ncol = cols, nrow = ceiling(numPlots/cols))
      }

     if (numPlots==1) {
        print(plots[[1]])

      } else {
        # Set up the page
        grid.newpage()
        pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout),widths=widths)))

        # Make each plot, in the correct location
        for (i in 1:numPlots) {
          # Get the i,j matrix positions of the regions that contain this subplot
          matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))

          print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                          layout.pos.col = matchidx$col))
        }
      }
    }

    scientific_10 <- function(x) {
      out <- gsub("1e", "10^", scientific_format()(x))
      out <- gsub("\\+","",out)
      out <- gsub("10\\^01","10",out)
      out <- parse(text=gsub("10\\^00","1",out))
    }

    lm_R2 <- function(m,prefix=NULL){
        out <- substitute("MSE = "~mse*","~~italic(R)^2~"="~r2,
             list(mse = signif(mean(m$residuals^2),3),
                  r2 = format(summary(m)$adj.r.squared, digits = 2)))
        paste(prefix,as.character(as.expression(out)))
    }

    heatmap.3 <- function(x,
                          Rowv = TRUE, Colv = if (symm) "Rowv" else TRUE,
                          distfun = dist,
                          hclustfun = hclust,
                          dendrogram = c("both","row", "column", "none"),
                          symm = FALSE,
                          scale = c("none","row", "column"),
                          na.rm = TRUE,
                          revC = identical(Colv,"Rowv"),
                          add.expr,
                          breaks,
                          symbreaks = max(x < 0, na.rm = TRUE) || scale != "none",
                          col = "heat.colors",
                          colsep,
                          rowsep,
                          sepcolor = "white",
                          sepwidth = c(0.05, 0.05),
                          cellnote,
                          notecex = 1,
                          notecol = "cyan",
                          na.color = par("bg"),
                          trace = c("none", "column","row", "both"),
                          tracecol = "cyan",
                          hline = median(breaks),
                          vline = median(breaks),
                          linecol = tracecol,
                          margins = c(5,5),
                          ColSideColors,
                          RowSideColors,
                          side.height.fraction=0.3,
                          cexRow = 0.2 + 1/log10(nr),
                          cexCol = 0.2 + 1/log10(nc),
                          labRow = NULL,
                          labCol = NULL,
                          key = TRUE,
                          keysize = 1.5,
                          density.info = c("none", "histogram", "density"),
                          denscol = tracecol,
                          symkey = max(x < 0, na.rm = TRUE) || symbreaks,
                          densadj = 0.25,
                          main = NULL,
                          xlab = NULL,
                          ylab = NULL,
                          lmat = NULL,
                          lhei = NULL,
                          lwid = NULL,
                          ColSideColorsSize = 1,
                          RowSideColorsSize = 1,
                          KeyValueName="Value",...){

        invalid <- function (x) {
          if (missing(x) || is.null(x) || length(x) == 0)
              return(TRUE)
          if (is.list(x))
              return(all(sapply(x, invalid)))
          else if (is.vector(x))
              return(all(is.na(x)))
          else return(FALSE)
        }

        x <- as.matrix(x)
        scale01 <- function(x, low = min(x), high = max(x)) {
            x <- (x - low)/(high - low)
            x
        }
        retval <- list()
        scale <- if (symm && missing(scale))
            "none"
        else match.arg(scale)
        dendrogram <- match.arg(dendrogram)
        trace <- match.arg(trace)
        density.info <- match.arg(density.info)
        if (length(col) == 1 && is.character(col))
            col <- get(col, mode = "function")
        if (!missing(breaks) && (scale != "none"))
            warning("Using scale=\"row\" or scale=\"column\" when breaks are",
                "specified can produce unpredictable results.", "Please consider using only one or the other.")
        if (is.null(Rowv) || is.na(Rowv))
            Rowv <- FALSE
        if (is.null(Colv) || is.na(Colv))
            Colv <- FALSE
        else if (Colv == "Rowv" && !isTRUE(Rowv))
            Colv <- FALSE
        if (length(di <- dim(x)) != 2 || !is.numeric(x))
            stop("`x' must be a numeric matrix")
        nr <- di[1]
        nc <- di[2]
        if (nr <= 1 || nc <= 1)
            stop("`x' must have at least 2 rows and 2 columns")
        if (!is.numeric(margins) || length(margins) != 2)
            stop("`margins' must be a numeric vector of length 2")
        if (missing(cellnote))
            cellnote <- matrix("", ncol = ncol(x), nrow = nrow(x))
        if (!inherits(Rowv, "dendrogram")) {
            if (((!isTRUE(Rowv)) || (is.null(Rowv))) && (dendrogram %in%
                c("both", "row"))) {
                if (is.logical(Colv) && (Colv))
                    dendrogram <- "column"
                else dedrogram <- "none"
                warning("Discrepancy: Rowv is FALSE, while dendrogram is `",
                    dendrogram, "'. Omitting row dendogram.")
            }
        }
        if (!inherits(Colv, "dendrogram")) {
            if (((!isTRUE(Colv)) || (is.null(Colv))) && (dendrogram %in%
                c("both", "column"))) {
                if (is.logical(Rowv) && (Rowv))
                    dendrogram <- "row"
                else dendrogram <- "none"
                warning("Discrepancy: Colv is FALSE, while dendrogram is `",
                    dendrogram, "'. Omitting column dendogram.")
            }
        }
        if (inherits(Rowv, "dendrogram")) {
            ddr <- Rowv
            rowInd <- order.dendrogram(ddr)
        }
        else if (is.integer(Rowv)) {
            hcr <- hclustfun(distfun(x))
            ddr <- as.dendrogram(hcr)
            ddr <- reorder(ddr, Rowv)
            rowInd <- order.dendrogram(ddr)
            if (nr != length(rowInd))
                stop("row dendrogram ordering gave index of wrong length")
        }
        else if (isTRUE(Rowv)) {
            Rowv <- rowMeans(x, na.rm = na.rm)
            hcr <- hclustfun(distfun(x))
            ddr <- as.dendrogram(hcr)
            ddr <- reorder(ddr, Rowv)
            rowInd <- order.dendrogram(ddr)
            if (nr != length(rowInd))
                stop("row dendrogram ordering gave index of wrong length")
        }
        else {
            rowInd <- nr:1
        }
        if (inherits(Colv, "dendrogram")) {
            ddc <- Colv
            colInd <- order.dendrogram(ddc)
        }
        else if (identical(Colv, "Rowv")) {
            if (nr != nc)
                stop("Colv = \"Rowv\" but nrow(x) != ncol(x)")
            if (exists("ddr")) {
                ddc <- ddr
                colInd <- order.dendrogram(ddc)
            }
            else colInd <- rowInd
        }
        else if (is.integer(Colv)) {
            hcc <- hclustfun(distfun(if (symm)
                x
            else t(x)))
            ddc <- as.dendrogram(hcc)
            ddc <- reorder(ddc, Colv)
            colInd <- order.dendrogram(ddc)
            if (nc != length(colInd))
                stop("column dendrogram ordering gave index of wrong length")
        }
        else if (isTRUE(Colv)) {
            Colv <- colMeans(x, na.rm = na.rm)
            hcc <- hclustfun(distfun(if (symm)
                x
            else t(x)))
            ddc <- as.dendrogram(hcc)
            ddc <- reorder(ddc, Colv)
            colInd <- order.dendrogram(ddc)
            if (nc != length(colInd))
                stop("column dendrogram ordering gave index of wrong length")
        }
        else {
            colInd <- 1:nc
        }
        retval$rowInd <- rowInd
        retval$colInd <- colInd
        retval$call <- match.call()
        x <- x[rowInd, colInd]
        x.unscaled <- x
        cellnote <- cellnote[rowInd, colInd]
        if (is.null(labRow))
            labRow <- if (is.null(rownames(x)))
                (1:nr)[rowInd]
            else rownames(x)
        else labRow <- labRow[rowInd]
        if (is.null(labCol))
            labCol <- if (is.null(colnames(x)))
                (1:nc)[colInd]
            else colnames(x)
        else labCol <- labCol[colInd]
        if (scale == "row") {
            retval$rowMeans <- rm <- rowMeans(x, na.rm = na.rm)
            x <- sweep(x, 1, rm)
            retval$rowSDs <- sx <- apply(x, 1, sd, na.rm = na.rm)
            x <- sweep(x, 1, sx, "/")
        }
        else if (scale == "column") {
            retval$colMeans <- rm <- colMeans(x, na.rm = na.rm)
            x <- sweep(x, 2, rm)
            retval$colSDs <- sx <- apply(x, 2, sd, na.rm = na.rm)
            x <- sweep(x, 2, sx, "/")
        }
        if (missing(breaks) || is.null(breaks) || length(breaks) < 1) {
            if (missing(col) || is.function(col))
                breaks <- 16
            else breaks <- length(col) + 1
        }
        if (length(breaks) == 1) {
            if (!symbreaks)
                breaks <- seq(min(x, na.rm = na.rm), max(x, na.rm = na.rm),
                    length = breaks)
            else {
                extreme <- max(abs(x), na.rm = TRUE)
                breaks <- seq(-extreme, extreme, length = breaks)
            }
        }
        nbr <- length(breaks)
        ncol <- length(breaks) - 1
        if (class(col) == "function")
            col <- col(ncol)
        min.breaks <- min(breaks)
        max.breaks <- max(breaks)
        x[x < min.breaks] <- min.breaks
        x[x > max.breaks] <- max.breaks
        if (missing(lhei) || is.null(lhei))
            lhei <- c(keysize, 4)
        if (missing(lwid) || is.null(lwid))
            lwid <- c(keysize, 4)
        if (missing(lmat) || is.null(lmat)) {
            lmat <- rbind(4:3, 2:1)

            if (!missing(ColSideColors)) {
               #if (!is.matrix(ColSideColors))
               #stop("'ColSideColors' must be a matrix")
                if (!is.character(ColSideColors) || nrow(ColSideColors) != nc)
                    stop("'ColSideColors' must be a matrix of nrow(x) rows")
                lmat <- rbind(lmat[1, ] + 1, c(NA, 1), lmat[2, ] + 1)
                #lhei <- c(lhei[1], 0.2, lhei[2])
                 lhei=c(lhei[1], side.height.fraction*ColSideColorsSize/2, lhei[2])
            }

            if (!missing(RowSideColors)) {
                #if (!is.matrix(RowSideColors))
                #stop("'RowSideColors' must be a matrix")
                if (!is.character(RowSideColors) || ncol(RowSideColors) != nr)
                    stop("'RowSideColors' must be a matrix of ncol(x) columns")
                lmat <- cbind(lmat[, 1] + 1, c(rep(NA, nrow(lmat) - 1), 1), lmat[,2] + 1)
                #lwid <- c(lwid[1], 0.2, lwid[2])
                lwid <- c(lwid[1], side.height.fraction*RowSideColorsSize/2, lwid[2])
            }
            lmat[is.na(lmat)] <- 0
        }

        if (length(lhei) != nrow(lmat))
            stop("lhei must have length = nrow(lmat) = ", nrow(lmat))
        if (length(lwid) != ncol(lmat))
            stop("lwid must have length = ncol(lmat) =", ncol(lmat))
        op <- par(no.readonly = TRUE)
        on.exit(par(op))

        layout(lmat, widths = lwid, heights = lhei, respect = FALSE)

        if (!missing(RowSideColors)) {
            if (!is.matrix(RowSideColors)){
                    par(mar = c(margins[1], 0, 0, 0.5))
                    image(rbind(1:nr), col = RowSideColors[rowInd], axes = FALSE)
            } else {
                par(mar = c(margins[1], 0, 0, 0.5))
                rsc = t(RowSideColors[,rowInd, drop=F])
                rsc.colors = matrix()
                rsc.names = names(table(rsc))
                rsc.i = 1
                for (rsc.name in rsc.names) {
                    rsc.colors[rsc.i] = rsc.name
                    rsc[rsc == rsc.name] = rsc.i
                    rsc.i = rsc.i + 1
                }
                rsc = matrix(as.numeric(rsc), nrow = dim(rsc)[1])
                image(t(rsc), col = as.vector(rsc.colors), axes = FALSE)
                if (length(rownames(RowSideColors)) > 0) {
                    axis(1, 0:(dim(rsc)[2] - 1)/max(1,(dim(rsc)[2] - 1)), rownames(RowSideColors), las = 2, tick = FALSE)
                }
            }
        }

        if (!missing(ColSideColors)) {

            if (!is.matrix(ColSideColors)){
                par(mar = c(0.5, 0, 0, margins[2]))
                image(cbind(1:nc), col = ColSideColors[colInd], axes = FALSE)
            } else {
                par(mar = c(0.5, 0, 0, margins[2]))
                csc = ColSideColors[colInd, , drop=F]
                csc.colors = matrix()
                csc.names = names(table(csc))
                csc.i = 1
                for (csc.name in csc.names) {
                    csc.colors[csc.i] = csc.name
                    csc[csc == csc.name] = csc.i
                    csc.i = csc.i + 1
                }
                csc = matrix(as.numeric(csc), nrow = dim(csc)[1])
                image(csc, col = as.vector(csc.colors), axes = FALSE)
                if (length(colnames(ColSideColors)) > 0) {
                    axis(2, 0:(dim(csc)[2] - 1)/max(1,(dim(csc)[2] - 1)), colnames(ColSideColors), las = 2, tick = FALSE)
                }
            }
        }

        par(mar = c(margins[1], 0, 0, margins[2]))
        x <- t(x)
        cellnote <- t(cellnote)
        if (revC) {
            iy <- nr:1
            if (exists("ddr"))
                ddr <- rev(ddr)
            x <- x[, iy]
            cellnote <- cellnote[, iy]
        }
        else iy <- 1:nr
        image(1:nc, 1:nr, x, xlim = 0.5 + c(0, nc), ylim = 0.5 + c(0, nr), axes = FALSE, xlab = "", ylab = "", col = col, breaks = breaks, ...)
        retval$carpet <- x
        if (exists("ddr"))
            retval$rowDendrogram <- ddr
        if (exists("ddc"))
            retval$colDendrogram <- ddc
        retval$breaks <- breaks
        retval$col <- col
        if (!invalid(na.color) & any(is.na(x))) { # load library(gplots)
            mmat <- ifelse(is.na(x), 1, NA)
            image(1:nc, 1:nr, mmat, axes = FALSE, xlab = "", ylab = "",
                col = na.color, add = TRUE)
        }
        axis(1, 1:nc, labels = labCol, las = 2, line = -0.5, tick = 0,
            cex.axis = cexCol)
        if (!is.null(xlab))
            mtext(xlab, side = 1, line = margins[1] - 1.25)
        axis(4, iy, labels = labRow, las = 2, line = -0.5, tick = 0,
            cex.axis = cexRow)
        if (!is.null(ylab))
            mtext(ylab, side = 4, line = margins[2] - 1.25)
        if (!missing(add.expr))
            eval(substitute(add.expr))
        if (!missing(colsep))
            for (csep in colsep) rect(xleft = csep + 0.5, ybottom = rep(0, length(csep)), xright = csep + 0.5 + sepwidth[1], ytop = rep(ncol(x) + 1, csep), lty = 1, lwd = 1, col = sepcolor, border = sepcolor)
        if (!missing(rowsep))
            for (rsep in rowsep) rect(xleft = 0, ybottom = (ncol(x) + 1 - rsep) - 0.5, xright = nrow(x) + 1, ytop = (ncol(x) + 1 - rsep) - 0.5 - sepwidth[2], lty = 1, lwd = 1, col = sepcolor, border = sepcolor)
        min.scale <- min(breaks)
        max.scale <- max(breaks)
        x.scaled <- scale01(t(x), min.scale, max.scale)
        if (trace %in% c("both", "column")) {
            retval$vline <- vline
            vline.vals <- scale01(vline, min.scale, max.scale)
            for (i in colInd) {
                if (!is.null(vline)) {
                    abline(v = i - 0.5 + vline.vals, col = linecol,
                      lty = 2)
                }
                xv <- rep(i, nrow(x.scaled)) + x.scaled[, i] - 0.5
                xv <- c(xv[1], xv)
                yv <- 1:length(xv) - 0.5
                lines(x = xv, y = yv, lwd = 1, col = tracecol, type = "s")
            }
        }
        if (trace %in% c("both", "row")) {
            retval$hline <- hline
            hline.vals <- scale01(hline, min.scale, max.scale)
            for (i in rowInd) {
                if (!is.null(hline)) {
                    abline(h = i + hline, col = linecol, lty = 2)
                }
                yv <- rep(i, ncol(x.scaled)) + x.scaled[i, ] - 0.5
                yv <- rev(c(yv[1], yv))
                xv <- length(yv):1 - 0.5
                lines(x = xv, y = yv, lwd = 1, col = tracecol, type = "s")
            }
        }
        if (!missing(cellnote))
            text(x = c(row(cellnote)), y = c(col(cellnote)), labels = c(cellnote),
                col = notecol, cex = notecex)
        par(mar = c(margins[1], 0, 0, 0))
        if (dendrogram %in% c("both", "row")) {
            plot(ddr, horiz = TRUE, axes = FALSE, yaxs = "i", leaflab = "none")
        }
        else plot.new()
        par(mar = c(0, 0, if (!is.null(main)) 5 else 0, margins[2]))
        if (dendrogram %in% c("both", "column")) {
            plot(ddc, axes = FALSE, xaxs = "i", leaflab = "none")
        }
        else plot.new()
        if (!is.null(main))
            title(main, cex.main = 1.5 * op[["cex.main"]])
        if (key) {
            par(mar = c(5, 4, 2, 1), cex = 0.75)
            tmpbreaks <- breaks
            if (symkey) {
                max.raw <- max(abs(c(x, breaks)), na.rm = TRUE)
                min.raw <- -max.raw
                tmpbreaks[1] <- -max(abs(x), na.rm = TRUE)
                tmpbreaks[length(tmpbreaks)] <- max(abs(x), na.rm = TRUE)
            }
            else {
                min.raw <- min(x, na.rm = TRUE)
                max.raw <- max(x, na.rm = TRUE)
            }

            z <- seq(min.raw, max.raw, length = length(col))
            image(z = matrix(z, ncol = 1), col = col, breaks = tmpbreaks,
                xaxt = "n", yaxt = "n")
            par(usr = c(0, 1, 0, 1))
            lv <- pretty(breaks)
            xv <- scale01(as.numeric(lv), min.raw, max.raw)
            axis(1, at = xv, labels = lv)
            if (scale == "row")
                mtext(side = 1, "Row Z-Score", line = 2)
            else if (scale == "column")
                mtext(side = 1, "Column Z-Score", line = 2)
            else mtext(side = 1, KeyValueName, line = 2)
            if (density.info == "density") {
                dens <- density(x, adjust = densadj, na.rm = TRUE)
                omit <- dens$x < min(breaks) | dens$x > max(breaks)
                dens$x <- dens$x[-omit]
                dens$y <- dens$y[-omit]
                dens$x <- scale01(dens$x, min.raw, max.raw)
                lines(dens$x, dens$y/max(dens$y) * 0.95, col = denscol,
                    lwd = 1)
                axis(2, at = pretty(dens$y)/max(dens$y) * 0.95, pretty(dens$y))
                title("Color Key\nand Density Plot")
                par(cex = 0.5)
                mtext(side = 2, "Density", line = 2)
            }
            else if (density.info == "histogram") {
                h <- hist(x, plot = FALSE, breaks = breaks)
                hx <- scale01(breaks, min.raw, max.raw)
                hy <- c(h$counts, h$counts[length(h$counts)])
                lines(hx, hy/max(hy) * 0.95, lwd = 1, type = "s",
                    col = denscol)
                axis(2, at = pretty(hy)/max(hy) * 0.95, pretty(hy))
                title("Color Key\nand Histogram")
                par(cex = 0.5)
                mtext(side = 2, "Count", line = 2)
            }
            else title("Color Key")
        }
        else plot.new()
        retval$colorTable <- data.frame(low = retval$breaks[-length(retval$breaks)],
            high = retval$breaks[-1], color = retval$col)
        invisible(retval)
    }

    myclust <- function(c)
    {
      hclust(c,method="average")
    }

    na.dist <- function(x,method="euclidian",...)
    {
      t.dist <- dist(x,...)
      t.dist <- as.matrix(t.dist)
      t.limit <- 1.1*max(t.dist,na.rm=T)
      t.dist[is.na(t.dist)] <- t.limit
      t.dist <- as.dist(t.dist)
      return(t.dist)
    }

## Figure Three

A “heatmap” of physico-chemical properties, in vitro TK parameters (Wetmore, et al., 2013), and TK parameters estimated from in vivo plasma concentration. Rows (chemicals) are clustered by Euclidean distance so that adjacent rows are more similar to each other. Each column (chemical properties) was scaled by the standard deviation of the column and the mean value was subtracted, such that a value of 0 corresponds to the mean and values of -1 or 1 correspond to values one standard deviation above or below the chemicals, respectively. In some cases, TK parameters could not be estimated (e.g., no oral data available for estimating Fbio and kgutabs). Fraction of the compound that is neutral, positively, or negatively ionized at pH 7.4 is indicated by “neutral ph74”, “positive ph74” and “negative ph74”. The color bar at the left-hand side indicates pharmaceuticals in grey and other chemicals in black.

    physprop.matrix <- chem.invivo.PK.aggregate.data[,c("MW",
                                        "logP",
                                        "WaterSol",
                                        "Neutral.pH74",
                                        "Positive.pH74",
                                        "Negative.pH74",
                                        "Clint",
                                        "Fup",
                                        "Vdist",
                                        "kelim",
                                        "kgutabs",
                                        "Fbio")]
    rnames <- chem.invivo.PK.aggregate.data$Compound
    rnames[rnames=="Bensulide"] <- c("Bensulide.Joint","Bensulide.NHEERL","Bensulide.RTI")
    rnames[rnames=="Propyzamide"] <- c("Propyzamide.Joint","Propyzamide.NHEERL","Propyzamide.RTI")
    rownames(physprop.matrix) <- rnames

    row.side.cols <- rep("Black",dim(physprop.matrix)[1])
    row.side.cols[sapply(chem.invivo.PK.aggregate.data$CAS,is.pharma)] <- "Grey"

    apply(physprop.matrix,2,function(x) mean(x,na.rm=T))
    #>            MW          logP      WaterSol  Neutral.pH74 Positive.pH74
    #>  3.174834e+02  3.190226e+00  3.860117e+04  6.421500e-01  1.365090e-01
    #> Negative.pH74         Clint           Fup         Vdist         kelim
    #>  2.006272e-01  6.847503e+01  2.424042e-01  4.363502e+01  6.443127e-01
    #>       kgutabs          Fbio
    #>  8.741492e+01  4.886260e-01
    for (this.col in c(c(1,3,7,9:11),c(4:6,8,12))) physprop.matrix[,this.col] <- log10(10^-6+physprop.matrix[,this.col])

    physprop.matrix <- apply(physprop.matrix,2,function(x) (x-mean(x,na.rm=T))/sd(x,na.rm=T))

    main_title="in vivo Toxicokinetic Parameters"
    heatmap.2(physprop.matrix,
              hclustfun=myclust,
              Colv=FALSE,
              distfun=na.dist,
              na.rm = TRUE,
              scale="none",
              trace="none",
              RowSideColors=row.side.cols,
              col=brewer.pal(11,"Spectral"),
              margins=c(8,10))
    # The following has to be adjusted manually:
    rect(0.65, 0.01, 0.87, 0.78, border="blue")
    text(0.75,0.81,expression(paste("Estimated from ",italic("In Vivo")," Data")))

The original scripts used a data.table called FitData that contains a lot of stuff we don’t need to make these figures. We recreate it from the httk object chem.invivo.PK.aggregate.data:

    # Use joint analysis data from both labs:
    FitData <- subset(chem.invivo.PK.aggregate.data,Compound!="Bensulide"|Source=="Wambaugh et al. (2018), NHEERL/RTI")
    FitData <- subset(FitData,Compound!="Propyzamide"|Source=="Wambaugh et al. (2018), NHEERL/RTI")
    # Rename some columns to match original data files:
    FitData$Compound.abbrev <- FitData$Abbrev
    # Add a column indicating chemical type:
    FitData$Chemical <- "Other"
    FitData[sapply(FitData$CAS,is.pharma),"Chemical"] <- "Pharmaceutical"

## Figure Four

Comparison of measured volumes of distribution (Vd) with predictions based upon in vitro data and in silico methods (Pearce, et al., 2017a; Schmitt, 2008). The solid line in each panel indicates the identity line (1:1, perfect predictions). Chemicals can be identified by their chemical abbreviation given in Table 1.

    # Get rid of chemicals with Fup < LOD:
    FitData.Fup <- subset(FitData,!(CAS%in%subset(chem.physical_and_invitro.data,Human.Funbound.plasma==0)$CAS))

    # Rename some columns to match original data files:
    FitData.Fup$SelectedVdist <- FitData.Fup$Vdist
    FitData.Fup$SelectedVdist.sd <- FitData.Fup$Vdist.sd

    #Predict volume of Distribution
    FitData.Fup$Vdist.1comp.pred <- sapply(FitData.Fup$CAS,
      function(x) calc_vdist(chem.cas=x,
      species="Rat",
      default.to.human = T,
      suppress.messages=T))
    FitData.Fup$Vdist.1comp.pred.nocal <- sapply(FitData.Fup$CAS,
      function(x) calc_vdist(chem.cas=x,
      regression=F,
      species="Rat",
      default.to.human = T,
      suppress.messages=T))

    FigVdista.fit <- lm(log(SelectedVdist)~log(Vdist.1comp.pred),data=subset(FitData.Fup,!is.na(SelectedVdist)&!is.na(Vdist.1comp.pred)))
    summary(FigVdista.fit)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred), data = subset(FitData.Fup,
    #>     !is.na(SelectedVdist) & !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.1461 -0.9777 -0.2608  1.5412  3.9452
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             1.7089     0.3668   4.659 4.24e-05 ***
    #> log(Vdist.1comp.pred)   0.3798     0.3750   1.013    0.318
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.168 on 36 degrees of freedom
    #> Multiple R-squared:  0.0277, Adjusted R-squared:  0.0006962
    #> F-statistic: 1.026 on 1 and 36 DF,  p-value: 0.3179

    FigVdista.fit.weighted <- lm(log(SelectedVdist)~log(Vdist.1comp.pred),data=subset(FitData.Fup,!is.na(SelectedVdist)&!is.na(Vdist.1comp.pred)),weights=1/SelectedVdist.sd^2)
    summary(FigVdista.fit)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred), data = subset(FitData.Fup,
    #>     !is.na(SelectedVdist) & !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.1461 -0.9777 -0.2608  1.5412  3.9452
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             1.7089     0.3668   4.659 4.24e-05 ***
    #> log(Vdist.1comp.pred)   0.3798     0.3750   1.013    0.318
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.168 on 36 degrees of freedom
    #> Multiple R-squared:  0.0277, Adjusted R-squared:  0.0006962
    #> F-statistic: 1.026 on 1 and 36 DF,  p-value: 0.3179

    FigVdista.fit.pharm <- lm(log(SelectedVdist)~log(Vdist.1comp.pred),data=subset(FitData.Fup,Chemical!="Other"&!is.na(Vdist.1comp.pred)))
    summary(FigVdista.fit.pharm)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred), data = subset(FitData.Fup,
    #>     Chemical != "Other" & !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -2.8295 -1.3330  0.4306  0.8705  3.2245
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             0.3616     0.4873   0.742    0.472
    #> log(Vdist.1comp.pred)   0.4034     0.5384   0.749    0.468
    #>
    #> Residual standard error: 1.766 on 12 degrees of freedom
    #>   (2 observations deleted due to missingness)
    #> Multiple R-squared:  0.04469,    Adjusted R-squared:  -0.03492
    #> F-statistic: 0.5613 on 1 and 12 DF,  p-value: 0.4682

    FigVdista.fit.other <- lm(log(SelectedVdist)~log(Vdist.1comp.pred),data=subset(FitData.Fup,Chemical=="Other"&!is.na(Vdist.1comp.pred)))
    summary(FigVdista.fit.other)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred), data = subset(FitData.Fup,
    #>     Chemical == "Other" & !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>    Min     1Q Median     3Q    Max
    #> -4.637 -1.461 -0.164  1.348  3.194
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             2.5160     0.4373   5.753 8.69e-06 ***
    #> log(Vdist.1comp.pred)   0.3006     0.4295   0.700    0.491
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.043 on 22 degrees of freedom
    #>   (2 observations deleted due to missingness)
    #> Multiple R-squared:  0.02179,    Adjusted R-squared:  -0.02268
    #> F-statistic:  0.49 on 1 and 22 DF,  p-value: 0.4913

    dim(subset(FitData.Fup,!is.na(SelectedVdist.sd)&!is.na(Vdist.1comp.pred)))[1]
    #> [1] 12

    FigVdista <- ggplot(data=subset(FitData.Fup,!is.na(Vdist.1comp.pred))) +
        geom_segment(color="Grey",aes(x=Vdist.1comp.pred,y=exp(log(SelectedVdist)-SelectedVdist.sd),xend=Vdist.1comp.pred,yend=exp(log(SelectedVdist)+SelectedVdist.sd)))+
        geom_text(aes_string(y="SelectedVdist",
                             x="Vdist.1comp.pred",
                             label="Compound.abbrev",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits = c(5*10^-2, 10^2)) +
       scale_x_log10(label=scientific_10,limits = c(5*10^-2, 10^2)) +
       annotation_logticks() +
       geom_abline(slope=1, intercept=0) +
       annotate("text", x = 1*10^-1, y = 3*10^1, label = "A",size=6)  +
       ylab(expression(paste(italic("In vivo")," estimated Volume of Distribution (L/kg)"))) +
       xlab(expression(paste("Calibrated ",italic("In vitro")," predicted ",V[d]," (L/kg)"))) +
       theme_bw()  +
       theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    FigVdistb.fit <- lm(log(SelectedVdist)~log(Vdist.1comp.pred.nocal),data=subset(FitData.Fup,!is.na(Vdist.1comp.pred)))
    summary(FigVdistb.fit)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred.nocal),
    #>     data = subset(FitData.Fup, !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.4208 -1.0646 -0.1083  1.5447  3.7382
    #>
    #> Coefficients:
    #>                             Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)                   1.4188     0.4278   3.316  0.00209 **
    #> log(Vdist.1comp.pred.nocal)   0.3285     0.2100   1.564  0.12649
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.128 on 36 degrees of freedom
    #>   (4 observations deleted due to missingness)
    #> Multiple R-squared:  0.06365,    Adjusted R-squared:  0.03764
    #> F-statistic: 2.447 on 1 and 36 DF,  p-value: 0.1265

    FigVdistb.fit.weighted <- lm(log(SelectedVdist)~log(Vdist.1comp.pred.nocal),data=subset(FitData.Fup,!is.na(Vdist.1comp.pred)),weights=1/SelectedVdist.sd^2)
    summary(FigVdistb.fit)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred.nocal),
    #>     data = subset(FitData.Fup, !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.4208 -1.0646 -0.1083  1.5447  3.7382
    #>
    #> Coefficients:
    #>                             Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)                   1.4188     0.4278   3.316  0.00209 **
    #> log(Vdist.1comp.pred.nocal)   0.3285     0.2100   1.564  0.12649
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.128 on 36 degrees of freedom
    #>   (4 observations deleted due to missingness)
    #> Multiple R-squared:  0.06365,    Adjusted R-squared:  0.03764
    #> F-statistic: 2.447 on 1 and 36 DF,  p-value: 0.1265

    FigVdistb.fit.pharm <- lm(log(SelectedVdist)~log(Vdist.1comp.pred.nocal),data=subset(FitData.Fup,Chemical!="Other"&!is.na(Vdist.1comp.pred)))
    summary(FigVdistb.fit.pharm)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred.nocal),
    #>     data = subset(FitData.Fup, Chemical != "Other" & !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -2.7693 -1.3172  0.4417  0.8679  3.3141
    #>
    #> Coefficients:
    #>                             Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)                   0.2645     0.5686   0.465    0.650
    #> log(Vdist.1comp.pred.nocal)   0.1743     0.2886   0.604    0.557
    #>
    #> Residual standard error: 1.78 on 12 degrees of freedom
    #>   (2 observations deleted due to missingness)
    #> Multiple R-squared:  0.0295, Adjusted R-squared:  -0.05138
    #> F-statistic: 0.3648 on 1 and 12 DF,  p-value: 0.5571

    FigVdistb.fit.other<- lm(log(SelectedVdist)~log(Vdist.1comp.pred.nocal),data=subset(FitData.Fup,Chemical=="Other"&!is.na(Vdist.1comp.pred)))
    summary(FigVdistb.fit.other)
    #>
    #> Call:
    #> lm(formula = log(SelectedVdist) ~ log(Vdist.1comp.pred.nocal),
    #>     data = subset(FitData.Fup, Chemical == "Other" & !is.na(Vdist.1comp.pred)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -5.0535 -1.1912  0.0224  1.2973  2.9310
    #>
    #> Coefficients:
    #>                             Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)                   2.1449     0.5098   4.208 0.000363 ***
    #> log(Vdist.1comp.pred.nocal)   0.3633     0.2457   1.479 0.153398
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 1.97 on 22 degrees of freedom
    #>   (2 observations deleted due to missingness)
    #> Multiple R-squared:  0.0904, Adjusted R-squared:  0.04906
    #> F-statistic: 2.187 on 1 and 22 DF,  p-value: 0.1534

    FigVdistb <- ggplot(data=subset(FitData.Fup,!is.na(Vdist.1comp.pred.nocal))) +
       geom_segment(color="Grey",aes(x=Vdist.1comp.pred.nocal,y=exp(log(SelectedVdist)-SelectedVdist.sd),xend=Vdist.1comp.pred.nocal,yend=exp(log(SelectedVdist)+SelectedVdist.sd)))+
       geom_text(aes_string(y="SelectedVdist",
                             x="Vdist.1comp.pred.nocal",
                             label="Compound.abbrev",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits = c(5*10^-2, 10^2)) +
       scale_x_log10(label=scientific_10,limits = c(5*10^-2, 10^2)) +
       annotation_logticks() +
       geom_abline(slope=1, intercept=0) +
       annotate("text", x = 1*10^-1, y = 3*10^1, label = "B",size=6) +
       ylab(expression(paste(italic("In vivo")," estimated Volume of Distribution (L/kg)"))) +
       xlab(expression(paste("Original ",italic("In vitro")," predicted ",V[d]," (L/kg)"))) +
       theme_bw()  +
       theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=10,height=6)
    multiplot(FigVdista,FigVdistb,cols=2,widths=c(1.75,1.75))

    Fig4a.data <- subset(FitData.Fup,!is.na(SelectedVdist)&!is.na(Vdist.1comp.pred))
    Fig4a.MSE <- mean((log(Fig4a.data$Vdist.1comp.pred)-log(Fig4a.data$SelectedVdist))^2)

    Fig4b.data <- subset(FitData.Fup,!is.na(SelectedVdist)&!is.na(Vdist.1comp.pred.nocal))
    Fig4b.MSE <- mean((log(Fig4b.data$Vdist.1comp.pred.nocal)-log(Fig4b.data$SelectedVdist))^2)

## Figure Five

Comparison of the TK clearance estimated from the in vivo data with the clearance predictions made using HTTK data. The more likely empirical TK model (either one or two-compartments, as in Figure 2) is selected for each chemical using the AIC (Akaike, 1974). A non-compartmental estimate of clearance is used if neither model is selected. Estimated standard deviation is indicated by a vertical line, and is often smaller than the plot point. The solid line indicates the identity line (1:1, perfect predictions), while the dotted and dashed lines indicate the linear regression (log-scale) trend-lines for pharmaceuticals and other chemicals, respectively. Chemicals can be identified by their chemical abbreviation given in Table 1.

    #FitData.Fup$CLtot.1comp <- FitData.Fup$Vdist.1comp.meas*FitData.Fup$kelim.1comp.meas
    #FitData.Fup$CLtot.1comp.sd <- (FitData.Fup$Vdist.1comp.meas.sd^2+FitData.Fup$kelim.1comp.meas.sd^2)^(1/2)
    #FitData.Fup[is.na(CLtot.1comp.sd)]$CLtot.1comp.sd <- Inf

    #FitData.Fup[is.na(SelectedCLtot.sd)]$SelectedClearance.sd <- Inf

    FitData.Fup$SelectedCLtot <- FitData.Fup$Vdist*FitData.Fup$kelim
    FitData.Fup$SelectedCLtot.sd <- (FitData.Fup$Vdist.sd^2 +
      FitData.Fup$kelim.sd^2)^(1/2)
    FitData.Fup$CLtot.1comp.pred <- sapply(FitData.Fup$CAS,
      function(x) calc_total_clearance(chem.cas=x,
      species="Rat",
      default.to.human = T,
      suppress.messages=T))

    Fig.SelectedClearance.fit <- lm(log(SelectedCLtot)~log(CLtot.1comp.pred),data=subset(FitData.Fup,!is.na(SelectedCLtot.sd)))
    summary(Fig.SelectedClearance.fit)
    #>
    #> Call:
    #> lm(formula = log(SelectedCLtot) ~ log(CLtot.1comp.pred), data = subset(FitData.Fup,
    #>     !is.na(SelectedCLtot.sd)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -3.1620 -0.1632  0.1349  0.7032  2.0681
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             2.1127     0.5726   3.690  0.00418 **
    #> log(CLtot.1comp.pred)   0.5997     0.2392   2.507  0.03106 *
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 1.571 on 10 degrees of freedom
    #> Multiple R-squared:  0.386,  Adjusted R-squared:  0.3246
    #> F-statistic: 6.286 on 1 and 10 DF,  p-value: 0.03106
    Fig.SelectedClearance.fit.weighted <- lm(log(SelectedCLtot)~log(CLtot.1comp.pred),data=subset(FitData.Fup,!is.na(SelectedCLtot.sd)),weights=1/SelectedCLtot.sd^2)
    summary(Fig.SelectedClearance.fit.weighted)
    #>
    #> Call:
    #> lm(formula = log(SelectedCLtot) ~ log(CLtot.1comp.pred), data = subset(FitData.Fup,
    #>     !is.na(SelectedCLtot.sd)), weights = 1/SelectedCLtot.sd^2)
    #>
    #> Weighted Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -53.667  -1.086   6.436   8.966  49.732
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             1.9671     0.5611   3.506  0.00567 **
    #> log(CLtot.1comp.pred)   0.7537     0.2499   3.016  0.01299 *
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 25.76 on 10 degrees of freedom
    #> Multiple R-squared:  0.4763, Adjusted R-squared:  0.4239
    #> F-statistic: 9.094 on 1 and 10 DF,  p-value: 0.01299
    Fig.SelectedClearance.fit.pharma <- lm(log(SelectedCLtot)~log(CLtot.1comp.pred),data=subset(FitData.Fup,Chemical!="Other"&!is.na(SelectedCLtot.sd)),weights=1/SelectedCLtot.sd^2)
    summary(Fig.SelectedClearance.fit.pharma)
    #>
    #> Call:
    #> lm(formula = log(SelectedCLtot) ~ log(CLtot.1comp.pred), data = subset(FitData.Fup,
    #>     Chemical != "Other" & !is.na(SelectedCLtot.sd)), weights = 1/SelectedCLtot.sd^2)
    #>
    #> Weighted Residuals:
    #>       3      10      30      46
    #> -0.4905 17.7995 -4.4264 -7.1998
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             1.9587     0.4504   4.349   0.0490 *
    #> log(CLtot.1comp.pred)   0.9627     0.1571   6.127   0.0256 *
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 13.94 on 2 degrees of freedom
    #> Multiple R-squared:  0.9494, Adjusted R-squared:  0.9241
    #> F-statistic: 37.54 on 1 and 2 DF,  p-value: 0.02562
    Fig.SelectedClearance.fit.other<- lm(log(SelectedCLtot)~log(CLtot.1comp.pred),data=subset(FitData.Fup,Chemical=="Other"&!is.na(SelectedCLtot.sd)),weights=1/SelectedCLtot.sd^2)
    summary(Fig.SelectedClearance.fit.other)
    #>
    #> Call:
    #> lm(formula = log(SelectedCLtot) ~ log(CLtot.1comp.pred), data = subset(FitData.Fup,
    #>     Chemical == "Other" & !is.na(SelectedCLtot.sd)), weights = 1/SelectedCLtot.sd^2)
    #>
    #> Weighted Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -33.794 -12.082   3.376   9.599  18.558
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             1.5718     0.6183   2.542   0.0439 *
    #> log(CLtot.1comp.pred)  -0.5254     0.4826  -1.089   0.3181
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 20.46 on 6 degrees of freedom
    #> Multiple R-squared:  0.165,  Adjusted R-squared:  0.02578
    #> F-statistic: 1.185 on 1 and 6 DF,  p-value: 0.3181
    Fig.SelectedClearance.fit.pharma <- lm(log(SelectedCLtot)~log(CLtot.1comp.pred),data=subset(FitData.Fup,Chemical!="Other"))
    summary(Fig.SelectedClearance.fit.pharma)
    #>
    #> Call:
    #> lm(formula = log(SelectedCLtot) ~ log(CLtot.1comp.pred), data = subset(FitData.Fup,
    #>     Chemical != "Other"))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.0930 -0.8350 -0.0164  1.3919  2.2213
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)            -0.1410     0.6383  -0.221    0.829
    #> log(CLtot.1comp.pred)   0.3894     0.2283   1.705    0.114
    #>
    #> Residual standard error: 1.747 on 12 degrees of freedom
    #>   (2 observations deleted due to missingness)
    #> Multiple R-squared:  0.1951, Adjusted R-squared:  0.128
    #> F-statistic: 2.908 on 1 and 12 DF,  p-value: 0.1139
    Fig.SelectedClearance.fit.other<- lm(log(SelectedCLtot)~log(CLtot.1comp.pred),data=subset(FitData.Fup,Chemical=="Other"))
    summary(Fig.SelectedClearance.fit.other)
    #>
    #> Call:
    #> lm(formula = log(SelectedCLtot) ~ log(CLtot.1comp.pred), data = subset(FitData.Fup,
    #>     Chemical == "Other"))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -4.1562 -0.8868  0.3667  1.1447  3.2630
    #>
    #> Coefficients:
    #>                       Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)             2.6767     0.5503   4.864 7.33e-05 ***
    #> log(CLtot.1comp.pred)   0.8861     0.1686   5.256 2.84e-05 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 1.926 on 22 degrees of freedom
    #>   (2 observations deleted due to missingness)
    #> Multiple R-squared:  0.5567, Adjusted R-squared:  0.5365
    #> F-statistic: 27.63 on 1 and 22 DF,  p-value: 2.84e-05

    Fig.SelectedClearance<- ggplot(data=FitData.Fup,aes(y=SelectedCLtot,x=CLtot.1comp.pred)) +
        geom_segment(data=subset(FitData.Fup,is.finite(SelectedCLtot.sd)),color="grey",aes(x=CLtot.1comp.pred,y=exp(log(SelectedCLtot)-SelectedCLtot.sd),xend=CLtot.1comp.pred,yend=exp(log(SelectedCLtot)+SelectedCLtot.sd)))+
      geom_text(aes_string(y="SelectedCLtot",
                             x="CLtot.1comp.pred",
                             label="Compound.abbrev",
                             color="Chemical"))+
    #    geom_point(data=twocomp.data,color="White",size=2,aes(shape=Source))+
       scale_y_log10(label=scientific_10,limits = c(10^-4, 10^3)) +
       scale_x_log10(label=scientific_10,limits = c(10^-4, 10^3)) +
        annotation_logticks() +
        geom_abline(slope=1, intercept=0) +
         geom_line(aes(x = CLtot.1comp.pred, y = exp(Fig.SelectedClearance.fit.pharma$coefficients[1]+Fig.SelectedClearance.fit.pharma$coefficients[2]*log(CLtot.1comp.pred))), colour = "darkturquoise", linetype="dotted", size=1.5) +
      geom_line(aes(x = CLtot.1comp.pred, y = exp(Fig.SelectedClearance.fit.other$coefficients[1]+Fig.SelectedClearance.fit.other$coefficients[2]*log(CLtot.1comp.pred))), colour = "red", linetype="dashed", size=1.5) +
         ylab(expression(paste(italic("In vivo")," estimated clearance (mg/L/h)"))) +
        xlab(expression(paste(italic("In vitro")," predicted clearance (mg/L/h)"))) +
        theme_bw()   +
        theme(legend.position="bottom")+
        annotate("text",x = 10^2/3/3/3, y = 3*3*10^-4,size=4, label = lm_R2(Fig.SelectedClearance.fit.pharma,prefix="Pharmaceutical:"),parse=T)+
        annotate("text",x = 10^2/3/3/3, y = 3*3*3*10^-5,size=4, label = lm_R2(Fig.SelectedClearance.fit.other,prefix="Other:"),parse=T)+
        theme(plot.margin = unit(c(1,1,1,1), "cm"))+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=6,height=6)
    print(Fig.SelectedClearance)

    paste("with",with(FitData.Fup,sum(SelectedCLtot<CLtot.1comp.pred,na.rm=T)),"chemicals over-estimated and",with(FitData.Fup,sum(SelectedCLtot>CLtot.1comp.pred,na.rm=T)),"under-estimated")
    #> [1] "with 7 chemicals over-estimated and 31 under-estimated"

## Figure Six

Distribution of Gut Absorption Rate for Environmental and Pharmaceutical Chemicals.

    FitData$Selectedkgutabs <- FitData$kgutabs
    # Cutoff from optimizer is 1000:
    Figkgutabs <- ggplot(subset(FitData,Selectedkgutabs<999), aes(Selectedkgutabs, fill = Chemical)) +
      geom_histogram(binwidth=0.5) +
         scale_x_log10(label=scientific_10) +
         ylab("Number of Chemicals")+
         xlab("Absorption Rate from Gut (1/h)")+
         theme_bw() +
            theme(legend.position="bottom")

    #dev.new(width=6,height=6)
    print(Figkgutabs)

    mean(subset(FitData,Selectedkgutabs<999)$Selectedkgutabs)
    #> [1] 46.99929
    min(subset(FitData,Selectedkgutabs<999)$Selectedkgutabs)
    #> [1] 0.2306496
    max(subset(FitData,Selectedkgutabs<999)$Selectedkgutabs)
    #> [1] 453.0789
    median(subset(FitData,Selectedkgutabs<999)$Selectedkgutabs)
    #> [1] 2.179775

## Figure Seven

In panel A, the observed fraction of oral dose absorbed from the gut is compared with predictions made using Gastroplus (Simulations Plus, 2017). The solid line indicates the identity line (1:1, perfect predictions). These fractions are distrusted from nearly zero to effectively 100% (Panel B). Chemicals can be identified by their chemical abbreviation given in Table 1.

    FitData$SelectedFbio <- FitData$Fbio

    FigFbioa <- ggplot(data=FitData) +
        geom_text(aes_string(y="SelectedFbio",
                             x="Fbio.pred",
                             label="Compound.abbrev",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits=c(10^-3,1)) +
       scale_x_log10(label=scientific_10,limits=c(10^-3,1)) +
    #    xlim(0, 1)+
    #    ylim(0, 1)+
        annotate("text", x = .015/10, y = 0.55, label = "A",size=6) +
        annotation_logticks() +
        geom_abline(slope=1, intercept=0) +
        ylab(expression(paste(italic("In vivo")," estimated Fraction Bioavailable"))) +
        xlab(expression(paste(italic("In silico")," predicted ",F[bio]))) +
    #    scale_color_brewer(palette="Set2") +
        theme_bw()  +
        theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    FigFbiob <- ggplot(FitData, aes(SelectedFbio, fill = Chemical)) +
      geom_histogram(binwidth=0.5) +
        scale_x_log10(label=scientific_10,limits=c(10^-3,3)) +
        annotate("text", x = .001, y = 18, label = "B",size=6) +
        ylab("Number of Chemicals")+
        xlab(expression(paste(italic("In vivo")," estimated Fraction Bioavailable"))) +
        theme_bw()  +
        theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),fill=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=10,height=6)
    multiplot(FigFbioa,FigFbiob,cols=2,widths=c(1.75,1.75))

    summary(lm(log(SelectedFbio)~log(Fbio.pred),data=FitData))

    paste("Fbio ranged from",signif(min(FitData[FitData$Chemical=="Pharmaceutical","SelectedFbio"],na.rm=T),2),"to",signif(max(FitData[FitData$Chemical=="Pharmaceutical","SelectedFbio"],na.rm=T),2),"for pharmaceutical compounds, but was observed to be as low as", signif(min(FitData[FitData$Chemical=="Other","SelectedFbio"],na.rm=T),3),"for other compounds.")

    min(FitData$SelectedFbio,na.rm=T)

## Figure Eight

Rat in vivo data were collected for diverse environmental chemicals to evaluate the predictive ability of HTTK, especially with respect to predicting steady-state serum concentration (Css). Chemicals can be identified by their chemical abbreviation given in Table 1. The abbreviations are centered at the measured and predicted values. The solid line indicates the identity line (1:1, perfect predictions). In panel A, the one-compartment model is parameterized with a predicted volume of distribution and clearance, based upon in vitro measured parameters. Fbio is assumed to be 100%. In panel B, the in vivo measured Fbio is used to reduce the amount of the oral dose absorbed in the one-compartment model, to illustrate the improvement possible if Fbio could be predicted accurately.

    FitData$SelectedFbio <- FitData$Fbio
    FitData$SelectedCss <- FitData$Css
    FitData$SelectedCss.sd <- FitData$Css.sd
    FitData$Css.1comp.pred <- sapply(FitData$CAS,
      function(x) calc_analytic_css(chem.cas=x,
      species="Rat",
      model="3compartmentss",
      suppress.messages=T,
      parameterize.args = list(
        default.to.human=T,
        adjusted.Funbound.plasma=T,
        regression=T,
        minimum.Funbound.plasma=1e-4)))

    Fig.1compCss.fit <- lm(log(SelectedCss)~log(Css.1comp.pred),data=FitData,na.rm=T)
    Fig.1compCss.fit.weighted <- lm(log(SelectedCss)~log(Css.1comp.pred),data=FitData,na.rm=T,weights=1/SelectedCss.sd^2)
    Fig.1compCss.fit.pharma <- lm(log(SelectedCss)~log(Css.1comp.pred),data=subset(FitData,Chemical!="Other"),na.rm=T)
    Fig.1compCss.fit.other <- lm(log(SelectedCss)~log(Css.1comp.pred),data=subset(FitData,Chemical=="Other"),na.rm=T)

    summary(Fig.1compCss.fit)
    #>
    #> Call:
    #> lm(formula = log(SelectedCss) ~ log(Css.1comp.pred), data = FitData,
    #>     na.rm = T)
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -6.2355 -1.5594 -0.0894  1.4074  5.7742
    #>
    #> Coefficients:
    #>                     Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)          -4.5912     0.5370  -8.550 2.03e-09 ***
    #> log(Css.1comp.pred)   0.8704     0.2086   4.173 0.000249 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.979 on 29 degrees of freedom
    #>   (11 observations deleted due to missingness)
    #> Multiple R-squared:  0.3752, Adjusted R-squared:  0.3537
    #> F-statistic: 17.42 on 1 and 29 DF,  p-value: 0.0002494
    summary(Fig.1compCss.fit.pharma)
    #>
    #> Call:
    #> lm(formula = log(SelectedCss) ~ log(Css.1comp.pred), data = subset(FitData,
    #>     Chemical != "Other"), na.rm = T)
    #>
    #> Residuals:
    #>    Min     1Q Median     3Q    Max
    #> -2.284 -1.535 -1.224  1.136  4.044
    #>
    #> Coefficients:
    #>                     Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)          -3.1127     0.8371  -3.718  0.00747 **
    #> log(Css.1comp.pred)   0.6613     0.3467   1.907  0.09814 .
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.363 on 7 degrees of freedom
    #>   (7 observations deleted due to missingness)
    #> Multiple R-squared:  0.342,  Adjusted R-squared:  0.248
    #> F-statistic: 3.638 on 1 and 7 DF,  p-value: 0.09814
    summary(Fig.1compCss.fit.other)
    #>
    #> Call:
    #> lm(formula = log(SelectedCss) ~ log(Css.1comp.pred), data = subset(FitData,
    #>     Chemical == "Other"), na.rm = T)
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -5.5165 -1.5544  0.4052  1.3667  6.0823
    #>
    #> Coefficients:
    #>                     Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)          -5.2706     0.6371  -8.273 6.91e-08 ***
    #> log(Css.1comp.pred)   1.0163     0.2415   4.207 0.000433 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.988 on 20 degrees of freedom
    #>   (4 observations deleted due to missingness)
    #> Multiple R-squared:  0.4695, Adjusted R-squared:  0.443
    #> F-statistic:  17.7 on 1 and 20 DF,  p-value: 0.0004331

    textx <- 10^-3
    texty <- 1*10^1

    Fig.Cssa <- ggplot(data=FitData) +
      geom_segment(color="grey",aes(x=Css.1comp.pred,y=exp(log(SelectedCss)-SelectedCss.sd),xend=Css.1comp.pred,yend=exp(log(SelectedCss)+SelectedCss.sd)))+
      geom_text(size=4,aes_string(y="SelectedCss", x="Css.1comp.pred",label="Compound.abbrev",color="Chemical"))+
      scale_y_log10(label=scientific_10,limits = c(5*10^-6, 110)) +
      scale_x_log10(label=scientific_10,limits = c(5*10^-6, 110)) +
      annotation_logticks() +
      geom_abline(slope=1, intercept=0) +
      ylab(expression(paste(italic("In vivo")," estimated ",C[ss]," (mg/L)"))) +
     xlab(expression(paste(italic("In vitro")," predicted ",C[ss]," (mg/L)"))) +
    #  scale_color_brewer(palette="Set2") +
      theme_bw()  +
      theme(legend.position="bottom")+
        annotate("text", x = textx/15, y = 5*texty, label = "A",size=6) +
      annotate("text",x = textx, y = texty,size=6, label = lm_R2(Fig.1compCss.fit),parse=T)+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))
    #  annotate("text",x = textx/3, y = texty/3,size=4, label = lm_R2(Fig.1compCss.fit.weighted,prefix="Weighted:"),parse=T)
    #  annotate("text",x = textx, y = texty,size=4, label = lm_R2(Fig.1compCss.fit.pharma,prefix="Pharmaceutical:"),parse=T)
    #  annotate("text",x = textx, y = texty/3,size=4, label = lm_R2(Fig.1compCss.fit.other,prefix="Other:"),parse=T)

    FitData$Css.Bio <- FitData$Css.1comp.pred*FitData$SelectedFbio
    Fig.1compCssb.fit <- lm(log(SelectedCss)~log(Css.Bio),data=FitData,na.rm=T)
    Fig.1compCssb.fit.weighted <- lm(log(SelectedCss)~log(Css.Bio),data=FitData,na.rm=T,weights=1/SelectedCss.sd^2)
    Fig.1compCssb.fit.pharma <- lm(log(SelectedCss)~log(Css.Bio),data=subset(FitData,Chemical!="Other"),na.rm=T)
    Fig.1compCssb.fit.other <- lm(log(SelectedCss)~log(Css.Bio),data=subset(FitData,Chemical=="Other"),na.rm=T)

    Fig.Cssb <- ggplot(data=FitData) +
      geom_segment(color="grey",aes(x=Css.Bio,y=exp(log(SelectedCss)-SelectedCss.sd),xend=Css.Bio,yend=exp(log(SelectedCss)+SelectedCss.sd)))+
      geom_text(size=4,aes_string(y="SelectedCss", x="Css.Bio",label="Compound.abbrev",color="Chemical"))+
      scale_y_log10(label=scientific_10,limits = c(5*10^-6, 110)) +
      scale_x_log10(label=scientific_10,limits = c(5*10^-6, 110)) +
      annotation_logticks() +
      geom_abline(slope=1, intercept=0) +
      ylab(expression(paste(italic("In vivo")," estimated ",C[ss]," (mg/L)"))) +
     xlab(expression(paste(italic("In vitro")," predicted ",C[ss]," (mg/L) Using Measured ", F[bio]))) +
     # scale_color_brewer(palette="Set2") +
      theme_bw()  +
      theme(legend.position="bottom")+
        annotate("text", x = textx/15, y = 5*texty, label = "B",size=6) +
      annotate("text",x = textx, y = texty,size=6, label = lm_R2(Fig.1compCssb.fit),parse=T)+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=10,height=6)
    multiplot(Fig.Cssa,Fig.Cssb,cols=2,widths=c(1.75,1.75))

## Figure Nine Evaluation of Wambaugh et al. (2015) classification scheme for predicting errors made when using HTTK data to predict in vivo steady state plasma concentration (Css). Chemicals were placed into categories, depending upon the size of the error. “On the Order” represented the best case, where errors were within 3.2 times over or under the true value. Some chemicals were determined to be problematic due to limitations in the HTTK methods (e.g., plasma protein binding estimation) or failure to come to steady state. Wherever the chemical names overlap the vertical, gray bands, the observed errors are consistent with predicted error. Chemicals can be identified by their chemical abbreviation given in Table 1.

    FitData$TriageCat <- FitData$Triage.Call
    FitData$CssResidual <- log10(FitData$Css.1comp.pred/FitData$Css)
    FitData[FitData$TriageCat%in%c("Does Not Reach Steady State","Plasma Binding Assay Failed"),"TriageCat"]<-"Problem"
    FitData$TriageCat <- factor(FitData$TriageCat,levels=c(">10x Underestimated",">3.2x Underestimated","On the Order",">3.2x Overestimated",">10x Overestimated","Problem"))

    Fig.Triage <- ggplot(data=subset(FitData,!is.na(TriageCat)&is.finite(CssResidual))) +
      geom_text(size=4,aes_string(y="CssResidual", x="TriageCat",label="Compound.abbrev",color="Chemical"))+
      geom_segment(aes(x = factor(">10x Underestimated",levels=levels(FitData$TriageCat)), y = log10(1/10), xend = factor(">10x Underestimated",levels=levels(FitData$TriageCat)), yend = log10(1/30)), size=3,colour = "grey") +
     # geom_segment(aes(x = factor(">3.2x Underestimated",levels=levels(FitData$TriageCat)), y = log10(1/10), xend = factor(">3.2x Underestimated",levels=levels(FitData$TriageCat)), yend = log10(1/3.2)), size=3,colour = "grey") +
      geom_segment(aes(x = factor("On the Order",levels=levels(FitData$TriageCat)), y = log10(1/3.2), xend = factor("On the Order",levels=levels(FitData$TriageCat)), yend = log10(3.2)), size=3,colour = "grey") +
      geom_segment(aes(x = factor(">3.2x Overestimated",levels=levels(FitData$TriageCat)), y = log10(3.2), xend = factor(">3.2x Overestimated",levels=levels(FitData$TriageCat)), yend = log10(10)), size=3,colour = "grey") +
      geom_segment(aes(x = factor(">10x Overestimated",levels=levels(FitData$TriageCat)), y = log10(10), xend = factor(">10x Overestimated",levels=levels(FitData$TriageCat)), yend = log10(500)), size=3,colour = "grey") +
      geom_hline(yintercept=0)+
      geom_hline(yintercept=log10(1/10),linetype="dashed")+
        geom_hline(yintercept=log10(1/3.2),linetype="dashed")+
      geom_hline(yintercept=log10(3.2),linetype="dashed")+
      geom_hline(yintercept=log10(10),linetype="dashed")+
      geom_text(size=4,aes_string(y="CssResidual", x="TriageCat",label="Compound.abbrev",color="Chemical"))+
      scale_y_continuous(name=expression(paste("Actual error in ",C[ss]," prediction")),breaks=c(log10(1/10),log10(1/3.2),0,log10(3.2),1),labels=c(">10x Under",">3.2x Under","On the Order",">3.2x Over",">10x Over")) +
      xlab("Predicted Error") +
      theme_bw()  +
      theme(legend.position="bottom")+
      theme(axis.text.x = element_text(angle = 45, hjust = 1))+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=6,height=6)
    print(Fig.Triage)

## Figure Ten

Evaluation of the ability of in vitro HTTK data, coupled with a one-compartment model, to predict important TK statistics like the maximum plasma concentration (Cmax) for characterizing tissue exposure. A single point is plotted for each combination of chemical, dose amount, and dose route, either intravenous (iv) or per oral (po). In panel A, the one-compartment model is parameterized with a predicted volume of distribution and clearance, based upon in vitro measured parameters. Fbio is assumed to be 100%. In panel B, the in vivo measured Fbio is used to reduce the amount of the oral dose absorbed in the one-compartment model, to illustrate the improvement possible if Fbio could be predicted accurately.

    PKstats <- chem.invivo.PK.summary.data
    # Add a column indicating chemical type:
    PKstats$Chemical <- "Other"
    PKstats[sapply(PKstats$CAS,is.pharma),"Chemical"] <- "Pharmaceutical"

    FigCmaxa.fit <- lm(log(Cmax)~log(Cmax.pred),data=subset(PKstats,is.finite(Cmax)))
    summary(FigCmaxa.fit)
    #>
    #> Call:
    #> lm(formula = log(Cmax) ~ log(Cmax.pred), data = subset(PKstats,
    #>     is.finite(Cmax)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -6.1371 -1.2346  0.2675  1.5178  4.8863
    #>
    #> Coefficients:
    #>                Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)     -1.3360     0.2433  -5.491 3.26e-07 ***
    #> log(Cmax.pred)   1.1252     0.1178   9.552 1.37e-15 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 2.269 on 96 degrees of freedom
    #> Multiple R-squared:  0.4873, Adjusted R-squared:  0.4819
    #> F-statistic: 91.24 on 1 and 96 DF,  p-value: 1.366e-15

    FigCmaxa <- ggplot(data=subset(PKstats,is.finite(Cmax))) +
        geom_point(size=3,aes_string(y="Cmax",
                             x="Cmax.pred",
                             shape="Route",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits = c(10^-4, 10^4)) +
       scale_x_log10(label=scientific_10,limits = c(10^-4, 10^4)) +
        annotation_logticks() +
        geom_abline(slope=1, intercept=0) +
        ylab(expression(paste(italic("In vivo")," estimated ",C[max]))) +
        xlab(expression(paste(italic("In vitro")," predicted ",C[max]))) +
    #    scale_color_brewer(palette="Set2") +
        annotate("text", x = 10^-3, y = 300, label = "A",size=6) +
        annotate("text",x = 3*10^1, y = 10^-3, label = lm_R2(FigCmaxa.fit),parse=T,size=6) +
        theme_bw()  +
        theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    FigCmaxb.fit <- lm(log(Cmax)~log(Cmax.pred.Fbio),data=subset(PKstats,is.finite(Cmax)))
    summary(FigCmaxb.fit)
    #>
    #> Call:
    #> lm(formula = log(Cmax) ~ log(Cmax.pred.Fbio), data = subset(PKstats,
    #>     is.finite(Cmax)))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -3.4000 -1.0483 -0.1754  0.8846  3.9986
    #>
    #> Coefficients:
    #>                     Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)         -0.40618    0.19647  -2.067   0.0425 *
    #> log(Cmax.pred.Fbio)  1.18734    0.08181  14.513   <2e-16 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 1.639 on 68 degrees of freedom
    #>   (28 observations deleted due to missingness)
    #> Multiple R-squared:  0.756,  Adjusted R-squared:  0.7524
    #> F-statistic: 210.6 on 1 and 68 DF,  p-value: < 2.2e-16

    FigCmaxb <- ggplot(data=subset(PKstats,is.finite(Cmax))) +
        geom_point(size=3,aes_string(y="Cmax",
                             x="Cmax.pred.Fbio",
                             shape="Route",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits = c(10^-4, 10^4)) +
       scale_x_log10(label=scientific_10,limits = c(10^-4, 10^4)) +
        annotation_logticks() +
        geom_abline(slope=1, intercept=0) +
        ylab(expression(paste(italic("In vivo")," estimated ",C[max]))) +
        xlab(expression(paste("Predicted ", C[max], " Using Measured ", F[bio ]))) +
        annotate("text", x = 10^-3, y = 300, label = "B",size=6) +
        annotate("text",x = 3*10^1, y = 10^-3, label = lm_R2(FigCmaxb.fit),parse=T,size=6) +
    #    scale_color_brewer(palette="Set2") +
        theme_bw()  +
        theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=10,height=6)
    multiplot(FigCmaxa,FigCmaxb,cols=2,widths=c(1.75,1.75))

## Figure Eleven Evaluation of predictions for the time integrated plasma concentration (i.e., area under the curve or AUC). A single point is plotted for each combination of chemical, dose amount, and dose route, either intravenous (iv) or per oral (po). In panel A, the one-compartment model is parameterized with a predicted volume of distribution and clearance, based upon in vitro measured parameters. Fbio is assumed to be 100%. In panel B, the in vivo measured Fbio is used to reduce the amount of the oral dose absorbed in the one-compartment model, to illustrate the improvement possible if Fbio could be predicted accurately. The solid line in each panel indicates the identity line (1:1, perfect predictions).

    FigAUCa.fit <- lm(log(AUC)~log(AUC.pred),data=subset(PKstats,is.finite(log(AUC))))
    FigAUCb.fit <- lm(log(AUC)~log(AUC.pred.Fbio),data=subset(PKstats,is.finite(log(AUC))))
    summary(FigAUCa.fit)
    #>
    #> Call:
    #> lm(formula = log(AUC) ~ log(AUC.pred), data = subset(PKstats,
    #>     is.finite(log(AUC))))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -5.9390 -1.1020  0.1627  1.1210  4.1205
    #>
    #> Coefficients:
    #>               Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)    1.03627    0.21780   4.758 7.06e-06 ***
    #> log(AUC.pred)  1.12330    0.09189  12.225  < 2e-16 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 1.95 on 94 degrees of freedom
    #> Multiple R-squared:  0.6139, Adjusted R-squared:  0.6098
    #> F-statistic: 149.4 on 1 and 94 DF,  p-value: < 2.2e-16
    summary(FigAUCb.fit)
    #>
    #> Call:
    #> lm(formula = log(AUC) ~ log(AUC.pred.Fbio), data = subset(PKstats,
    #>     is.finite(log(AUC))))
    #>
    #> Residuals:
    #>     Min      1Q  Median      3Q     Max
    #> -3.1541 -0.9817  0.0086  0.8015  4.1295
    #>
    #> Coefficients:
    #>                    Estimate Std. Error t value Pr(>|t|)
    #> (Intercept)         1.75737    0.23544   7.464 2.22e-10 ***
    #> log(AUC.pred.Fbio)  1.04066    0.06988  14.891  < 2e-16 ***
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> Residual standard error: 1.567 on 67 degrees of freedom
    #>   (27 observations deleted due to missingness)
    #> Multiple R-squared:  0.768,  Adjusted R-squared:  0.7645
    #> F-statistic: 221.8 on 1 and 67 DF,  p-value: < 2.2e-16

    FigAUCa <- ggplot(data=subset(PKstats,is.finite(log(AUC)))) +
        geom_point(size=3,aes_string(y="AUC",
                             x="AUC.pred",
                             shape="Route",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits = c(10^-3, 10^4)) +
       scale_x_log10(label=scientific_10,limits = c(10^-3, 10^4)) +
        annotation_logticks() +
        geom_abline(slope=1, intercept=0) +
        ylab(expression(paste(italic("In vivo")," estimated AUC (mg*h/L)"))) +
        xlab(expression(paste(italic("In vitro")," predicted Area under the Curve (AUC, mg*h/L)"))) +
        annotate("text", x = 10^-2, y = 3000, label = "A",size=6) +
        annotate("text",x = 3*10^1, y = 10^-2, label = lm_R2(FigAUCa.fit),parse=T,size=6) +
        theme_bw()  +
        theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    FigAUCb <- ggplot(data=subset(PKstats,is.finite(log(AUC)))) +
        geom_point(size=3,aes_string(y="AUC",
                             x="AUC.pred.Fbio",
                             shape="Route",
                             color="Chemical"))+
       scale_y_log10(label=scientific_10,limits = c(10^-3, 10^4)) +
       scale_x_log10(label=scientific_10,limits = c(10^-3, 10^4)) +
        annotation_logticks() +
        geom_abline(slope=1, intercept=0) +
        ylab(expression(paste(italic("In vivo")," estimated AUC (mg*h/L)"))) +
        xlab(expression(paste("Predicted AUC (mg*h/L) Using Measured ", F[bio]))) +
        annotate("text", x = 10^-2, y = 3000, label = "B",size=6) +
        annotate("text",x = 3*10^1, y = 10^-2, label = lm_R2(FigAUCb.fit),parse=T,size=6) +
        theme_bw()  +
        theme(legend.position="bottom")+
        guides(shape=guide_legend(nrow=2,byrow=TRUE),color=guide_legend(nrow=2,byrow=TRUE))

    #dev.new(width=10,height=6)
    multiplot(FigAUCa,FigAUCb,cols=2,widths=c(1.75,1.75))