Skip to content

Commit

Permalink
Update readme (#10)
Browse files Browse the repository at this point in the history
* Updated readme

* Updated readme
  • Loading branch information
SkylarMarvel authored Oct 18, 2023
1 parent 4d5b466 commit 9d2b75b
Show file tree
Hide file tree
Showing 3 changed files with 254 additions and 34 deletions.
131 changes: 120 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ knitr::opts_chunk$set(

<!-- badges: start -->

[![test-coverage](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/test-coverage.yaml)
[![codecov](https://codecov.io/github/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/graph/badge.svg?token=I1L9BZJ58Y)](https://codecov.io/github/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage)
[![R-CMD-check](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/check-release.yaml/badge.svg)](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/check-release.yaml)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![CRAN status](https://www.r-pkg.org/badges/version/GeoToxPackage)](https://CRAN.R-project.org/package=GeoToxPackage)

<!-- badges: end -->
Expand All @@ -34,25 +37,131 @@ devtools::install_github("Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage"

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(GeoToxPackage)
## basic example code
library(dplyr, warn.conflicts = FALSE)
```

### Estimate chemical concentration-response curves

```{r chem}
conc <- 10^rep(-2:2, each = 3)
tp <- 100 # top asymptote
ga <- 1.6 # AC50
gw <- 1.2 # slope
resp <- tp / (1 + (ga / conc)^gw) + rnorm(length(conc), sd = 5)
fit_2param <- fit_hill(log10(conc), resp) # slope fixed at 1
fit_3param <- fit_hill(log10(conc), resp, fixed_slope = FALSE)
rbind(
"inputs" = c(tp, log10(ga), gw, NA),
"3-param" = c(fit_3param$par),
"2-param" = c(fit_2param$par[1:2], 1, fit_2param$par[3])
)
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:
### Estimate population dose-response

Input data

```{r input_data}
# Number of samples to simulate
MC_iter <- 10
# Number of chemicals to simulate
n_chem <- 4
# Create age groups and group sizes
age <- data.frame(
AGEGRP = 0:18,
TOT_POP = c(0, round(runif(18, max = 1000)))
)
age$TOT_POP[1] <- sum(age$TOT_POP[-1])
# Create chemical exposure mean and sd
exposure <- data.frame(
mean = (1 + runif(n_chem))*1e-6,
sd = (1 + runif(n_chem))*1e-7
)
# Create chemical concentration-response data
conc_resp <- lapply(1:n_chem, function(idx) {
conc <- 10^rep(-2:2, each = 3)
tp <- 100 + rnorm(1, sd = 15)
ga <- 10^(2 * runif(1) - 1)
gw <- 1 + rnorm(1)/5
resp <- tp / (1 + (ga / conc)^gw) + rnorm(length(conc))
resp[resp < 0] <- 0
data.frame(
logc = log10(conc),
resp = resp
)
})
fits <- lapply(conc_resp, function(df) {
fit_hill(df$logc, df$resp)
})
chem_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
) %>%
mutate(across(tp:AIC, ~ as.numeric(.x)))
})
)
```{r cars}
summary(cars)
# Steady-state concentration (will be generated from httk)
C_ss <- matrix(runif(n_chem * MC_iter), nrow = MC_iter)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.
Simulate data

You can also embed plots, for example:
```{r simulate}
# Simulate age based on relative population group sizes
simulated_age <- simulate_age(
age,
n = MC_iter
)
```{r pressure, echo = FALSE}
plot(pressure)
# Simulate inhalation rate using default params
simulated_IR <- simulate_inhalation_rate(
simulated_age
)
# Simulate external exposure
simulated_exposure <- simulate_exposure(
exposure$mean,
exposure$sd,
n = MC_iter
)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.
Computations

```{r calculate}
internal_dose <- calc_internal_dose(
C_ext = simulated_exposure,
IR = simulated_IR
)
invitro_concentration <- calc_invitro_concentration(
D_int = internal_dose,
C_ss = C_ss
)
concentration_response <- calc_concentration_response(
resp = chem_params,
concentration = invitro_concentration
)
concentration_response
```
156 changes: 133 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# GeoToxPackage

<!-- badges: start -->

[![test-coverage](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/test-coverage.yaml/badge.svg)](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/test-coverage.yaml)
[![codecov](https://codecov.io/github/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/graph/badge.svg?token=I1L9BZJ58Y)](https://codecov.io/github/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage)
[![R-CMD-check](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/check-release.yaml/badge.svg)](https://github.com/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/actions/workflows/check-release.yaml)
Expand Down Expand Up @@ -32,39 +33,148 @@ You can install the development version of GeoToxPackage from
devtools::install_github("Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage")
```

## Code Coverage
![Code Coverage Visualization](https://codecov.io/github/Spatiotemporal-Exposures-and-Toxicology/GeoToxPackage/graphs/sunburst.svg?token=I1L9BZJ58Y)


## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(GeoToxPackage)
## basic example code
library(dplyr, warn.conflicts = FALSE)
```

What is special about using `README.Rmd` instead of just `README.md`?
You can include R chunks like so:
### Estimate chemical concentration-response curves

``` r
summary(cars)
#> speed dist
#> Min. : 4.0 Min. : 2.00
#> 1st Qu.:12.0 1st Qu.: 26.00
#> Median :15.0 Median : 36.00
#> Mean :15.4 Mean : 42.98
#> 3rd Qu.:19.0 3rd Qu.: 56.00
#> Max. :25.0 Max. :120.00
conc <- 10^rep(-2:2, each = 3)
tp <- 100 # top asymptote
ga <- 1.6 # AC50
gw <- 1.2 # slope
resp <- tp / (1 + (ga / conc)^gw) + rnorm(length(conc), sd = 5)

fit_2param <- fit_hill(log10(conc), resp) # slope fixed at 1
fit_3param <- fit_hill(log10(conc), resp, fixed_slope = FALSE)

rbind(
"inputs" = c(tp, log10(ga), gw, NA),
"3-param" = c(fit_3param$par),
"2-param" = c(fit_2param$par[1:2], 1, fit_2param$par[3])
)
#> tp logAC50 slope t-error
#> inputs 100.00000 0.2041200 1.200000 NA
#> 3-param 97.63578 0.1516374 1.485236 1.177891
#> 2-param 101.53494 0.2360917 1.000000 1.417567
```

You’ll still need to render `README.Rmd` regularly, to keep `README.md`
up-to-date. `devtools::build_readme()` is handy for this.
### Estimate population dose-response

You can also embed plots, for example:
Input data

``` r
# Number of samples to simulate
MC_iter <- 10

# Number of chemicals to simulate
n_chem <- 4

# Create age groups and group sizes
age <- data.frame(
AGEGRP = 0:18,
TOT_POP = c(0, round(runif(18, max = 1000)))
)
age$TOT_POP[1] <- sum(age$TOT_POP[-1])

# Create chemical exposure mean and sd
exposure <- data.frame(
mean = (1 + runif(n_chem))*1e-6,
sd = (1 + runif(n_chem))*1e-7
)

# Create chemical concentration-response data
conc_resp <- lapply(1:n_chem, function(idx) {
conc <- 10^rep(-2:2, each = 3)
tp <- 100 + rnorm(1, sd = 15)
ga <- 10^(2 * runif(1) - 1)
gw <- 1 + rnorm(1)/5
resp <- tp / (1 + (ga / conc)^gw) + rnorm(length(conc))
resp[resp < 0] <- 0
data.frame(
logc = log10(conc),
resp = resp
)
})
fits <- lapply(conc_resp, function(df) {
fit_hill(df$logc, df$resp)
})
chem_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
) %>%
mutate(across(tp:AIC, ~ as.numeric(.x)))
})
)

# Steady-state concentration (will be generated from httk)
C_ss <- matrix(runif(n_chem * MC_iter), nrow = MC_iter)
```

<img src="man/figures/README-pressure-1.png" width="100%" />
Simulate data

In that case, don’t forget to commit and push the resulting figure
files, so they display on GitHub and CRAN.
``` r
# Simulate age based on relative population group sizes
simulated_age <- simulate_age(
age,
n = MC_iter
)

# Simulate inhalation rate using default params
simulated_IR <- simulate_inhalation_rate(
simulated_age
)

# Simulate external exposure
simulated_exposure <- simulate_exposure(
exposure$mean,
exposure$sd,
n = MC_iter
)
```

Computations

``` r
internal_dose <- calc_internal_dose(
C_ext = simulated_exposure,
IR = simulated_IR
)

invitro_concentration <- calc_invitro_concentration(
D_int = internal_dose,
C_ss = C_ss
)

concentration_response <- calc_concentration_response(
resp = chem_params,
concentration = invitro_concentration
)

concentration_response
#> GCA.Eff IA.eff GCA.HQ.10 IA.HQ.10
#> 1 1.316500e-04 1.316519e-04 1.197871e-05 1.197851e-05
#> 2 1.928066e-04 1.928077e-04 1.756148e-05 1.756120e-05
#> 3 1.509427e-04 1.509448e-04 1.339909e-05 1.339880e-05
#> 4 1.931396e-04 1.931407e-04 1.742350e-05 1.742319e-05
#> 5 2.000661e-04 2.000678e-04 1.748640e-05 1.748673e-05
#> 6 9.090331e-05 9.090415e-05 8.634445e-06 8.634337e-06
#> 7 6.336773e-05 6.336758e-05 5.870044e-06 5.869961e-06
#> 8 1.501012e-04 1.501024e-04 1.365014e-05 1.364991e-05
#> 9 7.009742e-05 7.009701e-05 6.962928e-06 6.962838e-06
#> 10 7.310190e-05 7.310279e-05 6.848001e-06 6.847910e-06
```
1 change: 1 addition & 0 deletions vignettes/dev-conc-resp.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fits <- lapply(ice_conc_resp, function(df) {
### Extract fit parameters

```{r fit_params}
# TODO should this be made into a package function?
fit_params <- do.call(
rbind,
lapply(fits, function(fit) {
Expand Down

0 comments on commit 9d2b75b

Please sign in to comment.