aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/testthat/FOCUS_2006_D.csf2
-rw-r--r--tests/testthat/setup_script.R16
-rw-r--r--tests/testthat/test_FOCUS_D_UBA_expertise.R10
-rw-r--r--tests/testthat/test_SFORB.R5
-rw-r--r--tests/testthat/test_analytical.R5
-rw-r--r--tests/testthat/test_error_models.R17
-rw-r--r--tests/testthat/test_nafta.R5
-rw-r--r--tests/testthat/test_synthetic_data_for_UBA_2014.R23
8 files changed, 51 insertions, 32 deletions
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index f845cc1d..7c8340cd 100644
--- a/tests/testthat/FOCUS_2006_D.csf
+++ b/tests/testthat/FOCUS_2006_D.csf
@@ -5,7 +5,7 @@ Description:
MeasurementUnits: % AR
TimeUnits: days
Comments: Created using mkin::CAKE_export
-Date: 2020-05-28
+Date: 2020-05-29
Optimiser: IRLS
[Data]
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
index def52697..8d8ba3e9 100644
--- a/tests/testthat/setup_script.R
+++ b/tests/testthat/setup_script.R
@@ -57,18 +57,26 @@ DFOP_SFO <- mkinmod(parent = mkinsub("DFOP", to = "m1"),
# Avoid warning when fitting a dataset where zero value is removed
FOCUS_D <- subset(FOCUS_2006_D, value != 0)
+# We do not want warnings about non-normality of residuals here
+suppressWarnings(
f_sfo_sfo_desolve <- mkinfit(SFO_SFO, FOCUS_D,
solution_type = "deSolve", quiet = TRUE)
+)
+suppressWarnings(
f_sfo_sfo_eigen <- mkinfit(SFO_SFO, FOCUS_D,
solution_type = "eigen", quiet = TRUE)
-
+)
+suppressWarnings(
f_sfo_sfo.ff <- mkinfit(SFO_SFO.ff, FOCUS_D,
quiet = TRUE)
+)
SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data
DFOP_par_c <- synthetic_data_for_UBA_2014[[12]]$data
-f_2_mkin <- mkinfit("DFOP", DFOP_par_c, quiet = TRUE)
+# We also suppress the warning about non-normality of residuals here, the data
+# were generated with a different error model, so no wonder!
+f_2_mkin <- suppressWarnings(mkinfit("DFOP", DFOP_par_c, quiet = TRUE))
f_2_nls <- nls(value ~ SSbiexp(time, A1, lrc1, A2, lrc2), data = subset(DFOP_par_c, name == "parent"))
f_2_anova <- lm(value ~ as.factor(time), data = subset(DFOP_par_c, name == "parent"))
@@ -86,9 +94,9 @@ m_synth_DFOP_par <- mkinmod(parent = mkinsub("DFOP", c("M1", "M2")),
fit_nw_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE)
-# We know direct optimization is OK and direct needs 4 sec versus 5.5 for threestep and 6 for IRLS
+# We know direct optimization is OK and direct is faster than the default d_3
fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TRUE,
error_model_algorithm = "direct")
-# We know threestep is OK, and threestep (and IRLS) need 4.8 se versus 5.6 for direct
+# We know threestep is OK, and threestep (and IRLS) is faster here
fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE,
error_model_algorithm = "threestep")
diff --git a/tests/testthat/test_FOCUS_D_UBA_expertise.R b/tests/testthat/test_FOCUS_D_UBA_expertise.R
index be2806de..101c8e15 100644
--- a/tests/testthat/test_FOCUS_D_UBA_expertise.R
+++ b/tests/testthat/test_FOCUS_D_UBA_expertise.R
@@ -2,11 +2,10 @@ context("Results for FOCUS D established in expertise for UBA (Ranke 2014)")
# Results are from p. 40
-# Avoid warnings due to the zero value in the data for m1 at time zero
-FOCUS_D <- subset(FOCUS_2006_D, value != 0)
-
test_that("Fits without formation fractions are correct for FOCUS D", {
- fit.noff <- mkinfit(SFO_SFO, FOCUS_D, quiet = TRUE)
+ expect_warning(
+ fit.noff <- mkinfit(SFO_SFO, FOCUS_D, quiet = TRUE),
+ "p-value.*Shapiro-Wilk")
expect_equal(round(as.numeric(endpoints(fit.noff)$distimes["parent", ]), 2),
c(7.02, 23.33))
@@ -16,8 +15,7 @@ test_that("Fits without formation fractions are correct for FOCUS D", {
})
test_that("Fits with formation fractions are correct for FOCUS D", {
- skip_on_cran()
- fit.ff <- mkinfit(SFO_SFO.ff, FOCUS_D, quiet = TRUE)
+ fit.ff <- f_sfo_sfo.ff
expect_equivalent(round(fit.ff$bparms.optim, c(2, 4, 4, 4)),
c(99.60, 0.0987, 0.0053, 0.5145))
diff --git a/tests/testthat/test_SFORB.R b/tests/testthat/test_SFORB.R
index 4fb736ec..91c8f2fb 100644
--- a/tests/testthat/test_SFORB.R
+++ b/tests/testthat/test_SFORB.R
@@ -1,5 +1,8 @@
context("Fitting the SFORB model")
+# We do not want the warnings due to non-normality of residuals here
+warn_option <- options(warn=-1)
+
test_that("Fitting the SFORB model is equivalent to fitting DFOP", {
f_sforb <- mkinfit("SFORB", FOCUS_2006_C, quiet = TRUE)
f_dfop <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE)
@@ -32,3 +35,5 @@ test_that("Fitting the SFORB model is equivalent to fitting DFOP", {
expect_equivalent(endpoints(f_sforb_sfo_eigen)$distimes, endpoints(f_dfop_sfo)$distimes,
tolerance = 1e-6)
})
+
+options(warn = warn_option$warn)
diff --git a/tests/testthat/test_analytical.R b/tests/testthat/test_analytical.R
index a34fa2cd..66fb1ace 100644
--- a/tests/testthat/test_analytical.R
+++ b/tests/testthat/test_analytical.R
@@ -1,5 +1,8 @@
context("Analytical solutions for coupled models")
+# We do not want the warnings due to non-normality of residuals here
+warn_option <- options(warn=-1)
+
test_that("The analytical solutions for SFO-SFO are correct", {
# No sink, no formation fractions
SFO_SFO_nosink <- mkinmod(
@@ -58,3 +61,5 @@ test_that("The analytical solution for DFOP-SFO are correct", {
tolerance = 5e-6
)
})
+
+options(warn = warn_option$warn)
diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R
index 2dfb2e37..169001f1 100644
--- a/tests/testthat/test_error_models.R
+++ b/tests/testthat/test_error_models.R
@@ -15,36 +15,37 @@ test_that("Error model 'tc' works", {
test_that("The different error model fitting methods work for parent fits", {
skip_on_cran()
- f_9_OLS <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
- quiet = TRUE)
+ test_9 <- experimental_data_for_UBA_2019[[9]]$data
+
+ f_9_OLS <- mkinfit("SFO", test_9, quiet = TRUE)
expect_equivalent(round(AIC(f_9_OLS), 2), 137.43)
f_9_parms_const <- parms(f_9_OLS)
- f_9_direct <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
+ f_9_direct <- mkinfit("SFO", test_9,
error_model = "tc", error_model_algorithm = "direct", quiet = TRUE)
expect_equivalent(round(AIC(f_9_direct), 2), 134.94)
f_9_parms_tc_direct <- parms(f_9_direct)
- f_9_twostep <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
+ f_9_twostep <- mkinfit("SFO", test_9,
error_model = "tc", error_model_algorithm = "twostep", quiet = TRUE)
expect_equivalent(parms(f_9_twostep), f_9_parms_tc_direct, tolerance = 1e-5)
- f_9_threestep <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
+ f_9_threestep <- mkinfit("SFO", test_9,
error_model = "tc", error_model_algorithm = "threestep", quiet = TRUE)
expect_equivalent(round(AIC(f_9_threestep), 2), 139.43)
expect_equivalent(parms(f_9_threestep)[1:3], f_9_parms_const)
- f_9_fourstep <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
+ f_9_fourstep <- mkinfit("SFO", test_9,
error_model = "tc", error_model_algorithm = "fourstep", quiet = TRUE)
expect_equivalent(round(AIC(f_9_fourstep), 2), 139.43)
expect_equivalent(parms(f_9_fourstep)[1:3], f_9_parms_const)
- f_9_IRLS <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
+ f_9_IRLS <- mkinfit("SFO", test_9,
error_model = "tc", error_model_algorithm = "IRLS", quiet = TRUE)
expect_equivalent(round(AIC(f_9_IRLS), 2), 139.43)
expect_equivalent(parms(f_9_IRLS)[1:3], f_9_parms_const)
- f_9_d_3 <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data,
+ f_9_d_3 <- mkinfit("SFO", test_9,
error_model = "tc", error_model_algorithm = "d_3", quiet = TRUE)
expect_equivalent(round(AIC(f_9_d_3), 2), 134.94)
expect_equivalent(parms(f_9_d_3), f_9_parms_tc_direct)
diff --git a/tests/testthat/test_nafta.R b/tests/testthat/test_nafta.R
index 2cc25f82..595db999 100644
--- a/tests/testthat/test_nafta.R
+++ b/tests/testthat/test_nafta.R
@@ -28,8 +28,11 @@ test_that("Test data from Appendix B are correctly evaluated", {
})
test_that("Test data from Appendix D are correctly evaluated", {
+ # We are not interested in the warnings about non-normal residuals here
+ suppressWarnings(
res <- nafta(NAFTA_SOP_Appendix_D, "MRID 555555",
- cores = 1, quiet = TRUE)
+ cores = 1, quiet = TRUE)
+ )
# From Figure D.1
dtx_sop <- matrix(c(407, 541, 429, 1352, 5192066, 2383), nrow = 3, ncol = 2)
diff --git a/tests/testthat/test_synthetic_data_for_UBA_2014.R b/tests/testthat/test_synthetic_data_for_UBA_2014.R
index 4bff1b5a..989f963a 100644
--- a/tests/testthat/test_synthetic_data_for_UBA_2014.R
+++ b/tests/testthat/test_synthetic_data_for_UBA_2014.R
@@ -7,8 +7,8 @@ test_that("Results are correct for SFO_lin_a", {
M1 = mkinsub("SFO", "M2"),
M2 = mkinsub("SFO"),
use_of_ff = "max", quiet = TRUE)
- fit_SFO_lin_a <- mkinfit(m_synth_SFO_lin,
- synthetic_data_for_UBA_2014[[1]]$data,
+ fit_SFO_lin_a <- mkinfit(m_synth_SFO_lin,
+ synthetic_data_for_UBA_2014[[1]]$data,
quiet = TRUE)
# Results for SFO_lin_a from p. 48
@@ -21,19 +21,18 @@ test_that("Results are correct for SFO_lin_a", {
# Results for DFOP_par_c from p. 54
test_that("Results are correct for DFOP_par_c", {
- skip_on_cran()
- m_synth_DFOP_par <- mkinmod(parent = mkinsub("DFOP", c("M1", "M2")),
- M1 = mkinsub("SFO"),
- M2 = mkinsub("SFO"),
- use_of_ff = "max", quiet = TRUE)
-
+ skip_on_cran()
- fit_DFOP_par_c <- mkinfit(m_synth_DFOP_par,
- synthetic_data_for_UBA_2014[[12]]$data,
- quiet = TRUE)
+ # Supress warning about non-normal residuals, the data were generated
+ # using a different error model, so no wonder
+ suppressWarnings(
+ fit_DFOP_par_c <- mkinfit(m_synth_DFOP_par,
+ synthetic_data_for_UBA_2014[[12]]$data,
+ quiet = TRUE)
+ )
parms <- round(fit_DFOP_par_c$bparms.optim, c(1, 4, 4, 4, 4, 4, 4, 4))
- expect_equal(parms, c(parent_0 = 103.0,
+ expect_equal(parms, c(parent_0 = 103.0,
k_M1 = 0.0389, k_M2 = 0.0095,
f_parent_to_M1 = 0.5565, f_parent_to_M2 = 0.3784,
k1 = 0.3263, k2 = 0.0202, g = 0.7130))

Contact - Imprint