-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated 'calc_concentration_response'
- Loading branch information
1 parent
a54ea3f
commit 4683259
Showing
2 changed files
with
134 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,131 @@ | ||
test_that("mixture calculation for errors from bad inputs", { | ||
# errors from bad input | ||
|
||
# errors from bad order | ||
|
||
test_that("C_invitro with basic hill_params", { | ||
|
||
col_names <- c("sample", "GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10") | ||
|
||
hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1), resp = c(10, 5, 0))) | ||
|
||
C_invitro <- matrix(0) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(col_names %in% names(out[[1]]))) | ||
expect_true(all(unname(out[[1]]) == c(1, NA, NA, NA, NA))) | ||
|
||
C_invitro <- matrix(1) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(col_names %in% names(out[[1]]))) | ||
|
||
C_invitro <- matrix(1:4, ncol = 1) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(col_names %in% names(out[[1]]))) | ||
|
||
C_invitro <- list(matrix(1)) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(col_names %in% names(out[[1]]))) | ||
|
||
C_invitro <- list(matrix(1:4), matrix(5:8)) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_length(out, 2) | ||
expect_true(all(col_names %in% names(out |> do.call(what = rbind)))) | ||
|
||
C_invitro <- matrix(1:4, ncol = 2) | ||
# hill_params needs "chem" column if C_invitro has > 1 row | ||
expect_error(calc_concentration_response(C_invitro, hill_params)) | ||
}) | ||
|
||
|
||
test_that("calc_concentration_response is valid with simulated data", { | ||
|
||
|
||
# Set up a mixture concentration-response | ||
conc <- seq(0,1,by = 0.1) | ||
|
||
|
||
|
||
# | ||
test_that("hill_params 'chem'", { | ||
|
||
col_names <- c("GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10") | ||
|
||
# Single chemical | ||
|
||
hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1), | ||
resp = c(10, 5, 0), | ||
chem = rep("c1", each = 3)), | ||
chem = "chem") | ||
|
||
C_invitro <- matrix(1:4, ncol = 1) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(c(col_names, "sample") %in% names(out[[1]]))) | ||
expect_true(nrow(out[[1]]) == 4) | ||
|
||
# Multiple chemicals | ||
|
||
hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1, -2, -1, 0), | ||
resp = c(10, 5, 0, 0, 1, 2), | ||
chem = rep(c("c1", "c2"), each = 3)), | ||
chem = "chem") | ||
|
||
C_invitro <- matrix(1:4, ncol = 2) | ||
expect_error(calc_concentration_response(C_invitro, hill_params)) | ||
|
||
colnames(C_invitro) <- c("c1", "c2") | ||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(c(col_names, "sample") %in% names(out[[1]]))) | ||
expect_true(nrow(out[[1]]) == 2) | ||
}) | ||
|
||
test_that("calc_concentration_response is valid with ICE data", { | ||
|
||
# Set up a mixture concentration-response from ICE | ||
ice_data <- geo_tox_data$ice | ||
|
||
conc <- seq(0,1,by = 0.1) | ||
|
||
|
||
|
||
# | ||
test_that("hill_params 'assay'", { | ||
|
||
col_names <- c("GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10") | ||
|
||
# Single assay | ||
|
||
hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1), | ||
resp = c(10, 5, 0), | ||
assay = rep("a1", each = 3)), | ||
assay = "assay") | ||
|
||
C_invitro <- matrix(1:4, ncol = 1) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(c(col_names, "assay") %in% names(out[[1]]))) | ||
expect_true(nrow(out[[1]]) == 4) | ||
|
||
# Multiple assays | ||
|
||
hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1, -2, -1, 0), | ||
resp = c(10, 5, 0, 0, 1, 2), | ||
assay = rep(c("a1", "a2"), each = 3)), | ||
assay = "assay") | ||
|
||
C_invitro <- matrix(1:4, ncol = 1) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(c(col_names, "assay") %in% names(out[[1]]))) | ||
expect_true(nrow(out[[1]]) == 8) | ||
}) | ||
|
||
test_that("hill_params 'assay' and 'chem'", { | ||
|
||
col_names <- c("GCA.Eff", "IA.Eff", "GCA.HQ.10", "IA.HQ.10") | ||
|
||
df <- data.frame(logc = rep(c(-1, 0, 1, -2, -1, 0), times = 2), | ||
resp = rep(c(10, 5, 0, 0, 1, 2), times = 2), | ||
chem = rep(rep(c("c1", "c2"), each = 3), times = 2), | ||
assay = rep(rep(c("a1", "a2"), each = 6))) | ||
hill_params <- fit_hill(df, chem = "chem", assay = "assay") | ||
|
||
C_invitro <- matrix(1:4, ncol = 2, dimnames = list(NULL, c("c1", "c2"))) | ||
|
||
expect_no_error(out <- calc_concentration_response(C_invitro, hill_params)) | ||
expect_true(all(c(col_names, "assay", "sample") %in% names(out[[1]]))) | ||
expect_true(nrow(out[[1]]) == 4) | ||
}) | ||
|
||
|
||
test_that("calc_independent_action scales to Emax", { | ||
|
||
|
||
x <- data.frame(AGEGRP = 0:18, TOT_POP = c(sum(1:18), 1:18)) | ||
ages_test <- simulate_age(x, 10)[[1]] | ||
|
||
|
||
# age sample is of size "n" | ||
expect_vector(ages_test,size = 10) | ||
|
||
# age samples are within allowed age range [0,90] t | ||
expect_true(all(ages_test < 90 & ages_test >= 0)) | ||
|
||
|
||
# | ||
test_that("other inputs", { | ||
|
||
hill_params <- fit_hill(data.frame(logc = c(-1, 0, 1), resp = c(10, 5, 0))) | ||
C_invitro <- matrix(1) | ||
|
||
expect_no_error(calc_concentration_response(C_invitro, | ||
hill_params, | ||
max_mult = 1.1)) | ||
expect_no_error(calc_concentration_response(C_invitro, | ||
hill_params, | ||
fixed = TRUE)) | ||
}) |