From 6372ba681d72dfe2a787c6c98699b6fb53d7ea51 Mon Sep 17 00:00:00 2001 From: Spatiotemporal-Exposures-and-Toxicology Date: Fri, 12 Jan 2024 16:49:01 -0500 Subject: [PATCH 1/3] whitespace lint --- R/obj_hill.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/obj_hill.R b/R/obj_hill.R index ed4df9a..8050974 100644 --- a/R/obj_hill.R +++ b/R/obj_hill.R @@ -5,7 +5,7 @@ #' @param resp response #' #' @return value -obj_hill <- function (par, log10_conc, resp) { +obj_hill <- function(par, log10_conc, resp) { tp <- par[1] # top asymptote log10_ga <- par[2] # log10(AC50) From 797fb9af2ec38c1e975d1a8bb31b3de04c8e5467 Mon Sep 17 00:00:00 2001 From: Spatiotemporal-Exposures-and-Toxicology Date: Sat, 13 Jan 2024 13:00:05 -0500 Subject: [PATCH 2/3] objective fun full testing --- tests/testthat/test-obj_hill.R | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/testthat/test-obj_hill.R diff --git a/tests/testthat/test-obj_hill.R b/tests/testthat/test-obj_hill.R new file mode 100644 index 0000000..7529b68 --- /dev/null +++ b/tests/testthat/test-obj_hill.R @@ -0,0 +1,35 @@ +# Testing the obj-hill functions +test_that("2 and 3 parameter models give accurate likelihood", { + +## hill function for simulation + hill_fun <- function(x, alpha, beta, theta){ + alpha / (1 + 10^(beta * (theta - x))) + } + +## Creating regular parameters + tp <- 1 + log10_ga <- 1 + gw <- 2 + err <- 1 + +## 2-parameter model + + #simulate dose-response + params2 <- c(tp, log10_ga, err) + log10_conc <- seq(0.1,10,length.out = 50) + resp <- hill_fun(log10_conc, tp, log10_ga, gw) + + # 2 parameter hill model expectation + val <- obj_hill(params2, log10_conc, resp) + expect_equal(val, -100.201, tolerance = 0.001) + +## 2-parameter model + + #simulate dose-response + params3 <- c(tp, log10_ga, gw, err) + + # 3 parameter hill model expectation + params3 <- c(tp, log10_ga, gw, err) + val <- obj_hill(params3, log10_conc, resp) + expect_equal(val, -99.23463, tolerance = 0.001) +}) From b0c3f09a7c2fbb1e6de7fc690475055037805042 Mon Sep 17 00:00:00 2001 From: Spatiotemporal-Exposures-and-Toxicology Date: Sat, 13 Jan 2024 13:05:48 -0500 Subject: [PATCH 3/3] added tiny/large edge tests --- tests/testthat/test-obj_hill.R | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-obj_hill.R b/tests/testthat/test-obj_hill.R index 7529b68..4b3776f 100644 --- a/tests/testthat/test-obj_hill.R +++ b/tests/testthat/test-obj_hill.R @@ -23,13 +23,28 @@ test_that("2 and 3 parameter models give accurate likelihood", { val <- obj_hill(params2, log10_conc, resp) expect_equal(val, -100.201, tolerance = 0.001) -## 2-parameter model - - #simulate dose-response - params3 <- c(tp, log10_ga, gw, err) +## 3-parameter model # 3 parameter hill model expectation params3 <- c(tp, log10_ga, gw, err) val <- obj_hill(params3, log10_conc, resp) expect_equal(val, -99.23463, tolerance = 0.001) + + +#### Edge Tests + +# Really tiny parameter values + + #simulate dose-response + params_tiny <- c(1e-10, 1e-10, 1e-10, 1e-10) + + expect_no_warning(obj_hill(params_tiny, log10_conc, resp)) + + + # Really large parameter values + + #simulate dose-response + params_large <- c(1e10, 1e10, 1e10, 1e10) + + expect_no_warning(obj_hill(params_tiny, log10_conc, resp)) })