aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2018-09-18 10:14:40 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2018-09-18 10:14:40 +0200
commit39b6d8b8569801c2957b22d0973b5ad0c9405e7d (patch)
tree97d0580eec85d9ab4196338ec742ba407ccfa7f8 /tests
parent9a793d0d39c8239ebcc76390f227596cef9b9be1 (diff)
Support maximum twa for HS, test, docs
Diffstat (limited to 'tests')
-rw-r--r--tests/testthat/test_twa.R42
1 files changed, 24 insertions, 18 deletions
diff --git a/tests/testthat/test_twa.R b/tests/testthat/test_twa.R
index a84b2c4e..758c42c3 100644
--- a/tests/testthat/test_twa.R
+++ b/tests/testthat/test_twa.R
@@ -21,23 +21,29 @@ context("Calculation of maximum time weighted average concentrations (TWAs)")
test_that("Time weighted average concentrations are correct", {
skip_on_cran()
- twa_models <- c("SFO", "FOMC", "DFOP")
- fits <- mmkin(twa_models, list(FOCUS_D = FOCUS_2006_D),
- quiet = TRUE, cores = 1)
-
- outtimes_7 <- seq(0, 7, length.out = 10000)
- for (model in twa_models) {
- fit <- fits[[model, 1]]
- bpar <- summary(fit)$bpar[, "Estimate"]
- pred_7 <- mkinpredict(fit$mkinmod,
- odeparms = bpar[2:length(bpar)],
- odeini = c(parent = bpar[[1]]),
- outtimes = outtimes_7)
- twa_num <- mean(pred_7$parent)
- names(twa_num) <- 7
- twa_ana <- max_twa_parent(fit, 7)
-
- # Test for absolute difference (scale = 1)
- expect_equal(twa_num, twa_ana, tolerance = 0.001, scale = 1)
+ twa_models <- c("SFO", "FOMC", "DFOP", "HS")
+ fits <- mmkin(twa_models,
+ list(FOCUS_C = FOCUS_2006_C, FOCUS_D = FOCUS_2006_D),
+ quiet = TRUE, cores = 8)
+
+ outtimes_10 <- seq(0, 10, length.out = 10000)
+
+ for (ds in c("FOCUS_C", "FOCUS_D")) {
+ for (model in twa_models) {
+ fit <- fits[[model, ds]]
+ bpar <- summary(fit)$bpar[, "Estimate"]
+ pred_10 <- mkinpredict(fit$mkinmod,
+ odeparms = bpar[2:length(bpar)],
+ odeini = c(parent = bpar[[1]]),
+ outtimes = outtimes_10)
+ twa_num <- mean(pred_10$parent)
+ names(twa_num) <- 10
+ twa_ana <- max_twa_parent(fit, 10)
+
+ # Test for absolute difference (scale = 1)
+ # The tolerance can be reduced if the length of outtimes is increased,
+ # but this needs more computing time so we stay with lenght.out = 10k
+ expect_equal(twa_num, twa_ana, tolerance = 0.003, scale = 1)
+ }
}
})

Contact - Imprint