diff --git a/DESCRIPTION b/DESCRIPTION index dc52c758886791c58d183e4724e729e3221f4a51..4b0894ba2deb99d357853925b4dfe62dc2d8c3a5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: stressaddition Type: Package Title: Modelling Tri-Phasic Concentration-Response Relationships Version: 3.0.2 -Date: 2020-09-04 +Date: 2020-09-09 Authors@R: c(person("Sebastian", "Henz", role = c("aut", "cre"), diff --git a/tests/testthat/test-ecxsys.R b/tests/testthat/test-ecxsys.R index cd880a773b0b06effe6c22afeea4f5cab134db5f..f40f1aa698769a284f5f657648c3f996a8e367fe 100644 --- a/tests/testthat/test-ecxsys.R +++ b/tests/testthat/test-ecxsys.R @@ -17,7 +17,7 @@ # along with this program. If not, see <https://www.gnu.org/licenses/>. -mod <- ecxsys( +model <- ecxsys( concentration = c(0, 0.05, 0.5, 5, 30), hormesis_concentration = 0.5, survival_tox_observed = c(90, 81, 92, 28, 0), @@ -84,95 +84,86 @@ test_that("error when hormesis_index <= 2 or >= (length(concentration))", { test_that("min(concentration) == 0 is shifted the correct amount", { - expect_equal(mod$curves$concentration[1] * 10^5, 0.0001) + expect_equal(model$curves$concentration[1] * 10^5, 0.0001) }) test_that("the discrete results have not changed", { expect_equal( - mod$survival_tox_LL5, - c(90, 89.745092, 82.340325, 26.787104, 4.306868), - tolerance = 1e-4 + round(model$survival_tox_LL5, 3), + c(90, 89.745, 82.340, 26.787, 4.307) ) expect_equal( - mod$survival_tox, - c(100, 99.455327884, 92.000028403, 27.999995346, 0.002452598), - tolerance = 1e-4 + round(model$survival_tox, 3), + c(100, 99.455, 92, 28, 0.002) ) expect_equal( - mod$stress_tox, - c(0, 0.09296422, 0.23401450, 0.61804415, 0.98352101), - tolerance = 1e-4 + round(model$stress_tox, 3), + c(0, 0.093, 0.234, 0.618, 0.984) ) expect_equal( - mod$sys_tox_observed, - c(0.2541156, 0.2324304, 0, 0, 0), - tolerance = 1e-4 + round(model$sys_tox_observed, 3), + c(0.254, 0.232, 0, 0, 0) ) expect_equal( - mod$survival_tox_sys, - c(89.920669034, 81.890300846, 90.863799559, 27.999995346, 0.002452598), - tolerance = 1e-4 + round(model$survival_tox_sys, 3), + c(89.921, 81.890, 90.864, 28, 0.002) ) - expect_equal(mod$stress_env, 0.3556369, tolerance = 1e-4) + expect_equal(round(model$stress_env, 3), 0.356) expect_equal( - mod$survival_tox_env_LL5, - c(29.6666667, 29.6666657, 29.5214959, 5.4076411, 0.7871201), - tolerance = 1e-4 + round(model$survival_tox_env_LL5, 3), + c(29.667, 29.667, 29.521, 5.408, 0.787) ) expect_equal( - mod$stress_tox_env, - c(0.3556369, 0.4486011, 0.5896514, 0.9736810, 1.3391579), - tolerance = 1e-4 + round(model$stress_tox_env, 3), + c(0.356, 0.449, 0.59, 0.974, 1.339) ) expect_equal( - mod$survival_tox_env, - c(76.36558967, 59.90195211, 33, 0.01079038, 0), - tolerance = 1e-4 + round(model$survival_tox_env, 3), + c(76.366, 59.902, 33, 0.011, 0) ) expect_equal( - mod$sys_tox_env_observed, - c(0.2566005, 0.1753250, 0, 0, 0), - tolerance = 1e-4 + round(model$sys_tox_env_observed, 3), + c(0.257, 0.175, 0, 0, 0) ) expect_equal( - mod$survival_tox_env_sys, - c(29.37633973, 25.99861674, 30.16676004, 0.01079038, 0), - tolerance = 1e-4 + round(model$survival_tox_env_sys, 3), + c(29.376, 25.999, 30.167, 0.011, 0) ) }) test_that("the curves have not changed", { - new_curves <- mod$curves[c(1, 714, 810, 905, 1000), ] # random indices + new_curves <- model$curves[c(1, 714, 810, 905, 1000), ] # random indices + new_curves <- round(new_curves, 3) rownames(new_curves) <- NULL reference_curves <- data.frame( - concentration = c(0.00000, 0.03004, 0.30512, 3.02551, 30.00000), - survival_tox_LL5 = c(90.00000, 89.88245, 86.18591, 40.42560, 4.30687), - survival_tox_env_LL5 = c(29.66667, 29.66667, 29.65530, 9.27616, 0.78712), - survival_tox = c(100.00000, 99.70167, 95.45944, 49.54173, 0.00245), - stress_tox = c(0.00013, 0.07631, 0.19093, 0.50236, 0.98352), - sys_tox = c(0.25487, 0.24017, 0.05667, 0.00000, 0.00000), - stress_tox_sys = c(0.25499, 0.31648, 0.24760, 0.50236, 0.98352), - survival_tox_sys = c(89.90735, 82.27932, 90.67515, 49.54173, 0.00245), - stress_env = c(0.35564, 0.35564, 0.35564, 0.35564, 0.35564), - stress_tox_env = c(0.35576, 0.43195, 0.54657, 0.85800, 1.33916), - survival_tox_env = c(76.34546, 63.03379, 41.01651, 1.93183, 0.00000), - sys_tox_env = c(0.25443, 0.20496, 0.04445, 0.00000, 0.00000), - stress_tox_env_sys = c(0.61020, 0.63691, 0.59102, 0.85800, 1.33916), - survival_tox_env_sys = c(29.35449, 24.84147, 32.75385, 1.93182, 0), - concentration_for_plots = c(0.0001, 0.03004, 0.30512, 3.02551, 30) + concentration = c(0, 0.03, 0.305, 3.026, 30), + survival_tox_LL5 = c(90, 89.882, 86.186, 40.426, 4.307), + survival_tox_env_LL5 = c(29.667, 29.667, 29.655, 9.276, 0.787), + survival_tox = c(100, 99.702, 95.459, 49.542, 0.002), + stress_tox = c(0, 0.076, 0.191, 0.502, 0.984), + sys_tox = c(0.255, 0.24, 0.057, 0, 0), + stress_tox_sys = c(0.255, 0.316, 0.248, 0.502, 0.984), + survival_tox_sys = c(89.907, 82.279, 90.675, 49.542, 0.002), + stress_env = c(0.356, 0.356, 0.356, 0.356, 0.356), + stress_tox_env = c(0.356, 0.432, 0.547, 0.858, 1.339), + survival_tox_env = c(76.345, 63.034, 41.017, 1.932, 0), + sys_tox_env = c(0.254, 0.205, 0.044, 0, 0), + stress_tox_env_sys = c(0.61, 0.637, 0.591, 0.858, 1.339), + survival_tox_env_sys = c(29.354, 24.841, 32.754, 1.932, 0), + concentration_for_plots = c(0.000, 0.03, 0.305, 3.026, 30) ) class(new_curves) <- class(reference_curves) - expect_equal(new_curves, reference_curves, tolerance = 1e-3) + expect_equal(new_curves, reference_curves) }) test_that("the returned fn works the same way as internally", { # I don't know why it would fail but it doesn't hurt to test it. - curves <- mod$curves + curves <- model$curves curves$concentration_for_plots <- NULL - expect_identical(curves, predict_ecxsys(mod, curves$concentration)) + expect_identical(curves, predict_ecxsys(model, curves$concentration)) }) @@ -187,7 +178,7 @@ test_that("function arguments are returned unchanged", { p = 3.2, q = 3.2 ) - expect_identical(args_reference, mod$args) + expect_identical(args_reference, model$args) }) @@ -199,15 +190,15 @@ ecxsys( ) test_that("results are independent of concentration shift", { - mod_2 <- ecxsys( + model_2 <- ecxsys( concentration = c(0, 0.05, 0.5, 5, 30) * 2, hormesis_concentration = 0.5 * 2, survival_tox_observed = c(90, 81, 92, 28, 0), survival_tox_env_observed = c(29, 27, 33, 5, 0) ) - expect_equal(mod$survival_tox_sys, mod_2$survival_tox_sys) - expect_equal(mod$survival_tox_env_sys, mod_2$survival_tox_env_sys) - mod_10 <- ecxsys( + expect_equal(model$survival_tox_sys, model_2$survival_tox_sys) + expect_equal(model$survival_tox_env_sys, model_2$survival_tox_env_sys) + model_10 <- ecxsys( concentration = c(0, 0.05, 0.5, 5, 30) * 10, hormesis_concentration = 0.5 * 10, survival_tox_observed = c(90, 81, 92, 28, 0), @@ -215,24 +206,24 @@ test_that("results are independent of concentration shift", { ) # Concentration shifts by factors other than powers of 10 may affect # the result because of the way the zero concentration is "corrected". - expect_equal(mod$curves$survival_tox, - mod_10$curves$survival_tox) - expect_equal(mod$curves$survival_tox_sys, - mod_10$curves$survival_tox_sys) - expect_equal(mod$curves$survival_tox_env_sys, - mod_10$curves$survival_tox_env_sys) + expect_equal(model$curves$survival_tox, + model_10$curves$survival_tox) + expect_equal(model$curves$survival_tox_sys, + model_10$curves$survival_tox_sys) + expect_equal(model$curves$survival_tox_env_sys, + model_10$curves$survival_tox_env_sys) }) test_that("survival_tox_env_observed can be left out", { - mod_without_env <- ecxsys( + model_without_env <- ecxsys( concentration = c(0, 0.05, 0.5, 5, 30), hormesis_concentration = 0.5, survival_tox_observed = c(90, 81, 92, 28, 0) ) - expect_equal(mod$survival_tox_sys, mod_without_env$survival_tox_sys) - expect_equal(mod$curves$survival_tox_sys, - mod_without_env$curves$survival_tox_sys) + expect_equal(model$survival_tox_sys, model_without_env$survival_tox_sys) + expect_equal(model$curves$survival_tox_sys, + model_without_env$curves$survival_tox_sys) }) diff --git a/tests/testthat/test-lc.R b/tests/testthat/test-lc.R index 9bba84d31cad9392035f90c59d06e3e65ec10539..807bc9d226b716ec3d276401d24dce51938b8d21 100644 --- a/tests/testthat/test-lc.R +++ b/tests/testthat/test-lc.R @@ -43,9 +43,9 @@ test_that("all input formats produce identical models", { ) ec10_d <- lc(df_custom, "foo", 10) - expect_equal(ec10_a, ec10_b, tolerance = 1e-5) - expect_equal(ec10_b, ec10_c, tolerance = 1e-5) - expect_equal(ec10_c, ec10_d, tolerance = 1e-5) + expect_equal(ec10_a, ec10_b, tolerance = 1e-3) + expect_equal(ec10_b, ec10_c, tolerance = 1e-3) + expect_equal(ec10_c, ec10_d, tolerance = 1e-3) }) @@ -107,11 +107,11 @@ test_that("reference argument works", { expect_equal( lc(model, "survival_tox_LL5", 50, reference = 100), list(response = 50, concentration = 2.208119), - tolerance = 1e-4 + tolerance = 1e-3 ) expect_equal( lc(model, "survival_tox_LL5", 50, reference = 75), list(response = 37.5, concentration = 3.342715), - tolerance = 1e-4 + tolerance = 1e-3 ) }) diff --git a/tests/testthat/test-multi_tox.R b/tests/testthat/test-multi_tox.R index 0ac725683ba7e1b5af5eaad57fdd948bbac3be11..ae9323eb5850a2429a76d527ca863289810cf68d 100644 --- a/tests/testthat/test-multi_tox.R +++ b/tests/testthat/test-multi_tox.R @@ -41,17 +41,18 @@ test_that("results have not changed", { 5, 0.7 ) + new <- round(new, 3) reference <- data.frame( concentration_a = c(0, 0.01, 0.1, 1, 7, 15), concentration_b = 5, - survival = c(88.574578, 84.361552, 80.633762, 56.730550, 2.882718, 0), - stress_tox_sa = c(0.1886787, 0.2436883, 0.3185115, 0.5111081, 0.8904295, 1.0700716), - stress_tox_ca = c(0.18867873, 0.19199327, 0.21634282, 3.579444e-01, 7.126441e-01, 8.856914e-01), - stress_tox = c(0.18867873, 0.22817978, 0.28786093, 4.651590e-01, 8.370939e-01, 1.014758), - sys = c(0.07845536, 0.07312129, 0.04004696, 4.663355e-05, 0, 0), - stress_total = c(0.26713409, 0.30130107, 0.32790789, 4.652056e-01, 8.370939e-01, 1.014758) + survival = c(88.575, 84.361, 80.632, 56.731, 2.883, 0), + stress_tox_sa = c(0.189, 0.244, 0.319, 0.511, 0.89, 1.07), + stress_tox_ca = c(0.189, 0.192, 0.216, 0.358, 0.713, 0.886), + stress_tox = c(0.189, 0.228, 0.288, 0.465, 0.837, 1.015), + sys = c(0.078, 0.073, 0.04, 0, 0, 0), + stress_total = c(0.267, 0.301, 0.328, 0.465, 0.837, 1.015) ) - expect_equal(new, reference, tolerance = 1e-5) + expect_equal(new, reference) # diverse concentration_b new <- multi_tox( @@ -61,17 +62,18 @@ test_that("results have not changed", { c(0, 0.02, 0.2, 2, 14, 30), 0.7 ) + new <- round(new, 3) reference <- data.frame( concentration_a = c(0, 0.01, 0.1, 1, 7, 15), concentration_b = c(0, 0.02, 0.2, 2, 14, 30), - survival = c(88.2698383, 79.96171270, 78.1574808, 6.579998e+01, 3.861678e-01, 0), - stress_tox_sa = c(0, 0.07567745, 0.1807501, 4.510696e-01, 9.961584e-01, 1.294227), - stress_tox_ca = c(0, 0.05654834, 0.1343429, 3.367461e-01, 7.321990e-01, 9.063311e-01), - stress_tox = c(0, 0.06993872, 0.1668279, 4.167725e-01, 9.169706e-01, 1.177858), - sys = c(0.2698033, 0.26248944, 0.1774490, 1.829786e-04, 0, 0), - stress_total = c(0.2698033, 0.33242815, 0.3442769, 4.169555e-01, 9.169706e-01, 1.177858) + survival = c(88.270, 79.962, 78.157, 65.8, 0.386, 0), + stress_tox_sa = c(0, 0.076, 0.181, 0.451, 0.996, 1.294), + stress_tox_ca = c(0, 0.057, 0.134, 0.337, 0.732, 0.906), + stress_tox = c(0, 0.07, 0.167, 0.417, 0.917, 1.178), + sys = c(0.27, 0.262, 0.177, 0, 0, 0), + stress_total = c(0.27, 0.332, 0.344, 0.417, 0.917, 1.178) ) - expect_equal(new, reference, tolerance = 1e-5) + expect_equal(new, reference) # diverse concentration_b and custom survival_max new <- multi_tox( @@ -82,17 +84,18 @@ test_that("results have not changed", { 0.7, 42 ) + new <- round(new, 3) reference <- data.frame( concentration_a = c(0, 0.01, 0.1, 1, 7, 15), concentration_b = c(0, 0.02, 0.2, 2, 14, 30), - survival = c(37.0733321, 33.58391933, 32.8261419, 2.763599e+01, 1.621905e-01, 0), - stress_tox_sa = c(0, 0.07567745, 0.1807501, 4.510696e-01, 9.961584e-01, 1.294227), - stress_tox_ca = c(0, 0.05654834, 0.1343429, 3.367461e-01, 7.321990e-01, 9.063311e-01), - stress_tox = c(0, 0.06993872, 0.1668279, 4.167725e-01, 9.169706e-01, 1.177858), - sys = c(0.2698033, 0.26248944, 0.1774490, 1.829786e-04, 0, 0), - stress_total = c(0.2698033, 0.33242815, 0.3442769, 4.169555e-01, 9.169706e-01, 1.177858) + survival = c(37.073, 33.584, 32.826, 27.636, 0.162, 0), + stress_tox_sa = c(0, 0.076, 0.181, 0.451, 0.996, 1.294), + stress_tox_ca = c(0, 0.057, 0.134, 0.337, 0.732, 0.906), + stress_tox = c(0, 0.07, 0.167, 0.417, 0.917, 1.178), + sys = c(0.27, 0.262, 0.177, 0, 0, 0), + stress_total = c(0.27, 0.332, 0.344, 0.417, 0.917, 1.178) ) - expect_equal(new, reference, tolerance = 1e-5) + expect_equal(new, reference) })