aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-05-11 13:43:40 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-05-11 13:43:40 +0200
commitb36ae3d710858ee3ff2907eb2d780e0dff48a4f3 (patch)
treeb9e075d38233106465481c25b0a777ef043fb1c7 /tests
parent576fbc9d86f4db3d1be2fbd4e97b3fcd58f43c2b (diff)
Analytical solutions for all SFO variants
Diffstat (limited to 'tests')
-rw-r--r--tests/testthat/DFOP_FOCUS_C_messages.txt2
-rw-r--r--tests/testthat/setup_script.R22
-rw-r--r--tests/testthat/test_analytical.R45
-rw-r--r--tests/testthat/test_from_max_mean.R14
-rw-r--r--tests/testthat/test_mkinfit_errors.R12
5 files changed, 64 insertions, 31 deletions
diff --git a/tests/testthat/DFOP_FOCUS_C_messages.txt b/tests/testthat/DFOP_FOCUS_C_messages.txt
index 7284dd19..6aa73e01 100644
--- a/tests/testthat/DFOP_FOCUS_C_messages.txt
+++ b/tests/testthat/DFOP_FOCUS_C_messages.txt
@@ -81,7 +81,7 @@ Sum of squared residuals at call 55: 4.364078
85.016328 -0.776316 -4.027611 1.248897
Sum of squared residuals at call 56: 4.364078
85.016327 -0.776316 -4.027611 1.248897
-Sum of squared residuals at call 57: 4.364078
+Sum of squared residuals at call 57: 4.364077
85.016327 -0.776316 -4.027611 1.248897
85.016327 -0.776316 -4.027611 1.248897
85.008939 -0.777792 -4.026307 1.247720
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
index 86d5089f..58e328cd 100644
--- a/tests/testthat/setup_script.R
+++ b/tests/testthat/setup_script.R
@@ -39,25 +39,27 @@ fits <- mmkin(models,
quiet = TRUE, cores = n_cores)
# One metabolite
-SFO_SFO <- mkinmod(parent = list(type = "SFO", to = "m1"),
- m1 = list(type = "SFO"),
+SFO_SFO <- mkinmod(parent = mkinsub("SFO", to = "m1"),
+ m1 = mkinsub("SFO"),
use_of_ff = "min", quiet = TRUE)
-SFO_SFO.ff <- mkinmod(parent = list(type = "SFO", to = "m1"),
- m1 = list(type = "SFO"),
+SFO_SFO.ff <- mkinmod(parent = mkinsub("SFO", to = "m1"),
+ m1 = mkinsub("SFO"),
use_of_ff = "max", quiet = TRUE)
SFO_SFO.ff.nosink <- mkinmod(
parent = mkinsub("SFO", "m1", sink = FALSE),
m1 = mkinsub("SFO"), quiet = TRUE, use_of_ff = "max")
+FOMC_SFO <- mkinmod(parent = mkinsub("FOMC", to = "m1"),
+ m1 = mkinsub("SFO"), quiet = TRUE)
-f_sfo_sfo_desolve <- mkinfit(SFO_SFO,
- subset(FOCUS_2006_D, value != 0),
+# Avoid warning when fitting a dataset where zero value is removed
+FOCUS_D <- subset(FOCUS_2006_D, value != 0)
+
+f_sfo_sfo_desolve <- mkinfit(SFO_SFO, FOCUS_D,
solution_type = "deSolve", quiet = TRUE)
-f_sfo_sfo_eigen <- mkinfit(SFO_SFO,
- subset(FOCUS_2006_D, value != 0),
+f_sfo_sfo_eigen <- mkinfit(SFO_SFO, FOCUS_D,
solution_type = "eigen", quiet = TRUE)
-f_sfo_sfo.ff <- mkinfit(SFO_SFO.ff,
- subset(FOCUS_2006_D, value != 0),
+f_sfo_sfo.ff <- mkinfit(SFO_SFO.ff, FOCUS_D,
quiet = TRUE)
SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data
diff --git a/tests/testthat/test_analytical.R b/tests/testthat/test_analytical.R
index 3d30e042..5972a18a 100644
--- a/tests/testthat/test_analytical.R
+++ b/tests/testthat/test_analytical.R
@@ -1,11 +1,46 @@
context("Analytical solutions for coupled models")
-test_that("The analytical solution of SFO-SFO is correct", {
- f_sfo_sfo.ff.analytical <- mkinfit(SFO_SFO.ff,
- subset(FOCUS_2006_D, value != 0),
- quiet = TRUE)
+test_that("The analytical solutions of SFO-SFO are correct", {
+ # No sink, no formation fractions
+ SFO_SFO_nosink <- mkinmod(
+ parent = mkinsub("SFO", to = "m1", sink = FALSE),
+ m1 = mkinsub("SFO"),
+ use_of_ff = "min", quiet = TRUE)
+ f_sfo_sfo_nosink <- mkinfit(SFO_SFO_nosink, FOCUS_D, quiet = TRUE)
+ f_sfo_sfo_nosink_deSolve <- mkinfit(SFO_SFO_nosink, FOCUS_D,
+ solution_type = "deSolve", quiet = TRUE)
+ expect_equal(
+ parms(f_sfo_sfo_nosink),
+ parms(f_sfo_sfo_nosink_deSolve)
+ )
+
+ # No sink, with formation fractions
+ SFO_SFO.ff_nosink <- mkinmod(
+ parent = mkinsub("SFO", to = "m1", sink = FALSE),
+ m1 = mkinsub("SFO"),
+ use_of_ff = "max", quiet = TRUE)
+ f_sfo_sfo_nosink <- mkinfit(SFO_SFO.ff_nosink, FOCUS_D, quiet = TRUE)
+ f_sfo_sfo_nosink_deSolve <- mkinfit(SFO_SFO.ff_nosink, FOCUS_D,
+ solution_type = "deSolve", quiet = TRUE)
+ expect_equal(
+ parms(f_sfo_sfo_nosink),
+ parms(f_sfo_sfo_nosink_deSolve)
+ )
+
+ # Without formation fraction
+ f_sfo_sfo_analytical <- mkinfit(SFO_SFO, FOCUS_D,
+ solution_type = "analytical", quiet = TRUE)
+ expect_equal(
+ parms(f_sfo_sfo_analytical),
+ parms(f_sfo_sfo_desolve)
+ )
+
+ # With formation fraction
+ f_sfo_sfo.ff_desolve <- mkinfit(SFO_SFO.ff, FOCUS_D,
+ solution_type = "deSolve", quiet = TRUE)
expect_equal(
parms(f_sfo_sfo.ff),
- parms(f_sfo_sfo.ff.analytical)
+ parms(f_sfo_sfo.ff_desolve)
)
+
})
diff --git a/tests/testthat/test_from_max_mean.R b/tests/testthat/test_from_max_mean.R
index 002b39e2..5a66c1ef 100644
--- a/tests/testthat/test_from_max_mean.R
+++ b/tests/testthat/test_from_max_mean.R
@@ -6,15 +6,15 @@ test_that("Fitting from maximum mean value works", {
expect_error(mkinfit(SFO_SFO, FOCUS_2006_D, from_max_mean = TRUE),
"only implemented for models with a single observed variable"),
"Observations with value of zero were removed")
-
+
# We can either explicitly create a model for m1, or subset the data
SFO_m1 <- mkinmod(m1 = mkinsub("SFO"))
- f.1 <- expect_warning(mkinfit(SFO_m1, FOCUS_2006_D, from_max_mean = TRUE, quiet = TRUE))
- expect_equivalent(endpoints(f.1)$distimes["m1", ], c(170.8, 567.5),
- scale = 1, tolerance = 0.1)
+ f.1 <- mkinfit(SFO_m1, FOCUS_D, from_max_mean = TRUE, quiet = TRUE)
+ expect_equivalent(endpoints(f.1)$distimes["m1", ], c(170.8, 567.5),
+ scale = 1, tolerance = 0.1)
- f.2 <- expect_warning(mkinfit("SFO", subset(FOCUS_2006_D, name == "m1"),
- from_max_mean = TRUE, quiet = TRUE))
- expect_equivalent(endpoints(f.2)$distimes["m1", ], c(170.8, 567.5),
+ f.2 <- mkinfit("SFO", subset(FOCUS_D, name == "m1"),
+ from_max_mean = TRUE, quiet = TRUE)
+ expect_equivalent(endpoints(f.2)$distimes["m1", ], c(170.8, 567.5),
scale = 1, tolerance = 0.1)
})
diff --git a/tests/testthat/test_mkinfit_errors.R b/tests/testthat/test_mkinfit_errors.R
index c1e9da1d..85ee574e 100644
--- a/tests/testthat/test_mkinfit_errors.R
+++ b/tests/testthat/test_mkinfit_errors.R
@@ -4,28 +4,24 @@ test_that("mkinfit stops to prevent and/or explain user errors", {
expect_error(mkinfit("foo", FOCUS_2006_A))
expect_error(mkinfit(3, FOCUS_2006_A))
- # We remove zero observations from FOCUS_2006_D beforehand in
- # order to avoid another expect_warning in the code
- FOCUS_2006_D <- subset(FOCUS_2006_D, value != 0)
-
# We get a warning if we use transform_fractions = FALSE with formation fractions
# and an error if any pathway to sink is turned off as well
expect_warning(
expect_error(
- mkinfit(SFO_SFO.ff.nosink, FOCUS_2006_D, transform_fractions = FALSE, quiet = TRUE),
+ mkinfit(SFO_SFO.ff.nosink, FOCUS_D, transform_fractions = FALSE, quiet = TRUE),
"turn off pathways to sink"
),
"sum of formation fractions may exceed one")
- expect_error(mkinfit(SFO_SFO.ff, FOCUS_2006_D, transform_fractions = TRUE,
+ expect_error(mkinfit(SFO_SFO.ff, FOCUS_D, transform_fractions = TRUE,
parms.ini = c(f_parent_to_m1 = 0.5), fixed_parms = "f_parent_to_m1", quiet = TRUE),
"not supported")
- expect_error(mkinfit(SFO_SFO.ff, FOCUS_2006_D,
+ expect_error(mkinfit(SFO_SFO.ff, FOCUS_D,
parms.ini = c(f_parent_to_m1 = 1.1), quiet = TRUE),
"sum up to more than 1")
- expect_error(mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "analytical"), "not implemented")
+ expect_error(mkinfit(FOMC_SFO, FOCUS_D, solution_type = "analytical"), "not implemented")
expect_error(mkinfit("FOMC", FOCUS_2006_A, solution_type = "eigen"), "coefficient matrix not present")
})

Contact - Imprint