-
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.
* Updated plot_sensitivity * Added example for plot_sensitivity * Added unit test for GeoTox S3 object
- Loading branch information
1 parent
b211b96
commit 05a941c
Showing
8 changed files
with
324 additions
and
22 deletions.
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
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.
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,112 @@ | ||
test_that("errors", { | ||
|
||
geoTox <- GeoTox() | ||
|
||
expect_error(plot(geoTox), | ||
"No response data found") | ||
|
||
geoTox$resp <- list() | ||
|
||
expect_error(plot(geoTox), | ||
"No region boundary data found") | ||
}) | ||
|
||
test_that("default params", { | ||
|
||
geoTox <- GeoTox() | ||
|
||
expect_equal(geoTox$par, | ||
list(n = 1e3, | ||
IR_params = NULL, | ||
obesity = list(obes_prev = "OBESITY_CrudePrev", | ||
obes_sd = "OBESITY_SD", | ||
obes_label = "FIPS"), | ||
exposure = list(expos_mean = "mean", | ||
expos_sd = "sd", | ||
expos_label = "casn"), | ||
internal_dose = list(time = 1, | ||
BW = 1, | ||
scaling = 1), | ||
resp = list(max_mult = 1.5))) | ||
}) | ||
|
||
test_that("package data subset", { | ||
|
||
set.seed(2357) | ||
n <- 10 # Population size | ||
m <- 5 # Number of regions | ||
idx <- if (m < 100) sample(1:100, m) else 1:100 | ||
|
||
expect_no_error( | ||
geoTox <- GeoTox() |> | ||
# Set region and group boundaries (for plotting) | ||
set_boundaries(region = geo_tox_data$boundaries$county, | ||
group = geo_tox_data$boundaries$state) |> | ||
# 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 | ||
calculate_response() |> | ||
# Perform sensitivity analysis | ||
sensitivity_analysis() | ||
) | ||
|
||
# Print GeoTox object | ||
expect_no_error(capture_output(print(geoTox))) | ||
|
||
# Plot hill fits | ||
expect_no_error(plot(geoTox, type = "hill")) | ||
# Plot exposure data | ||
expect_no_error(plot(geoTox, type = "exposure")) | ||
# Plot response data | ||
# Warning from resp_quantiles() | ||
expect_warning(plot(geoTox), | ||
"Multiple assays found, using first assay") | ||
expect_no_error(plot(geoTox, assays = "TOX21_H2AX_HTRF_CHO_Agonist_ratio")) | ||
# Plot sensitivity data | ||
expect_warning(expect_warning( | ||
plot(geoTox, type = "sensitivity"), | ||
"Multiple assays found, using first assay"), | ||
"Removed \\d+ NA value") | ||
expect_no_error(plot(geoTox, | ||
type = "sensitivity", | ||
assay = "TOX21_H2AX_HTRF_CHO_Agonist_ratio")) | ||
}) | ||
|
||
test_that("print corner cases", { | ||
|
||
geoTox <- GeoTox() | ||
|
||
expect_no_error(capture_output(print(geoTox))) | ||
|
||
geoTox$age <- list() | ||
geoTox$obesity <- c(0) | ||
geoTox$par <- NULL | ||
|
||
expect_no_error(capture_output(print(geoTox))) | ||
|
||
geoTox <- GeoTox() |> | ||
set_hill_params(geo_tox_data$dose_response |> | ||
dplyr::filter(endp == "TOX21_H2AX_HTRF_CHO_Agonist_ratio", | ||
casn == "510-15-6") |> | ||
fit_hill()) | ||
|
||
expect_no_error(capture_output(print(geoTox))) | ||
|
||
geoTox <- geoTox |> | ||
set_hill_params(geo_tox_data$dose_response |> | ||
fit_hill(assay = "endp", chem = "casn")) | ||
|
||
expect_no_error(capture_output(print(geoTox))) | ||
|
||
geoTox$resp <- c(1:5) | ||
|
||
expect_no_error(capture_output(print(geoTox))) | ||
}) |
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,89 @@ | ||
test_that("errors", { | ||
|
||
geoTox <- GeoTox() | ||
|
||
expect_error(plot_sensitivity(geoTox), | ||
"No sensitivity data found") | ||
|
||
geoTox$sensitivity <- list() | ||
|
||
expect_error(plot_sensitivity(geoTox), | ||
"No baseline response data found") | ||
}) | ||
|
||
test_that("no assay", { | ||
|
||
make_data <- function(n = 5, metric = "GCA.Eff") { | ||
list(stats::setNames(data.frame(1:n, runif(n)), | ||
c("sample", metric))) | ||
} | ||
|
||
x <- GeoTox() | ||
n <- 5 | ||
x$resp <- make_data(n) | ||
x$sensitivity <- list(age = make_data(n), | ||
obesity = make_data(n), | ||
css_params = make_data(n), | ||
fit_params = make_data(n), | ||
C_ext = make_data(n)) | ||
|
||
expect_no_error(plot_sensitivity(x)) | ||
}) | ||
|
||
test_that("with assay", { | ||
|
||
make_data <- function(n = 5, metric = "GCA.Eff", assay = c("a1", "a2")) { | ||
list(stats::setNames(data.frame(rep(assay, each = n), | ||
rep(1:n, 2), | ||
runif(2 * n)), | ||
c("assay", "sample", metric))) | ||
} | ||
|
||
x <- GeoTox() | ||
n <- 5 | ||
x$resp <- make_data(n) | ||
x$sensitivity <- list(age = make_data(n), | ||
obesity = make_data(n), | ||
css_params = make_data(n), | ||
fit_params = make_data(n), | ||
C_ext = make_data(n)) | ||
|
||
expect_warning(plot_sensitivity(x), | ||
"Multiple assays found, using first assay") | ||
expect_no_error(plot_sensitivity(x, assay = "a1")) | ||
expect_no_error(plot_sensitivity(x, assay = "a2")) | ||
}) | ||
|
||
test_that("data NAs and missing", { | ||
|
||
make_data <- function(n = 5, metric = "GCA.Eff", p_NA = 0.5) { | ||
df <- stats::setNames(data.frame(1:n, runif(n)), | ||
c("sample", metric)) | ||
df[sample(n, n * p_NA), metric] <- NA | ||
list(df) | ||
} | ||
|
||
x <- GeoTox() | ||
n <- 5 | ||
x$resp <- make_data(n) | ||
x$sensitivity <- list(age = make_data(n), | ||
obesity = make_data(n), | ||
css_params = make_data(n), | ||
fit_params = make_data(n), | ||
C_ext = make_data(n)) | ||
|
||
expect_warning(plot_sensitivity(x), | ||
"Removed \\d+ NA value") | ||
|
||
p_NA <- 1 | ||
x$resp <- make_data(n, p_NA = p_NA) | ||
x$sensitivity <- list(age = make_data(n, p_NA = p_NA), | ||
obesity = make_data(n, p_NA = p_NA), | ||
css_params = make_data(n, p_NA = p_NA), | ||
fit_params = make_data(n, p_NA = p_NA), | ||
C_ext = make_data(n, p_NA = p_NA)) | ||
|
||
expect_error(expect_warning(plot_sensitivity(x), | ||
"Removed \\d+ NA value"), | ||
"No data to plot") | ||
}) |
Oops, something went wrong.