Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples #72

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GeoTox
Title: Spatiotemporal Mixture Risk Assessment
Version: 0.1.3
Version: 0.1.4
Authors@R: c(
person("Skylar", "Marvel", , "skylar.marvel@nih.gov", role = c("aut", "ctb"), comment = c(ORCID = "0000-0002-2971-9743")),
person("David", "Reif", , "david.reif@nih.gov", role = c("aut", "ctb"), comment = c(ORCID = "0000-0001-7815-6767")),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export(get_fixed_css)
export(get_fixed_obesity)
export(get_fixed_other)
export(get_fixed_params)
export(hill_conc)
export(hill_val)
export(plot_exposure)
export(plot_hill)
export(plot_resp)
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# GeoTox 0.1.3
# GeoTox 0.1.4
- Updated unit test coverage and function examples

# GeoTox 0.0.1
- Adding supporting documents to the `GeoTox` repository such as this news.md, issue templates, and contributor's guide
Expand Down
2 changes: 1 addition & 1 deletion R/GeoTox.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#' # Plot hill fits
#' plot(geoTox, type = "hill")
#' # Plot exposure data
#' plot(geoTox, type = "exposure")
#' plot(geoTox, type = "exposure", ncol = 5)
#' # Plot response data
#' plot(geoTox)
#' plot(geoTox, assays = "TOX21_H2AX_HTRF_CHO_Agonist_ratio")
Expand Down
18 changes: 16 additions & 2 deletions R/calc_concentration_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,23 @@
#' generalized concentration addition response, the independent action
#' response, and a hazard quotient
#'
#' @return data frame
#'
#' @return list of data frames
#' @export
#'
#' @examples
#' C_invitro <- list(
#' matrix(1:8 / 1e3, ncol = 2, dimnames = list(NULL, c("c1", "c2"))),
#' matrix(9:16 / 1e3, ncol = 2, dimnames = list(NULL, c("c1", "c2")))
#' )
#' hill_params <- fit_hill(
#' data.frame(chem = rep(c("c1", "c2"), each = 3),
#' logc = c(-1, 0, 1, 0, 1, 2),
#' resp = c(10, 5, 0, 4, 2, 0) / 10),
#' chem = "chem"
#' )
#'
#' calc_concentration_response(C_invitro, hill_params)
#' calc_concentration_response(C_invitro, hill_params, fixed = TRUE)
calc_concentration_response <- function(C_invitro,
hill_params,
max_mult = 1.5,
Expand Down
9 changes: 9 additions & 0 deletions R/calc_independent_action.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@
#' response function for each chemical.
#'
#' @seealso \code{\link{hill_val}}
#'
#' @examples
#' n_chem <- 5
#' conc <- 10^sample(-1:4, n_chem, replace = TRUE)
#' max <- 80 * runif(n_chem)
#' AC50 <- 10^(5 * runif(n_chem) - 1)
#' Emax <- 100
#'
#' calc_independent_action(conc, max, AC50, Emax)
calc_independent_action <- function(conc, max, AC50, Emax, n = 1) {

# if (any(max > Emax)) {
Expand Down
34 changes: 19 additions & 15 deletions R/calculate_response.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@
#' [calc_concentration_response]
#'
#' @examples
#' # Create GeoTox object
#' geoTox <- GeoTox()
#' # Use a subset of the package data for demonstration purposes
#' set.seed(2357)
#' n <- 10 # Population size
#' m <- 5 # Number of regions
#' idx <- if (m < 100) sample(1:100, m) else 1:100
#'
#' # The following fields are required inputs
#' geoTox$IR <- 2
#' geoTox$C_ext <- matrix(3)
#' geoTox$C_ss <- 5
#' geoTox$hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1),
#' resp = c(10, 5, 0)))
#' # Create GeoTox object and populate required fields
#' geoTox <- GeoTox() |>
#' # Simulate populations for each region
#' simulate_population(age = split(geo_tox_data$age, ~FIPS)[idx],
#' obesity = geo_tox_data$obesity[idx, ],
#' exposure = split(geo_tox_data$exposure, ~FIPS)[idx],
#' simulated_css = geo_tox_data$simulated_css,
#' n = n) |>
#' # Estimated Hill parameters
#' set_hill_params(geo_tox_data$dose_response |>
#' fit_hill(assay = "endp", chem = "casn") |>
#' dplyr::filter(!tp.sd.imputed, !logAC50.sd.imputed))
#'
#' # Calculate response
#' geoTox <- calculate_response(geoTox)
#'
#' # The following fields will be computed
#' geoTox$D_int
#' geoTox$C_invitro
#' geoTox$resp
#' # Response computations can now be done
#' geoTox <- geoTox |> calculate_response()
calculate_response <- function(x, ...) {

# Update parameters
Expand Down
24 changes: 24 additions & 0 deletions R/compute_sensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,30 @@
#'
#' @return output from [calc_concentration_response]
#' @export
#'
#' @examples
#' # Use a subset of the package data for demonstration purposes
#' set.seed(2357)
#' n <- 10 # Population size
#' m <- 5 # Number of regions
#' idx <- if (m < 100) sample(1:100, m) else 1:100
#'
#' # Create GeoTox object and populate required fields
#' geoTox <- GeoTox() |>
#' # Simulate populations for each region
#' simulate_population(age = split(geo_tox_data$age, ~FIPS)[idx],
#' obesity = geo_tox_data$obesity[idx, ],
#' exposure = split(geo_tox_data$exposure, ~FIPS)[idx],
#' simulated_css = geo_tox_data$simulated_css,
#' n = n) |>
#' # Estimated Hill parameters
#' set_hill_params(geo_tox_data$dose_response |>
#' fit_hill(assay = "endp", chem = "casn") |>
#' dplyr::filter(!tp.sd.imputed, !logAC50.sd.imputed))
#'
#' # Sensitivity computations can now be done
#' age_resp <- geoTox |> compute_sensitivity()
#' obesity_resp <- geoTox |> compute_sensitivity(vary = "obesity")
compute_sensitivity <- function(x,
vary = c("age", "obesity", "css_params",
"fit_params", "C_ext"),
Expand Down
3 changes: 2 additions & 1 deletion R/hill_conc.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#' @param AC50 concentration of half-maximal response
#' @param n Hill coefficient (slope)
#'
#' @keywords internal
#'
#' @return concentration in regular space
#' @export
#'
#' @details
#' This is a regular space version of
Expand Down
3 changes: 2 additions & 1 deletion R/hill_val.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
#' @param AC50 concentration of half-maximal response
#' @param n Hill coefficient (slope)
#'
#' @keywords internal
#'
#' @return response value
#' @export
#'
#' @details
#' This is a regular space version of
Expand Down
2 changes: 2 additions & 0 deletions R/obj_ECx.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' @param max maximal (asymtotic) response
#' @param AC50 concentrations of half-maximal response
#'
#' @keywords internal
#'
#' @return objective value
obj_ECx <- function(conc_mix, resp, conc, max, AC50) {
x <- hill_conc(resp, max, AC50, 1)
Expand Down
2 changes: 2 additions & 0 deletions R/obj_GCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#' @param max maximal (asymtotic) responses
#' @param AC50 concentrations of half-maximal response
#'
#' @keywords internal
#'
#' @return objective value
obj_GCA <- function(ln_resp, conc, max, AC50) {
# Solving for the efficacy on the natural log-scale. This allows for
Expand Down
2 changes: 2 additions & 0 deletions R/obj_hill.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#' @param log10_conc base-10 log scale concentration
#' @param resp response
#'
#' @keywords internal
#'
#' @return value of the objective function
obj_hill <- function(par, log10_conc, resp) {

Expand Down
16 changes: 8 additions & 8 deletions R/plot_sensitivity.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#' c("sample", metric)))
#' }
#'
#' x <- GeoTox()
#' x$resp <- make_data()
#' x$sensitivity <- list(age = make_data(),
#' obesity = make_data(),
#' css_params = make_data(),
#' fit_params = make_data(),
#' C_ext = make_data())
#' geoTox <- GeoTox()
#' geoTox$resp <- make_data()
#' geoTox$sensitivity <- list(age = make_data(),
#' obesity = make_data(),
#' css_params = make_data(),
#' fit_params = make_data(),
#' C_ext = make_data())
#'
#' plot_sensitivity(x)
#' plot_sensitivity(geoTox)
plot_sensitivity <- function(x,
metric = "GCA.Eff",
assay = NULL,
Expand Down
23 changes: 23 additions & 0 deletions R/sensitivity_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@
#'
#' @return The same GeoTox object with added `sensitivity` field.
#' @export
#'
#' @examples
#' # Use a subset of the package data for demonstration purposes
#' set.seed(2357)
#' n <- 10 # Population size
#' m <- 5 # Number of regions
#' idx <- if (m < 100) sample(1:100, m) else 1:100
#'
#' # Create GeoTox object and populate required fields
#' geoTox <- GeoTox() |>
#' # Simulate populations for each region
#' simulate_population(age = split(geo_tox_data$age, ~FIPS)[idx],
#' obesity = geo_tox_data$obesity[idx, ],
#' exposure = split(geo_tox_data$exposure, ~FIPS)[idx],
#' simulated_css = geo_tox_data$simulated_css,
#' n = n) |>
#' # Estimated Hill parameters
#' set_hill_params(geo_tox_data$dose_response |>
#' fit_hill(assay = "endp", chem = "casn") |>
#' dplyr::filter(!tp.sd.imputed, !logAC50.sd.imputed))
#'
#' # Sensitivity analysis can now be done
#' geoTox <- geoTox |> sensitivity_analysis()
sensitivity_analysis <- function(x,
max_mult = list(NULL, NULL, NULL,
1.2, NULL)) {
Expand Down
21 changes: 13 additions & 8 deletions R/simulate_population.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
#' @export
#'
#' @examples
#' # For information about geo_tox_data, see:
#' # vignette("package_data", package = "GeoTox")
#'
#' geoTox <- GeoTox() |>
#' simulate_population(age = split(geo_tox_data$age, ~FIPS)[1:5],
#' obesity = geo_tox_data$obesity[1:5, ],
#' exposure = split(geo_tox_data$exposure, ~FIPS)[1:5],
#' # Use a subset of the package data for demonstration purposes
#' set.seed(2357)
#' n <- 10 # Population size
#' m <- 5 # Number of regions
#' idx <- if (m < 100) sample(1:100, m) else 1:100
#'
#' # Create GeoTox object
#' geoTox <- GeoTox() |>
#' # Simulate populations for each region
#' simulate_population(age = split(geo_tox_data$age, ~FIPS)[idx],
#' obesity = geo_tox_data$obesity[idx, ],
#' exposure = split(geo_tox_data$exposure, ~FIPS)[idx],
#' simulated_css = geo_tox_data$simulated_css,
#' n = 10)
#' n = n)
simulate_population <- function(x, age = NULL, obesity = NULL, exposure = NULL,
simulated_css = NULL, ...) {

Expand Down
4 changes: 1 addition & 3 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@ reference:
- subtitle: Auxiliary
desc: Auxillary and helper functions
- contents:
- starts_with("fit_")
- fit_hill
- starts_with("get_")
- starts_with("hill_")
- starts_with("obj_")
- subtitle: Datasets
desc: Package datasets
- contents:
Expand Down
2 changes: 1 addition & 1 deletion man/GeoTox.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion man/calc_concentration_response.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions man/calc_independent_action.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions man/calculate_response.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading