---
title: "Honda et al. (2019): Updated Armitage et al. (2014) Model"
author: "Gregory S. Honda"
date: "July 13, 2018"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{f) Honda (2019): Updated Armitage et al. (2014) Model}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---
*Please send questions to John.Wambaugh@UL.org*

from "Using the concordance of *in vitro* and *in vivo* data to evaluate extrapolation assumptions"

Gregory S. Honda, Robert G. Pearce, Ly L. Pham, R. W. Setzer, Barbara A. Wetmore,
Nisha S. Sipes, Jon Gilbert, Briana Franz, Russell S. Thomas, John F. Wambaugh 

PLoS ONE 14(5): e0217564.

https://doi.org/10.1371/journal.pone.0217564

The authors thank James Armitage for providing a revised version of his model (
https://doi.org/10.1021/es501955g). 

## Abstract
Linking *in vitro* bioactivity and *in vivo* toxicity on a dose basis enables the 
use of high-throughput in vitro assays as an alternative to traditional animal 
studies. In this study, we evaluated assumptions in the use of a 
high-throughput, physiologically based toxicokinetic (PBTK) model to relate 
*in vitro* bioactivity and rat *in vivo* toxicity data. The fraction unbound in 
plasma ($f_{up}$) and intrinsic hepatic clearance ($Cl_{int}$) were measured for rats 
(for 67 and 77 chemicals, respectively), combined with fup and $Cl_{int}$ 
literature data for 97 chemicals, and incorporated in the PBTK model. Of 
these chemicals, 84 had corresponding *in vitro* ToxCast bioactivity data and 
*in vivo* toxicity data. For each possible comparison of *in vitro* and *in vivo* 
endpoint, the concordance between the *in vivo* and *in vitro* data was evaluated 
by a regression analysis. For a base set of assumptions, the PBTK results 
were more frequently better associated than either the results from a 
"random" model parameterization or direct comparison of the "untransformed" 
values of $AC_{50}$ and dose (performed best in 51%, 28%, and 21% of cases, 
respectively). We also investigated several assumptions in the application 
of PBTK for *in vitro-in vivo* extrapolation (IVIVE), including clearance and 
internal dose selection. One of 
the better assumptions sets-restrictive clearance and comparing free *in vivo*
venous plasma concentration with free *in vitro* concentration-outperformed 
the random and untransformed results in 71% of the *in vitro-in vivo* endpoint 
comparisons. These results demonstrate that applying PBTK improves our 
ability to observe the association between *in vitro* bioactivity and *in vivo* 
toxicity data in general. This suggests that potency values from *in vitro* 
screening should be transformed using IVIVE 
to build potentially better machine learning and other statistical models 
for predicting in vivo toxicity in humans.

## HTTK Version

This vignette was created with **httk** v1.9. Although we attempt to maintain 
backward compatibility, if you encounter issues with the latest release of 
**httk**
and cannot easily address the changes, historical versions of httk are 
available from: https://cran.r-project.org/src/contrib/Archive/httk/

## Prepare for session
R package **knitr** generates html and PDF documents from this RMarkdown file,
Each bit of code that follows is known as a "chunk". We start by telling 
**knitr** how we want our chunks to look.
```{r setup, include=FALSE, eval = TRUE}
knitr::opts_chunk$set(echo = TRUE, fig.width=6, fig.height=5)
```

### Clear the memory
It is a bad idea to let variables and other information from previous R
sessions float around, so we first remove everything in the R memory.
```{r clear_memory, eval = TRUE}
rm(list=ls()) 
```

### eval = execute.vignette
If you are using the RMarkdown version of this vignette (extension, .RMD) you
will be able to see that several chunks of code in this vignette
have the statement "eval = execute.vignette". The next chunk of code, by default,
sets execute.vignette = FALSE.  This means that the code is included (and necessary) but was
not run when the vignette was built. We do this because some steps require 
extensive computing time and the checks on CRAN limit how long we can spend
building the package. If you want this vignette to work, you must run all code,
either by cutting and pasting it into R. Or, if viewing the .RMD file, you can
either change execute.vignette to TRUE or press "play" (the green arrow) on
each chunk in RStudio.
```{r runchunks, eval = TRUE}
# Set whether or not the following chunks will be executed (run):
execute.vignette <- FALSE
```

### Load the relevant libraries
If you get the message "Error in library(X) : there is no package called 'X'"
then you will need to install that package: 

From the R command prompt:

install.packages("X")

Or, if using RStudio, look for 'Install Packages' under 'Tools' tab.
```{r InitialPrep, eval = execute.vignette}
library(data.table)
library(magrittr)
library(ggplot2)
library(httk)
library(httkexamples)
```

## Updated Armitage 2014 Top Panel Figure 3

This produces an updated version of the top panel of Figure 3 from the paper 
[Armitage, 2014](https://doi.org/10.1021/es501955g)


```{r MakeTable, eval = execute.vignette}
armitage.dt <- copy(armitage_input)
armitage.dt[,well_number:=384] %>% 
  .[,option.bottom:=TRUE] %>% 
  .[,option.plastic:=TRUE] %>% 
  .[,Tsys:=37] %>% 
  .[,Tref:=298.15] %>% 
  .[,FBSf:=0.1] %>% 
  .[,nomconc:=50]

# Make sure we have data for the chemical:
armitage.dt <- subset(armitage.dt,casrn%in%get_cheminfo(model="armitage"))
# These chemicals are missing water solubilities:
armitage.dt <- subset(armitage.dt,!(casrn%in%c("71751-41-2","34590-94-8","141517-21-7")))

armitage.dt2 <- armitage_estimate_sarea(tcdata = armitage.dt)
armitage_output1 <- armitage_eval(tcdata = armitage.dt2[,ac50:=50])
armitage_output2 <- armitage_eval(tcdata = armitage.dt2[,ac50:=1])
armitage_output3 <- armitage_eval(tcdata = armitage.dt2[,ac50:=0.001])

```

## Plot results

```{r MakePlot, echo=TRUE, eval = execute.vignette}
armitage_output <- rbind(armitage_output1[,xfill:="50 \U00B5M"],
                         armitage_output2[,xfill:="1 \U00B5M"],
                         armitage_output3[,xfill:="1 nM"])
armitage_output[,xfill:=factor(xfill,levels=c("50 \U00B5M","1 \U00B5M","1 nM"))]

ggplot(armitage_output) +
  geom_point(aes(x=gkow,y=log10(ccells/MW*1e9),color=xfill),shape=1) +
  labs(color=expression("AC"["50"]),x="log P", y = "log(ng chemical/g cells)") +
  theme_bw()
```


