aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2015-05-15 13:55:19 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2015-05-15 13:55:19 +0200
commit6c65cba39dbca98caf3f8e69552b3454ec1721fc (patch)
tree00252649aeccfdd13e723054c22203006cab10c6 /tests
parenta26b44d15c11ebb41083fc2efab0cc91a027b55b (diff)
parent89cd81cf47c9f05831e854d5185b5cc599745db4 (diff)
Merge branch 'master' into compile_odes
Conflicts (resolved manually, deleting code that I had integrated into the RUnit tests for testing the compiled version): .gitignore DESCRIPTION inst/unitTests/runit.mkinerrmin.R inst/unitTests/runit.mkinfit.R tests/testthat/test_mkinpredict_SFO_SFO.R vignettes/FOCUS_L.html
Diffstat (limited to 'tests')
-rw-r--r--tests/doRUnit.R42
-rw-r--r--tests/testthat.R4
-rw-r--r--tests/testthat/test_FOCUS_D_UBA_expertise.R58
-rw-r--r--tests/testthat/test_FOCUS_chi2_error_level.R53
-rw-r--r--tests/testthat/test_mkinpredict_SFO_SFO.R70
-rw-r--r--tests/testthat/test_parent_only.R211
-rw-r--r--tests/testthat/test_schaefer07_complex_case.R68
-rw-r--r--tests/testthat/test_synthetic_data_for_UBA_2014.R67
8 files changed, 531 insertions, 42 deletions
diff --git a/tests/doRUnit.R b/tests/doRUnit.R
deleted file mode 100644
index 9faee940..00000000
--- a/tests/doRUnit.R
+++ /dev/null
@@ -1,42 +0,0 @@
-# Adapted from a version around 2.9 of the rcdk package by Rajarshi Guha
-if(require("RUnit", quietly=TRUE)) {
-
- pkg <- "mkin"
- path <- system.file(package=pkg, "unitTests")
-
- cat("\nRunning unit tests\n")
- print(list(pkg=pkg, getwd=getwd(), pathToUnitTests=path))
-
- library(package=pkg, character.only=TRUE)
-
- ## Define tests
- testSuite <- defineTestSuite(name=paste(pkg, " Unit Tests"),
- dirs=path)
- ## Run
- tests <- runTestSuite(testSuite)
-
- ## Default report name
- pathReport <- file.path(path, "report")
-
- ## Report to stdout and text files
- cat("------------------- UNIT TEST SUMMARY ---------------------\n\n")
- printTextProtocol(tests, showDetails=FALSE)
- printTextProtocol(tests, showDetails=FALSE,
- fileName=paste(pathReport, "Summary.txt", sep=""))
- printTextProtocol(tests, showDetails=TRUE,
- fileName=paste(pathReport, ".txt", sep=""))
-
- ## Report to HTML file
- printHTMLProtocol(tests, fileName=paste(pathReport, ".html", sep=""))
-
- ## Return stop() to cause R CMD check stop in case of
- ## - failures i.e. FALSE to unit tests or
- ## - errors i.e. R errors
- tmp <- getErrors(tests)
- if(tmp$nFail > 0 | tmp$nErr > 0) {
- stop(paste("\n\nunit testing failed (#test failures: ", tmp$nFail,
- ", #R errors: ", tmp$nErr, ")\n\n", sep=""))
- }
-} else {
- warning("cannot run unit tests -- package RUnit is not available")
-}
diff --git a/tests/testthat.R b/tests/testthat.R
new file mode 100644
index 00000000..01c9b7cd
--- /dev/null
+++ b/tests/testthat.R
@@ -0,0 +1,4 @@
+library(testthat)
+library(mkin)
+
+test_check("mkin")
diff --git a/tests/testthat/test_FOCUS_D_UBA_expertise.R b/tests/testthat/test_FOCUS_D_UBA_expertise.R
new file mode 100644
index 00000000..ce1e0a5a
--- /dev/null
+++ b/tests/testthat/test_FOCUS_D_UBA_expertise.R
@@ -0,0 +1,58 @@
+# Copyright (C) 2015 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+context("Results for FOCUS D established in expertise for UBA (Ranke 2014)")
+
+SFO_SFO <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"))
+SFO_SFO.ff <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"),
+ use_of_ff = "max")
+
+fit.default <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE)
+fit.ff <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, quiet = TRUE)
+
+# Results are from p. 40
+
+test_that("Fitted parameters are correct for FOCUS D", {
+ expect_equivalent(round(fit.ff$bparms.optim, c(2, 4, 4, 4)),
+ c(99.60, 0.0987, 0.0053, 0.5145))
+})
+
+test_that("FOCUS chi2 error levels are correct for FOCUS D", {
+ expect_equivalent(round(100 * mkinerrmin(fit.ff)$err.min, 2),
+ c(6.40, 6.46, 4.69))
+})
+
+test_that("DT50/90 are correct for FOCUS D when using formation fractions", {
+ expect_equal(round(as.numeric(endpoints(fit.ff)$distimes["parent", ]), 2),
+ c(7.02, 23.33))
+ expect_equal(round(as.numeric(endpoints(fit.ff)$distimes["m1", ]), 1),
+ c(131.8, 437.7))
+})
+
+test_that("DT50/90 are correct for FOCUS D when not using formation fractions", {
+ expect_equal(round(as.numeric(endpoints(fit.default)$distimes["parent", ]), 2),
+ c(7.02, 23.33))
+ expect_equal(round(as.numeric(endpoints(fit.default)$distimes["m1", ]), 1),
+ c(131.8, 437.7))
+})
+
+# References:
+# Ranke (2014) Prüfung und Validierung von Modellierungssoftware als Alternative
+# zu ModelMaker 4.0, Umweltbundesamt Projektnummer 27452
diff --git a/tests/testthat/test_FOCUS_chi2_error_level.R b/tests/testthat/test_FOCUS_chi2_error_level.R
new file mode 100644
index 00000000..65e1ada7
--- /dev/null
+++ b/tests/testthat/test_FOCUS_chi2_error_level.R
@@ -0,0 +1,53 @@
+# Copyright (C) 2014-15 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+# These tests were migrated from inst/unitTests/runit.mkinerrmin.R
+
+context("Calculation of FOCUS chi2 error levels")
+
+SFO_SFO.ff <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"),
+ use_of_ff = "max")
+
+test_that("Chi2 error levels for FOCUS D are as in mkin 0.9-33", {
+
+ fit <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, quiet = TRUE)
+
+ errmin.FOCUS_2006_D_rounded = data.frame(
+ err.min = c(0.0640, 0.0646, 0.0469),
+ n.optim = c(4, 2, 2),
+ df = c(15, 7, 8),
+ row.names = c("All data", "parent", "m1"))
+
+ expect_equal(round(mkinerrmin(fit), 4),
+ errmin.FOCUS_2006_D_rounded)
+})
+
+test_that("Chi2 error levels for FOCUS E are as in mkin 0.9-33", {
+
+ fit <- mkinfit(SFO_SFO.ff, FOCUS_2006_E, quiet = TRUE)
+
+ errmin.FOCUS_2006_E_rounded = data.frame(
+ err.min = c(0.1544, 0.1659, 0.1095),
+ n.optim = c(4, 2, 2),
+ df = c(13, 7, 6),
+ row.names = c("All data", "parent", "m1"))
+
+ expect_equal(round(mkinerrmin(fit), 4),
+ errmin.FOCUS_2006_E_rounded)
+})
diff --git a/tests/testthat/test_mkinpredict_SFO_SFO.R b/tests/testthat/test_mkinpredict_SFO_SFO.R
new file mode 100644
index 00000000..1238bb28
--- /dev/null
+++ b/tests/testthat/test_mkinpredict_SFO_SFO.R
@@ -0,0 +1,70 @@
+# $Id: jranke $
+
+# Copyright (C) 2012-2015 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+# This was migrated from an RUnit test in inst/unitTests/runit.mkinpredict.R
+
+context("Model predictions with mkinpredict")
+test_that("Variants of model predictions for SFO_SFO model give equivalent results", {
+ # Check model specification and solution types for SFO_SFO
+ # Relative Tolerance is 0.01%
+ # Do not use time 0, as eigenvalue based solution does not give 0 at time 0 for metabolites
+ # and relative tolerance is thus not met
+ tol = 0.01
+ SFO_SFO.1 <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"), use_of_ff = "min")
+ SFO_SFO.2 <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"), use_of_ff = "max")
+
+ ot = seq(0, 100, by = 1)
+ r.1.e <- subset(mkinpredict(SFO_SFO.1,
+ c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "eigen"),
+ time %in% c(1, 10, 50, 100))
+ r.1.d <- subset(mkinpredict(SFO_SFO.1,
+ c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "deSolve"),
+ time %in% c(1, 10, 50, 100))
+
+ r.2.e <- subset(mkinpredict(SFO_SFO.2, c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "eigen"),
+ time %in% c(1, 10, 50, 100))
+ r.2.d <- subset(mkinpredict(SFO_SFO.2, c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "deSolve"),
+ time %in% c(1, 10, 50, 100))
+
+ # Compare eigen and deSolve for minimum use of formation fractions
+ dev.1.e_d.percent = 100 * (r.1.e[-1] - r.1.d[-1])/r.1.e[-1]
+ dev.1.e_d.percent = as.numeric(unlist((dev.1.e_d.percent)))
+ dev.1.e_d.percent = ifelse(is.na(dev.1.e_d.percent), 0, dev.1.e_d.percent)
+ expect_equivalent(dev.1.e_d.percent < tol, rep(TRUE, length(dev.1.e_d.percent)))
+
+ # Compare eigen and deSolve for maximum use of formation fractions
+ dev.2.e_d.percent = 100 * (r.1.e[-1] - r.1.d[-1])/r.1.e[-1]
+ dev.2.e_d.percent = as.numeric(unlist((dev.2.e_d.percent)))
+ dev.2.e_d.percent = ifelse(is.na(dev.2.e_d.percent), 0, dev.2.e_d.percent)
+ expect_equivalent(dev.2.e_d.percent < tol, rep(TRUE, length(dev.2.e_d.percent)))
+
+ # Compare minimum and maximum use of formation fractions
+ dev.1_2.e.percent = 100 * (r.1.e[-1] - r.2.e[-1])/r.1.e[-1]
+ dev.1_2.e.percent = as.numeric(unlist((dev.1_2.e.percent)))
+ dev.1_2.e.percent = ifelse(is.na(dev.1_2.e.percent), 0, dev.1_2.e.percent)
+ expect_equivalent(dev.1_2.e.percent < tol, rep(TRUE, length(dev.1_2.e.percent)))
+
+})
diff --git a/tests/testthat/test_parent_only.R b/tests/testthat/test_parent_only.R
new file mode 100644
index 00000000..5dcf297c
--- /dev/null
+++ b/tests/testthat/test_parent_only.R
@@ -0,0 +1,211 @@
+# Copyright (C) 2015 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+context("Fitting of parent only models")
+
+calc_dev.percent <- function(fitlist, reference, endpoints = TRUE, round_results = NULL) {
+ dev.percent <- list()
+ for (i in 1:length(fitlist)) {
+ fit <- fitlist[[i]]
+ if (endpoints) {
+ results <- c(fit$bparms.optim,
+ endpoints(fit)$distimes$DT50,
+ endpoints(fit)$distimes$DT90)
+ } else {
+ results <- fit$bparms.optim
+ }
+ if (!missing(round_results)) results <- round(results, round_results)
+ dev.percent[[i]] <- abs(100 * ((reference - results)/reference))
+ }
+ return(dev.percent)
+}
+
+SFO <- mkinmod(parent = list(type = "SFO"))
+FOMC <- mkinmod(parent = list(type = "FOMC"))
+DFOP <- mkinmod(parent = list(type = "DFOP"))
+HS <- mkinmod(parent = list(type = "HS"))
+SFORB <- mkinmod(parent = list(type = "SFORB"))
+
+test_that("Fits for FOCUS A deviate less than 0.1% from median of values from FOCUS report", {
+ fit.A.SFO <- list(mkinfit("SFO", FOCUS_2006_A, quiet = TRUE))
+
+ median.A.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "A",
+ c(M0, k, DT50, DT90)), "median"))
+
+ dev.percent.A.SFO <- calc_dev.percent(fit.A.SFO, median.A.SFO)
+ expect_equivalent(dev.percent.A.SFO[[1]] < 0.1, rep(TRUE, 4))
+
+ # Fitting FOCUS A with FOMC is possible, but the correlation between
+ # alpha and beta, when obtained, is 1.0000, and the fit sometimes failed on
+ # Windows, as the Port algorithm did not converge (winbuilder, 2015-05-15)
+ fit.A.FOMC <- try(list(mkinfit("FOMC", FOCUS_2006_A, quiet = TRUE)))
+ if (!inherits(fit.A.FOMC, "try-error")) {
+
+ median.A.FOMC <- as.numeric(lapply(subset(FOCUS_2006_FOMC_ref_A_to_F,
+ dataset == "A",
+ c(M0, alpha, beta, DT50, DT90)), "median"))
+
+ dev.percent.A.FOMC <- calc_dev.percent(fit.A.FOMC, median.A.FOMC)
+ # alpha and are beta ill-determined, do not compare those
+ expect_equivalent(dev.percent.A.FOMC[[1]][c(1, 4, 5)] < 0.1, rep(TRUE, 3))
+ }
+
+ fit.A.DFOP <- list(mkinfit("DFOP", FOCUS_2006_A, quiet = TRUE))
+
+ median.A.DFOP <- as.numeric(lapply(subset(FOCUS_2006_DFOP_ref_A_to_B,
+ dataset == "A",
+ c(M0, k1, k2, f, DT50, DT90)), "median"))
+
+ dev.percent.A.DFOP <- calc_dev.percent(fit.A.DFOP, median.A.DFOP)
+ #expect_equivalent(dev.percent.A.DFOP[[1]] < 0.1, rep(TRUE, 6)) # g/f is ill-determined
+ expect_equivalent(dev.percent.A.DFOP[[1]][c(1, 2, 3, 5, 6)] < 0.1, rep(TRUE, 5))
+
+ fit.A.HS <- list(mkinfit("HS", FOCUS_2006_A, quiet = TRUE))
+
+ median.A.HS <- as.numeric(lapply(subset(FOCUS_2006_HS_ref_A_to_F,
+ dataset == "A",
+ c(M0, k1, k2, tb, DT50, DT90)), "median"))
+
+ dev.percent.A.HS <- calc_dev.percent(fit.A.HS, median.A.HS)
+ expect_equivalent(dev.percent.A.HS[[1]] < 0.1, rep(TRUE, 6))
+})
+
+test_that("Fits for FOCUS B deviate less than 0.1% from median of values from FOCUS report", {
+ fit.B.SFO <- list(mkinfit("SFO", FOCUS_2006_B, quiet = TRUE))
+
+ median.B.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "B",
+ c(M0, k, DT50, DT90)), "median"))
+
+ dev.percent.B.SFO <- calc_dev.percent(fit.B.SFO, median.B.SFO)
+ expect_equivalent(dev.percent.B.SFO[[1]] < 0.1, rep(TRUE, 4))
+
+ fit.B.FOMC <- list(mkinfit("FOMC", FOCUS_2006_B, quiet = TRUE))
+
+ median.B.FOMC <- as.numeric(lapply(subset(FOCUS_2006_FOMC_ref_A_to_F,
+ dataset == "B",
+ c(M0, alpha, beta, DT50, DT90)), "median"))
+
+ dev.percent.B.FOMC <- calc_dev.percent(fit.B.FOMC, median.B.FOMC)
+ expect_equivalent(dev.percent.B.FOMC[[1]] < 0.1, rep(TRUE, 5))
+
+ fit.B.DFOP <- list(mkinfit("DFOP", FOCUS_2006_B, quiet = TRUE))
+
+ median.B.DFOP <- as.numeric(lapply(subset(FOCUS_2006_DFOP_ref_A_to_B,
+ dataset == "B",
+ c(M0, k1, k2, f, DT50, DT90)), "median"))
+
+ dev.percent.B.DFOP <- calc_dev.percent(fit.B.DFOP, median.B.DFOP)
+ #expect_equivalent(dev.percent.B.DFOP[[1]] < 0.1, rep(TRUE, 6)) # g/f is ill-determined
+ expect_equivalent(dev.percent.B.DFOP[[1]][c(1, 2, 3, 5, 6)] < 0.1, rep(TRUE, 5))
+
+ fit.B.HS <- list(mkinfit("HS", FOCUS_2006_B, quiet = TRUE))
+
+ median.B.HS <- as.numeric(lapply(subset(FOCUS_2006_HS_ref_A_to_F,
+ dataset == "B",
+ c(M0, k1, k2, tb, DT50, DT90)),
+ "median", na.rm = TRUE))
+
+ dev.percent.B.HS <- calc_dev.percent(fit.B.HS, median.B.HS)
+ expect_equivalent(dev.percent.B.HS[[1]] < 0.1, rep(TRUE, 6))
+
+ fit.B.SFORB <- list(mkinfit(SFORB, FOCUS_2006_B, quiet=TRUE))
+ dev.percent.B.SFORB <- calc_dev.percent(fit.B.SFORB, median.B.DFOP)
+ expect_equivalent(dev.percent.B.SFORB[[1]][c(1, 5, 6)] < 0.1, rep(TRUE, 3))
+})
+
+test_that("Fits for FOCUS C deviate less than 0.1% from median of values from FOCUS report", {
+ fit.C.SFO <- list(mkinfit("SFO", FOCUS_2006_C, quiet = TRUE))
+
+ median.C.SFO <- as.numeric(lapply(subset(FOCUS_2006_SFO_ref_A_to_F,
+ dataset == "C",
+ c(M0, k, DT50, DT90)), "median"))
+
+ dev.percent.C.SFO <- calc_dev.percent(fit.C.SFO, median.C.SFO)
+ expect_equivalent(dev.percent.C.SFO[[1]] < 0.1, rep(TRUE, 4))
+
+ fit.C.FOMC <- list(mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE))
+
+ median.C.FOMC <- as.numeric(lapply(subset(FOCUS_2006_FOMC_ref_A_to_F,
+ dataset == "C",
+ c(M0, alpha, beta, DT50, DT90)), "median"))
+
+ dev.percent.C.FOMC <- calc_dev.percent(fit.C.FOMC, median.C.FOMC,
+ round_results = 2) # Not enough precision in FOCUS results
+ expect_equivalent(dev.percent.C.FOMC[[1]] < 0.1, rep(TRUE, 5))
+
+ fit.C.HS <- list(mkinfit("HS", FOCUS_2006_C, quiet = TRUE))
+
+ median.C.HS <- as.numeric(lapply(subset(FOCUS_2006_HS_ref_A_to_F,
+ dataset == "C",
+ c(M0, k1, k2, tb, DT50, DT90)), "median"))
+
+ dev.percent.C.HS <- calc_dev.percent(fit.C.HS, median.C.HS, round_results = c(2, 4, 6, 2, 2))
+ # Not enouth precision in k2 available
+ expect_equivalent(dev.percent.C.HS[[1]] < c(0.1, 0.1, 0.3, 0.1, 0.1, 0.1), rep(TRUE, 6))
+})
+
+test_that("SFO fits give approximately (0.001%) equal results with different solution methods", {
+ fit.A.SFO.default <- mkinfit("SFO", FOCUS_2006_A, quiet = TRUE)$bparms.optim
+
+ fits.A.SFO <- list()
+ fits.A.SFO[[1]] <- mkinfit(SFO, FOCUS_2006_A, quiet = TRUE)
+ fits.A.SFO[[2]] <- mkinfit(SFO, FOCUS_2006_A, quiet = TRUE, solution_type = "eigen")
+ fits.A.SFO[[3]] <- mkinfit(SFO, FOCUS_2006_A, quiet = TRUE, solution_type = "deSolve")
+
+ dev.percent <- calc_dev.percent(fits.A.SFO, fit.A.SFO.default, endpoints = FALSE)
+ expect_equivalent(dev.percent[[1]] < 0.001, rep(TRUE, 2))
+ expect_equivalent(dev.percent[[2]] < 0.001, rep(TRUE, 2))
+ expect_equivalent(dev.percent[[3]] < 0.001, rep(TRUE, 2))
+})
+
+test_that("FOMC fits give approximately (0.001%) equal results with different solution methods", {
+ fit.C.FOMC.default <- mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE)$bparms.optim
+
+ fits.C.FOMC <- list()
+ fits.C.FOMC[[1]] <- mkinfit(FOMC, FOCUS_2006_C, quiet = TRUE)
+ fits.C.FOMC[[2]] <- mkinfit(FOMC, FOCUS_2006_C, quiet = TRUE, solution_type = "deSolve")
+
+ dev.percent <- calc_dev.percent(fits.C.FOMC, fit.C.FOMC.default, endpoints = FALSE)
+ expect_equivalent(dev.percent[[1]] < 0.001, rep(TRUE, 3))
+ expect_equivalent(dev.percent[[2]] < 0.001, rep(TRUE, 3))
+})
+
+test_that("DFOP fits give approximately (0.001%) equal results with different solution methods", {
+ fit.C.DFOP.default <- mkinfit("DFOP", FOCUS_2006_C, quiet = TRUE)$bparms.optim
+
+ fits.C.DFOP <- list()
+ fits.C.DFOP[[1]] <- mkinfit(DFOP, FOCUS_2006_C, quiet = TRUE)
+ fits.C.DFOP[[2]] <- mkinfit(DFOP, FOCUS_2006_C, quiet = TRUE, solution_type = "deSolve")
+
+ dev.percent <- calc_dev.percent(fits.C.DFOP, fit.C.DFOP.default, endpoints = FALSE)
+ expect_equivalent(dev.percent[[1]] < 0.001, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[2]] < 0.001, rep(TRUE, 4))
+})
+
+test_that("SFORB fits give approximately (0.002%) equal results with different solution methods", {
+ fit.B.SFORB.default <- mkinfit(SFORB, FOCUS_2006_B, quiet=TRUE)$bparms.optim
+
+ fits.B.SFORB <- list()
+ fits.B.SFORB[[1]] <- mkinfit(SFORB, FOCUS_2006_B, quiet=TRUE, solution_type = "eigen")
+ fits.B.SFORB[[2]] <- mkinfit(SFORB, FOCUS_2006_B, quiet=TRUE, solution_type = "deSolve")
+ dev.percent <- calc_dev.percent(fits.B.SFORB, fit.B.SFORB.default, endpoints = FALSE)
+ expect_equivalent(dev.percent[[1]] < 0.001, rep(TRUE, 4))
+ expect_equivalent(dev.percent[[2]] < 0.002, rep(TRUE, 4))
+})
diff --git a/tests/testthat/test_schaefer07_complex_case.R b/tests/testthat/test_schaefer07_complex_case.R
new file mode 100644
index 00000000..1ef5106e
--- /dev/null
+++ b/tests/testthat/test_schaefer07_complex_case.R
@@ -0,0 +1,68 @@
+# Copyright (C) 2014-2015 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+# This test was migrated from a RUnit test inst/unitTests/runit.mkinfit.R
+
+context("Complex test case from Schaefer et al. (2007) Piacenza paper")
+
+schaefer07_complex_model <- mkinmod(
+ parent = list(type = "SFO", to = c("A1", "B1", "C1"), sink = FALSE),
+ A1 = list(type = "SFO", to = "A2"),
+ B1 = list(type = "SFO"),
+ C1 = list(type = "SFO"),
+ A2 = list(type = "SFO"), use_of_ff = "max")
+
+schaefer07_long <- mkin_wide_to_long(schaefer07_complex_case, time = "time")
+
+fit.default <- mkinfit(schaefer07_complex_model, schaefer07_long, quiet = TRUE)
+
+test_that("Complex test case from Schaefer (2007) can be reproduced (10% tolerance)", {
+
+ s <- summary(fit.default)
+ r <- schaefer07_complex_results
+
+ with(as.list(fit.default$bparms.optim), {
+ r$mkin <<- c(
+ k_parent,
+ s$distimes["parent", "DT50"],
+ s$ff["parent_A1"],
+ k_A1,
+ s$distimes["A1", "DT50"],
+ s$ff["parent_B1"],
+ k_B1,
+ s$distimes["B1", "DT50"],
+ s$ff["parent_C1"],
+ k_C1,
+ s$distimes["C1", "DT50"],
+ s$ff["A1_A2"],
+ k_A2,
+ s$distimes["A2", "DT50"])
+ }
+ )
+ r$means <- (r$KinGUI + r$ModelMaker)/2
+ r$mkin.deviation <- abs(round(100 * ((r$mkin - r$means)/r$means), digits=1))
+ expect_equal(r$mkin.deviation < 10, rep(TRUE, 14))
+})
+
+test_that("We avoid the local minumum with default settings", {
+ # If we use optimisation algorithm 'Marq' we get a local minimum with a
+ # sum of squared residuals of 273.3707
+ # When using 'Marq', we need to give a good starting estimate e.g. for k_A2 in
+ # order to get the optimum with sum of squared residuals 240.5686
+ expect_equal(round(fit.default$ssr, 4), 240.5686)
+})
diff --git a/tests/testthat/test_synthetic_data_for_UBA_2014.R b/tests/testthat/test_synthetic_data_for_UBA_2014.R
new file mode 100644
index 00000000..2bf01075
--- /dev/null
+++ b/tests/testthat/test_synthetic_data_for_UBA_2014.R
@@ -0,0 +1,67 @@
+# Copyright (C) 2015 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+context("Results for synthetic data established in expertise for UBA (Ranke 2014)")
+
+
+m_synth_SFO_lin <- mkinmod(parent = list(type = "SFO", to = "M1"),
+ M1 = list(type = "SFO", to = "M2"),
+ M2 = list(type = "SFO"), use_of_ff = "max")
+
+
+m_synth_DFOP_par <- mkinmod(parent = list(type = "DFOP", to = c("M1", "M2")),
+ M1 = list(type = "SFO"),
+ M2 = list(type = "SFO"), use_of_ff = "max")
+
+fit_SFO_lin_a <- mkinfit(m_synth_SFO_lin,
+ synthetic_data_for_UBA_2014[[1]]$data,
+ quiet = TRUE)
+fit_DFOP_par_c <- mkinfit(m_synth_DFOP_par,
+ synthetic_data_for_UBA_2014[[12]]$data,
+ quiet = TRUE)
+
+# Results for SFO_lin_a from p. 48
+
+test_that("Fitted parameters are correct for SFO_lin_a", {
+ parms <- round(fit_SFO_lin_a$bparms.optim, c(1, 4, 4, 4, 4, 4))
+ expect_equivalent(parms, c(102.1, 0.7393, 0.2992, 0.0202, 0.7687, 0.7229))
+})
+
+test_that("FOCUS chi2 error levels are correct for SFO_lin_a", {
+ errmin <- round(100 * mkinerrmin(fit_SFO_lin_a)$err.min, 2)
+ expect_equivalent(errmin, c(8.45, 8.66, 10.58, 3.59))
+})
+
+# Results for DFOP_par_c from p. 54
+
+test_that("Fitted parameters are correct for DFOP_par_c", {
+ 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,
+ 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))
+})
+
+test_that("FOCUS chi2 error levels are correct for DFOP_par_c", {
+ errmin <- round(100 * mkinerrmin(fit_DFOP_par_c)$err.min, 2)
+ expect_equivalent(errmin, c(4.03, 3.05, 5.07, 3.17))
+})
+
+# References:
+# Ranke (2014) Prüfung und Validierung von Modellierungssoftware als Alternative
+# zu ModelMaker 4.0, Umweltbundesamt Projektnummer 27452

Contact - Imprint