-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added conc resp vignette * Removed tcpl comparison data from vignette * Adjust age order to match GeoToxMIE script
- Loading branch information
1 parent
03a99e9
commit ba158f6
Showing
5 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
title: "dev-conc-resp" | ||
output: rmarkdown::html_vignette | ||
vignette: > | ||
%\VignetteIndexEntry{dev-conc-resp} | ||
%\VignetteEngine{knitr::rmarkdown} | ||
%\VignetteEncoding{UTF-8} | ||
--- | ||
|
||
```{r, include = FALSE} | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
``` | ||
|
||
```{r setup} | ||
library(GeoToxPackage) | ||
options(tidyverse.quiet = TRUE) | ||
library(tidyverse) | ||
``` | ||
|
||
### Load data | ||
|
||
```{r load_data} | ||
# Load dose response data | ||
load("~/dev/GeoTox/data/LTEA_HepaRG_CYP1A1_up 41 chems for Kyle 220131.RData") | ||
ice_data <- cdat; rm(cdat) | ||
``` | ||
|
||
### Format data | ||
|
||
```{r format_data} | ||
# Split dose response data by chemical | ||
ice_conc_resp <- split(as.data.frame(ice_data), ~casn) | ||
``` | ||
|
||
### 2-parameter Hill fit | ||
|
||
```{r fits} | ||
fits <- lapply(ice_conc_resp, function(df) { | ||
suppressWarnings( | ||
fit_hill(df$logc, df$resp) | ||
) | ||
}) | ||
``` | ||
|
||
### Extract fit parameters | ||
|
||
```{r fit_params} | ||
fit_params <- do.call( | ||
rbind, | ||
lapply(fits, function(fit) { | ||
as_tibble(t(unlist(fit))) %>% | ||
rename( | ||
tp = par.tp, | ||
tp.sd = sds.tp, | ||
logAC50 = par.logAC50, | ||
logAC50.sd = sds.logAC50 | ||
) %>% | ||
select( | ||
tp, tp.sd, logAC50, logAC50.sd, | ||
logc_min, logc_max, resp_min, resp_max, AIC | ||
) | ||
}) | ||
) | ||
``` | ||
|
||
### Replace NA sd with mean | ||
|
||
```{r replace_na} | ||
# TODO is this a good idea? See plots below | ||
fit_params <- fit_params %>% | ||
mutate( | ||
tp.na = is.na(tp.sd), # for plot below | ||
logAC50.na = is.na(logAC50.sd), # for plot below | ||
tp.sd = if_else(is.na(tp.sd), tp, tp.sd), | ||
logAC50.sd = if_else(is.na(logAC50.sd), logAC50, logAC50.sd) | ||
) | ||
``` | ||
|
||
```{r} | ||
xylim <- range(with(fit_params, c(tp, tp.sd)), na.rm = T) | ||
ggplot(fit_params, aes(tp, tp.sd)) + | ||
geom_abline(linetype = 3) + | ||
geom_point(aes(color = tp.na), show.legend = FALSE) + | ||
coord_cartesian(xlim = xylim, ylim = xylim) | ||
``` | ||
|
||
```{r} | ||
xylim <- range(with(fit_params, c(logAC50, logAC50.sd)), na.rm = T) | ||
ggplot(fit_params, aes(logAC50, logAC50.sd)) + | ||
geom_abline(linetype = 3) + | ||
geom_point(aes(color = logAC50.na), show.legend = FALSE) + | ||
coord_cartesian(xlim = xylim, ylim = xylim) | ||
``` | ||
|
||
### Plot fits | ||
|
||
```{r plot_fits} | ||
log10_x <- seq(-3, 3, length.out = 100) | ||
y <- as.matrix( | ||
apply(fit_params[, c("tp", "logAC50")], 1, function(par) { | ||
par["tp"] / (1 + 10^(par["logAC50"] - log10_x)) | ||
}) | ||
) | ||
colnames(y) <- names(ice_conc_resp) | ||
y <- as_tibble(y) %>% mutate(x = 10^log10_x, .before = 1) | ||
ggplot(y %>% pivot_longer(!x), aes(x, value, color = name)) + | ||
geom_line(show.legend = FALSE) + | ||
scale_x_log10(labels = scales::label_math(10^.x, format = log10)) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters