aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2019-02-25 16:24:50 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2019-02-25 16:24:50 +0100
commitaeb6ff55560fa1c704312576be82e3e7ab4ab364 (patch)
tree516e614de008d6ec11f8747b2c32a8a17c3136ab
parent8228a83a4dbd420352823a755926c8778baca460 (diff)
Test printing the summary of an mkinfit object
-rw-r--r--man/summary.mkinfit.Rd4
-rw-r--r--tests/testthat/summary_DFOP_FOCUS_C.txt79
-rw-r--r--tests/testthat/test_plots_summary_twa.R76
3 files changed, 157 insertions, 2 deletions
diff --git a/man/summary.mkinfit.Rd b/man/summary.mkinfit.Rd
index f8c8c9d6..3d71917e 100644
--- a/man/summary.mkinfit.Rd
+++ b/man/summary.mkinfit.Rd
@@ -23,7 +23,7 @@
an object of class \code{summary.mkinfit}.
}
\item{data}{
- logical, indicating whether the data should be included in the summary.
+ logical, indicating whether the data should be included in the summary.
}
\item{distimes}{
logical, indicating whether DT50 and DT90 values should be included.
@@ -64,7 +64,7 @@
Degradation Kinetics from Environmental Fate Studies on Pesticides in EU
Registration} Report of the FOCUS Work Group on Degradation Kinetics,
EC Document Reference Sanco/10058/2005 version 2.0, 434 pp,
- \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics}
+ \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics}
}
\author{
Johannes Ranke
diff --git a/tests/testthat/summary_DFOP_FOCUS_C.txt b/tests/testthat/summary_DFOP_FOCUS_C.txt
new file mode 100644
index 00000000..d8a3e05a
--- /dev/null
+++ b/tests/testthat/summary_DFOP_FOCUS_C.txt
@@ -0,0 +1,79 @@
+mkin version used for fitting: Dummy 0.0 for testing
+R version used for fitting: Dummy R version for testing
+Date of fit: Dummy date for testing
+Date of summary: Dummy date for testing
+
+Equations:
+d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
+ time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time)))
+ * parent
+
+Model predictions using solution type analytical
+
+Fitted with method Port using 127 model solutions performed in 0.401 s
+
+Weighting: none
+
+Starting values for parameters to be optimised:
+ value type
+parent_0 85.10 state
+k1 0.10 deparm
+k2 0.01 deparm
+g 0.50 deparm
+
+Starting values for the transformed parameters actually optimised:
+ value lower upper
+parent_0 85.100000 -Inf Inf
+log_k1 -2.302585 -Inf Inf
+log_k2 -4.605170 -Inf Inf
+g_ilr 0.000000 -Inf Inf
+
+Fixed parameter values:
+None
+
+Optimised, transformed parameters with symmetric confidence intervals:
+ Estimate Std. Error Lower Upper
+parent_0 85.0000 0.89070 82.7100 87.2900
+log_k1 -0.7775 0.04430 -0.8914 -0.6636
+log_k2 -4.0260 0.17030 -4.4640 -3.5880
+g_ilr 1.2490 0.07619 1.0530 1.4450
+
+Parameter correlation:
+ parent_0 log_k1 log_k2 g_ilr
+parent_0 1.00000 0.4338 0.07924 -0.01897
+log_k1 0.43380 1.0000 0.46567 -0.66010
+log_k2 0.07924 0.4657 1.00000 -0.74183
+g_ilr -0.01897 -0.6601 -0.74183 1.00000
+
+Residual standard error: 0.9341 on 5 degrees of freedom
+
+Backtransformed parameters:
+Confidence intervals for internally transformed parameters are asymmetric.
+t-test (unrealistically) based on the assumption of normal distribution
+for estimators of untransformed parameters.
+ Estimate t value Pr(>t) Lower Upper
+parent_0 85.00000 95.440 1.197e-09 82.71000 87.29000
+k1 0.45960 22.570 1.586e-06 0.41010 0.51500
+k2 0.01785 5.873 1.016e-03 0.01152 0.02765
+g 0.85390 63.540 9.135e-09 0.81590 0.88520
+
+Chi2 error levels in percent:
+ err.min n.optim df
+All data 2.661 4 5
+parent 2.661 4 5
+
+Estimated disappearance times:
+ DT50 DT90 DT50_k1 DT50_k2
+parent 1.887 21.25 1.508 38.83
+
+Data:
+ time variable observed predicted residual
+ 0 parent 85.1 85.003 0.09726
+ 1 parent 57.9 58.039 -0.13912
+ 3 parent 29.9 30.054 -0.15351
+ 7 parent 14.6 13.866 0.73388
+ 14 parent 9.7 9.787 -0.08657
+ 28 parent 6.6 7.532 -0.93205
+ 63 parent 4.0 4.033 -0.03269
+ 91 parent 3.9 2.447 1.45348
+ 119 parent 0.6 1.484 -0.88424
diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R
new file mode 100644
index 00000000..83a6a040
--- /dev/null
+++ b/tests/testthat/test_plots_summary_twa.R
@@ -0,0 +1,76 @@
+# Copyright (C) 2016-2019 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/>
+
+models <- c("SFO", "FOMC", "DFOP", "HS")
+fits <- mmkin(models,
+ list(FOCUS_C = FOCUS_2006_C, FOCUS_D = FOCUS_2006_D),
+ quiet = TRUE, cores = if (Sys.getenv("TRAVIS") == "") 15 else 1)
+
+context("Calculation of maximum time weighted average concentrations (TWAs)")
+
+test_that("Time weighted average concentrations are correct", {
+ skip_on_cran()
+
+ outtimes_10 <- seq(0, 10, length.out = 10000)
+
+ for (ds in c("FOCUS_C", "FOCUS_D")) {
+ for (model in 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)
+ }
+ }
+})
+
+context("Summary")
+
+test_that("The summary is reproducible", {
+ skip_on_cran()
+ fit <- fits[["DFOP", "FOCUS_C"]]
+ undebug(summary.mkinfit)
+ test_summary$fit_version <- "Dummy 0.0 for testing"
+ test_summary$fit_Rversion <- "Dummy R version for testing"
+ test_summary$date.fit <- "Dummy date for testing"
+ test_summary$date.summary <- "Dummy date for testing"
+ expect_known_output(print(test_summary), "summary_DFOP_FOCUS_C.txt")
+})
+
+context("Plotting")
+
+test_that("Plotting mmkin objects is reproducible", {
+ skip_on_cran()
+ plot_sep_FOCUS_C_SFO <- function() plot_sep(fits[["SFO", "FOCUS_C"]])
+ mmkin_FOCUS_C <- function() plot(fits[, "FOCUS_C"])
+ mmkin_SFO <- function() plot(fits["SFO",])
+
+ vdiffr::expect_doppelganger("mkinfit plot for FOCUS C with sep = TRUE", plot_sep_FOCUS_C_SFO)
+ vdiffr::expect_doppelganger("mmkin plot for FOCUS C", mmkin_FOCUS_C)
+ vdiffr::expect_doppelganger("mmkin plot for SFO (FOCUS C and D)", mmkin_SFO)
+})
+

Contact - Imprint