aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2019-10-21 15:31:59 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2019-10-21 15:31:59 +0200
commit41a2a356bd9b61c90c04b47aee147bf837223028 (patch)
tree8bc2649d36faefede800e058a86bd0c322625fbd
parent7624a2b8398b4ad665a3b0b622488e1893a5ee7c (diff)
Improve tests, remove geometric_mean
-rw-r--r--R/geometric_mean.R4
-rw-r--r--_pkgdown.yml1
-rw-r--r--docs/reference/geometric_mean.html194
-rw-r--r--man/geometric_mean.Rd22
-rw-r--r--test.log21
-rw-r--r--tests/figs/deps.txt2
-rw-r--r--tests/figs/plotting/mkinerrplot-for-focus-c-sfo.svg58
-rw-r--r--tests/testthat/setup_script.R75
-rw-r--r--tests/testthat/slow/test_roundtrip_error_parameters.R45
-rw-r--r--tests/testthat/summary_DFOP_FOCUS_D.txt125
-rw-r--r--tests/testthat/test_CAKE_export.R8
-rw-r--r--tests/testthat/test_FOCUS_D_UBA_expertise.R6
-rw-r--r--tests/testthat/test_SFORB.R32
-rw-r--r--tests/testthat/test_confidence.R15
-rw-r--r--tests/testthat/test_error_models.R31
-rw-r--r--tests/testthat/test_plots_summary_twa.R27
16 files changed, 362 insertions, 304 deletions
diff --git a/R/geometric_mean.R b/R/geometric_mean.R
deleted file mode 100644
index 646732cd..00000000
--- a/R/geometric_mean.R
+++ /dev/null
@@ -1,4 +0,0 @@
-geometric_mean <- function(x, na.rm = FALSE)
-{
- exp(mean(log(x), na.rm = na.rm))
-}
diff --git a/_pkgdown.yml b/_pkgdown.yml
index efe8b6a0..d51a7f27 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -53,7 +53,6 @@ reference:
- plot.nafta
- title: Helper functions
contents:
- - geometric_mean
- mkinsub
- max_twa_parent
- mkinpredict
diff --git a/docs/reference/geometric_mean.html b/docs/reference/geometric_mean.html
deleted file mode 100644
index 3f9241b4..00000000
--- a/docs/reference/geometric_mean.html
+++ /dev/null
@@ -1,194 +0,0 @@
-<!-- Generated by pkgdown: do not edit by hand -->
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="utf-8">
-<meta http-equiv="X-UA-Compatible" content="IE=edge">
-<meta name="viewport" content="width=device-width, initial-scale=1.0">
-
-<title>Calculate the geometric mean — geometric_mean • mkin</title>
-
-<!-- jquery -->
-<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
-<!-- Bootstrap -->
-
-<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
-<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
-
-<!-- Font Awesome icons -->
-<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/all.min.css" integrity="sha256-nAmazAk6vS34Xqo0BSrTb+abbtFlgsFK7NKSi6o7Y78=" crossorigin="anonymous" />
-<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.7.1/css/v4-shims.min.css" integrity="sha256-6qHlizsOWFskGlwVOKuns+D1nB6ssZrHQrNj1wGplHc=" crossorigin="anonymous" />
-
-<!-- clipboard.js -->
-<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js" integrity="sha256-FiZwavyI2V6+EXO1U+xzLG3IKldpiTFf3153ea9zikQ=" crossorigin="anonymous"></script>
-
-<!-- headroom.js -->
-<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/headroom.min.js" integrity="sha256-DJFC1kqIhelURkuza0AvYal5RxMtpzLjFhsnVIeuk+U=" crossorigin="anonymous"></script>
-<script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.9.4/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script>
-
-<!-- pkgdown -->
-<link href="../pkgdown.css" rel="stylesheet">
-<script src="../pkgdown.js"></script>
-
-
-
-<meta property="og:title" content="Calculate the geometric mean — geometric_mean" />
-
-<meta property="og:description" content="Function calculating the geometric mean of numeric vectors" />
-<meta name="twitter:card" content="summary" />
-
-
-
-<!-- mathjax -->
-<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script>
-<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script>
-
-<!--[if lt IE 9]>
-<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
-<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
-<![endif]-->
-
-
-
- </head>
-
- <body>
- <div class="container template-reference-topic">
- <header>
- <div class="navbar navbar-default navbar-fixed-top" role="navigation">
- <div class="container">
- <div class="navbar-header">
- <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
- <span class="sr-only">Toggle navigation</span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <span class="navbar-brand">
- <a class="navbar-link" href="../index.html">mkin</a>
- <span class="version label label-default" data-toggle="tooltip" data-placement="bottom" title="Released version">0.9.49.6</span>
- </span>
- </div>
-
- <div id="navbar" class="navbar-collapse collapse">
- <ul class="nav navbar-nav">
- <li>
- <a href="../reference/index.html">Functions and data</a>
-</li>
-<li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
- Articles
-
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu" role="menu">
- <li>
- <a href="../articles/mkin.html">Introduction to mkin</a>
- </li>
- <li>
- <a href="../articles/FOCUS_D.html">Example evaluation of FOCUS Example Dataset D</a>
- </li>
- <li>
- <a href="../articles/FOCUS_L.html">Example evaluation of FOCUS Laboratory Data L1 to L3</a>
- </li>
- <li>
- <a href="../articles/web_only/FOCUS_Z.html">Example evaluation of FOCUS Example Dataset Z</a>
- </li>
- <li>
- <a href="../articles/web_only/compiled_models.html">Performance benefit by using compiled model definitions in mkin</a>
- </li>
- <li>
- <a href="../articles/twa.html">Calculation of time weighted average concentrations with mkin</a>
- </li>
- <li>
- <a href="../articles/web_only/NAFTA_examples.html">Example evaluation of NAFTA SOP Attachment examples</a>
- </li>
- </ul>
-</li>
-<li>
- <a href="../news/index.html">News</a>
-</li>
- </ul>
-
- <ul class="nav navbar-nav navbar-right">
-
- </ul>
-
- </div><!--/.nav-collapse -->
- </div><!--/.container -->
-</div><!--/.navbar -->
-
-
-
- </header>
-
-<div class="row">
- <div class="col-md-9 contents">
- <div class="page-header">
- <h1>Calculate the geometric mean</h1>
-
- <div class="hidden name"><code>geometric_mean.Rd</code></div>
- </div>
-
- <div class="ref-description">
-
- <p>Function calculating the geometric mean of numeric vectors</p>
-
- </div>
-
- <pre class="usage"><span class='fu'>geometric_mean</span>(<span class='no'>x</span>, <span class='kw'>na.rm</span> <span class='kw'>=</span> <span class='fl'>FALSE</span>)</pre>
-
- <h2 class="hasAnchor" id="arguments"><a class="anchor" href="#arguments"></a>Arguments</h2>
- <table class="ref-arguments">
- <colgroup><col class="name" /><col class="desc" /></colgroup>
- <tr>
- <th>x</th>
- <td><p>A numeric vector</p></td>
- </tr>
- <tr>
- <th>na.rm</th>
- <td><p>Should NA values be ignored</p></td>
- </tr>
- </table>
-
- <h2 class="hasAnchor" id="value"><a class="anchor" href="#value"></a>Value</h2>
-
- <p>The geometric mean.</p>
-
-
- <h2 class="hasAnchor" id="examples"><a class="anchor" href="#examples"></a>Examples</h2>
- <pre class="examples"><div class='input'> <span class='fu'>geometric_mean</span>(<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>1</span>,<span class='fl'>3</span>, <span class='fl'>9</span>))</div><div class='output co'>#&gt; [1] 3</div><div class='input'> <span class='fu'>geometric_mean</span>(<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>1</span>,<span class='fl'>3</span>, <span class='fl'>NA</span>))</div><div class='output co'>#&gt; [1] NA</div><div class='input'> <span class='fu'>geometric_mean</span>(<span class='fu'><a href='https://rdrr.io/r/base/c.html'>c</a></span>(<span class='fl'>1</span>,<span class='fl'>3</span>, <span class='fl'>NA</span>), <span class='kw'>na.rm</span> <span class='kw'>=</span> <span class='fl'>TRUE</span>)</div><div class='output co'>#&gt; [1] 1.732051</div></pre>
- </div>
- <div class="col-md-3 hidden-xs hidden-sm" id="sidebar">
- <h2>Contents</h2>
- <ul class="nav nav-pills nav-stacked">
- <li><a href="#arguments">Arguments</a></li>
-
- <li><a href="#value">Value</a></li>
-
- <li><a href="#examples">Examples</a></li>
- </ul>
-
- </div>
-</div>
-
-
- <footer>
- <div class="copyright">
- <p>Developed by Johannes Ranke.</p>
-</div>
-
-<div class="pkgdown">
- <p>Site built with <a href="https://pkgdown.r-lib.org/">pkgdown</a> 1.4.1.</p>
-</div>
-
- </footer>
- </div>
-
-
-
-
- </body>
-</html>
-
-
diff --git a/man/geometric_mean.Rd b/man/geometric_mean.Rd
deleted file mode 100644
index 301d9fec..00000000
--- a/man/geometric_mean.Rd
+++ /dev/null
@@ -1,22 +0,0 @@
-\name{geometric_mean}
-\alias{geometric_mean}
-\title{ Calculate the geometric mean }
-\description{
- Function calculating the geometric mean of numeric vectors
-}
-\usage{
- geometric_mean(x, na.rm = FALSE)
-}
-\arguments{
- \item{x}{ A numeric vector }
- \item{na.rm}{ Should NA values be ignored }
-}
-\value{
- The geometric mean.
-}
-\examples{
- geometric_mean(c(1,3, 9))
- geometric_mean(c(1,3, NA))
- geometric_mean(c(1,3, NA), na.rm = TRUE)
-}
-\keyword{ manip }
diff --git a/test.log b/test.log
index 79ff8ba7..fd292165 100644
--- a/test.log
+++ b/test.log
@@ -1,11 +1,11 @@
Loading mkin
Testing mkin
✔ | OK F W S | Context
-✔ | 1 | Export dataset for reading into CAKE
-✔ | 2 | Confidence intervals and p-values [5.6 s]
-✔ | 11 | Error model fitting [53.4 s]
+✔ | 2 | Export dataset for reading into CAKE
+✔ | 3 | Confidence intervals and p-values
+✔ | 10 | Error model fitting [51.6 s]
✔ | 5 | Calculation of FOCUS chi2 error levels [3.5 s]
-✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.7 s]
+✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.4 s]
✔ | 6 | Test fitting the decline of metabolites from their maximum [0.9 s]
✔ | 1 | Fitting the logistic model [0.9 s]
✔ | 1 | Test dataset class mkinds used in gmkin
@@ -14,17 +14,18 @@ Testing mkin
✔ | 3 | Model predictions with mkinpredict [0.3 s]
✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.0 s]
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2 s]
-✔ | 1 | Summary
-✔ | 4 | Plotting [0.3 s]
-✔ | 2 | AIC calculation
-✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.2 s]
+✔ | 2 | Summary
+✔ | 5 | Plotting [0.3 s]
+✔ | 3 | AIC calculation
+✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.3 s]
+✔ | 4 | Fitting the SFORB model [1.7 s]
✔ | 1 | Summaries of old mkinfit objects
✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.1 s]
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 95.5 s
+Duration: 84.4 s
-OK: 98
+OK: 106
Failed: 0
Warnings: 0
Skipped: 0
diff --git a/tests/figs/deps.txt b/tests/figs/deps.txt
index 059d3572..0f64e23e 100644
--- a/tests/figs/deps.txt
+++ b/tests/figs/deps.txt
@@ -1,3 +1,3 @@
- vdiffr-svg-engine: 1.0
-- vdiffr: 0.3.0
+- vdiffr: 0.3.1
- freetypeharfbuzz: 0.2.5
diff --git a/tests/figs/plotting/mkinerrplot-for-focus-c-sfo.svg b/tests/figs/plotting/mkinerrplot-for-focus-c-sfo.svg
new file mode 100644
index 00000000..186d4aac
--- /dev/null
+++ b/tests/figs/plotting/mkinerrplot-for-focus-c-sfo.svg
@@ -0,0 +1,58 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 720.00 576.00'>
+<defs>
+ <style type='text/css'><![CDATA[
+ line, polyline, polygon, path, rect, circle {
+ fill: none;
+ stroke: #000000;
+ stroke-linecap: round;
+ stroke-linejoin: round;
+ stroke-miterlimit: 10.00;
+ }
+ ]]></style>
+</defs>
+<rect width='100%' height='100%' style='stroke: none; fill: #FFFFFF;'/>
+<line x1='82.40' y1='502.56' x2='597.27' y2='502.56' style='stroke-width: 0.75;' />
+<line x1='82.40' y1='502.56' x2='82.40' y2='509.76' style='stroke-width: 0.75;' />
+<line x1='211.12' y1='502.56' x2='211.12' y2='509.76' style='stroke-width: 0.75;' />
+<line x1='339.83' y1='502.56' x2='339.83' y2='509.76' style='stroke-width: 0.75;' />
+<line x1='468.55' y1='502.56' x2='468.55' y2='509.76' style='stroke-width: 0.75;' />
+<line x1='597.27' y1='502.56' x2='597.27' y2='509.76' style='stroke-width: 0.75;' />
+<text x='79.06' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>0</text>
+<text x='204.45' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>20</text>
+<text x='333.16' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>40</text>
+<text x='461.88' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>60</text>
+<text x='590.60' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>80</text>
+<line x1='59.04' y1='486.13' x2='59.04' y2='112.81' style='stroke-width: 0.75;' />
+<line x1='59.04' y1='486.13' x2='51.84' y2='486.13' style='stroke-width: 0.75;' />
+<line x1='59.04' y1='392.80' x2='51.84' y2='392.80' style='stroke-width: 0.75;' />
+<line x1='59.04' y1='299.47' x2='51.84' y2='299.47' style='stroke-width: 0.75;' />
+<line x1='59.04' y1='206.14' x2='51.84' y2='206.14' style='stroke-width: 0.75;' />
+<line x1='59.04' y1='112.81' x2='51.84' y2='112.81' style='stroke-width: 0.75;' />
+<text transform='translate(41.76,489.47) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>0</text>
+<text transform='translate(41.76,399.48) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>20</text>
+<text transform='translate(41.76,306.15) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>40</text>
+<text transform='translate(41.76,212.82) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>60</text>
+<text transform='translate(41.76,119.49) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='13.34px' lengthAdjust='spacingAndGlyphs'>80</text>
+<polyline points='59.04,502.56 689.76,502.56 689.76,59.04 59.04,59.04 59.04,502.56 ' style='stroke-width: 0.75;' />
+<text x='349.06' y='557.28' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='50.69px' lengthAdjust='spacingAndGlyphs'>Predicted</text>
+<text transform='translate(12.96,326.16) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='90.72px' lengthAdjust='spacingAndGlyphs'>Squared residual</text>
+<defs>
+ <clipPath id='cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA=='>
+ <rect x='59.04' y='59.04' width='630.72' height='443.52' />
+ </clipPath>
+</defs>
+<circle cx='613.31' cy='454.40' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='473.33' cy='448.43' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='294.36' cy='443.17' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='144.71' cy='373.26' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='89.71' cy='143.91' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='82.50' cy='283.82' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='82.40' cy='411.47' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='82.40' cy='415.16' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='82.40' cy='484.45' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<line x1='59.04' y1='384.23' x2='689.76' y2='384.23' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<rect x='597.21' y='81.22' width='61.02' height='28.80' style='stroke-width: 0.75; fill: #FFFFFF;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<circle cx='608.01' cy='95.62' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
+<g clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)'><text x='618.81' y='99.74' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='34.02px' lengthAdjust='spacingAndGlyphs'>parent</text></g>
+</svg>
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
new file mode 100644
index 00000000..c1d46dcb
--- /dev/null
+++ b/tests/testthat/setup_script.R
@@ -0,0 +1,75 @@
+# 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/>
+
+require(mkin)
+require(testthat)
+
+# Per default (on my box where I set NOT_CRAN) use all cores minus one
+if (identical(Sys.getenv("NOT_CRAN"), "true")) {
+ n_cores <- parallel::detectCores() - 1
+} else {
+ n_cores <- 1
+}
+
+# We are only allowed one core on travis, but they also set NOT_CRAN=true
+if (Sys.getenv("TRAVIS") != "") n_cores = 1
+
+# On Windows we would need to make a cluster first
+if (Sys.info()["sysname"] == "Windows") n_cores = 1
+
+# mmkin object of parent fits for tests
+models <- c("SFO", "FOMC", "DFOP", "HS")
+fits <- mmkin(models,
+ list(FOCUS_C = FOCUS_2006_C, FOCUS_D = FOCUS_2006_D),
+ quiet = TRUE, cores = n_cores)
+
+# One metabolite
+SFO_SFO <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"), quiet = TRUE)
+SFO_SFO.ff <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"),
+ use_of_ff = "max", quiet = TRUE)
+
+f_sfo_sfo <- mkinfit(SFO_SFO,
+ subset(FOCUS_2006_D, value != 0),
+ quiet = TRUE)
+
+f_sfo_sfo.ff <- mkinfit(SFO_SFO.ff,
+ subset(FOCUS_2006_D, value != 0),
+ quiet = TRUE)
+
+# Two metabolites
+SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data
+
+DFOP_par_c <- synthetic_data_for_UBA_2014[[12]]$data
+
+m_synth_SFO_lin <- mkinmod(
+ parent = mkinsub("SFO", "M1"),
+ M1 = mkinsub("SFO", "M2"),
+ M2 = mkinsub("SFO"),
+ use_of_ff = "max", quiet = TRUE)
+
+m_synth_DFOP_par <- mkinmod(parent = mkinsub("DFOP", c("M1", "M2")),
+ M1 = mkinsub("SFO"),
+ M2 = mkinsub("SFO"),
+ use_of_ff = "max", quiet = TRUE)
+
+f_SFO_lin_mkin_OLS <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE)
+f_SFO_lin_mkin_ML <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE,
+ error_model = "const", error_model_algorithm = "direct")
+
diff --git a/tests/testthat/slow/test_roundtrip_error_parameters.R b/tests/testthat/slow/test_roundtrip_error_parameters.R
index 97510563..7fa6c4e1 100644
--- a/tests/testthat/slow/test_roundtrip_error_parameters.R
+++ b/tests/testthat/slow/test_roundtrip_error_parameters.R
@@ -1,3 +1,36 @@
+# Copyright (C) 2018,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/>
+
+context("Roundtripping error model parameters")
+
+# Per default (on my box where I set NOT_CRAN) use all cores minus one
+if (identical(Sys.getenv("NOT_CRAN"), "true")) {
+ n_cores <- parallel::detectCores() - 1
+} else {
+ n_cores <- 1
+}
+
+# We are only allowed one core on travis, but they also set NOT_CRAN=true
+if (Sys.getenv("TRAVIS") != "") n_cores = 1
+
+# On Windows we would need to make a cluster first
+if (Sys.info()["sysname"] == "Windows") n_cores = 1
+
test_that("Reweighting method 'tc' produces reasonable variance estimates", {
# Check if we can approximately obtain the parameters and the error model
@@ -19,18 +52,6 @@ test_that("Reweighting method 'tc' produces reasonable variance estimates", {
sdfunc = function(x) sigma_twocomp(x, 0.5, 0.07),
n = 1, reps = 100, digits = 5, LOD = -Inf, seed = 123456)
- # Per default (on my box where I set NOT_CRAN) use all cores minus one
- if (identical(Sys.getenv("NOT_CRAN"), "true")) {
- n_cores <- parallel::detectCores() - 1
- } else {
- n_cores <- 1
- }
-
- # We are only allowed one core on travis, but they also set NOT_CRAN=true
- if (Sys.getenv("TRAVIS") != "") n_cores = 1
-
- # On Windows we would need to make a cluster first
- if (Sys.info()["sysname"] == "Windows") n_cores = 1
# Unweighted fits
f_2_10 <- mmkin("DFOP", d_2_10, error_model = "const", quiet = TRUE,
diff --git a/tests/testthat/summary_DFOP_FOCUS_D.txt b/tests/testthat/summary_DFOP_FOCUS_D.txt
new file mode 100644
index 00000000..8abc15e7
--- /dev/null
+++ b/tests/testthat/summary_DFOP_FOCUS_D.txt
@@ -0,0 +1,125 @@
+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 = - k_parent_sink * parent - k_parent_m1 * parent
+d_m1/dt = + k_parent_m1 * parent - k_m1_sink * m1
+
+Model predictions using solution type deSolve
+
+Fitted using test 0 model solutions performed in test time 0 s
+
+Error model: Constant variance
+
+Error model algorithm: OLS
+
+Starting values for parameters to be optimised:
+ value type
+parent_0 100.7500 state
+k_parent_sink 0.1000 deparm
+k_parent_m1 0.1001 deparm
+k_m1_sink 0.1002 deparm
+
+Starting values for the transformed parameters actually optimised:
+ value lower upper
+parent_0 100.750000 -Inf Inf
+log_k_parent_sink -2.302585 -Inf Inf
+log_k_parent_m1 -2.301586 -Inf Inf
+log_k_m1_sink -2.300587 -Inf Inf
+
+Fixed parameter values:
+ value type
+m1_0 0 state
+
+Optimised, transformed parameters with symmetric confidence intervals:
+ Estimate Std. Error Lower Upper
+parent_0 99.600 1.57000 96.400 102.800
+log_k_parent_sink -3.038 0.07626 -3.193 -2.883
+log_k_parent_m1 -2.980 0.04033 -3.062 -2.898
+log_k_m1_sink -5.248 0.13320 -5.518 -4.977
+sigma 3.126 0.35850 2.396 3.855
+
+Parameter correlation:
+ parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink
+parent_0 1e+00 6e-01 -6e-02 -2e-01
+log_k_parent_sink 6e-01 1e+00 -9e-02 -6e-01
+log_k_parent_m1 -6e-02 -9e-02 1e+00 5e-01
+log_k_m1_sink -2e-01 -6e-01 5e-01 1e+00
+sigma 1e-09 -9e-10 2e-08 -1e-10
+ sigma
+parent_0 1e-09
+log_k_parent_sink -9e-10
+log_k_parent_m1 2e-08
+log_k_m1_sink -1e-10
+sigma 1e+00
+
+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 99.600000 63.430 2.298e-36 96.400000 1.028e+02
+k_parent_sink 0.047920 13.110 6.126e-15 0.041030 5.596e-02
+k_parent_m1 0.050780 24.800 3.269e-23 0.046780 5.512e-02
+k_m1_sink 0.005261 7.510 6.165e-09 0.004012 6.898e-03
+sigma 3.126000 8.718 2.235e-10 2.396000 3.855e+00
+
+FOCUS Chi2 error levels in percent:
+ err.min n.optim df
+All data 6.398 4 15
+parent 6.827 3 6
+m1 4.490 1 9
+
+Resulting formation fractions:
+ ff
+parent_sink 0.4855
+parent_m1 0.5145
+m1_sink 1.0000
+
+Estimated disappearance times:
+ DT50 DT90
+parent 7.023 23.33
+m1 131.761 437.70
+
+Data:
+ time variable observed predicted residual
+ 0 parent 99.46 99.59848 -1.385e-01
+ 0 parent 102.04 99.59848 2.442e+00
+ 1 parent 93.50 90.23787 3.262e+00
+ 1 parent 92.50 90.23787 2.262e+00
+ 3 parent 63.23 74.07320 -1.084e+01
+ 3 parent 68.99 74.07320 -5.083e+00
+ 7 parent 52.32 49.91207 2.408e+00
+ 7 parent 55.13 49.91207 5.218e+00
+ 14 parent 27.27 25.01257 2.257e+00
+ 14 parent 26.64 25.01257 1.627e+00
+ 21 parent 11.50 12.53462 -1.035e+00
+ 21 parent 11.64 12.53462 -8.946e-01
+ 35 parent 2.85 3.14787 -2.979e-01
+ 35 parent 2.91 3.14787 -2.379e-01
+ 50 parent 0.69 0.71624 -2.624e-02
+ 50 parent 0.63 0.71624 -8.624e-02
+ 75 parent 0.05 0.06074 -1.074e-02
+ 75 parent 0.06 0.06074 -7.382e-04
+ 1 m1 4.84 4.80296 3.704e-02
+ 1 m1 5.64 4.80296 8.370e-01
+ 3 m1 12.91 13.02400 -1.140e-01
+ 3 m1 12.96 13.02400 -6.400e-02
+ 7 m1 22.97 25.04476 -2.075e+00
+ 7 m1 24.47 25.04476 -5.748e-01
+ 14 m1 41.69 36.69002 5.000e+00
+ 14 m1 33.21 36.69002 -3.480e+00
+ 21 m1 44.37 41.65310 2.717e+00
+ 21 m1 46.44 41.65310 4.787e+00
+ 35 m1 41.22 43.31312 -2.093e+00
+ 35 m1 37.95 43.31312 -5.363e+00
+ 50 m1 41.19 41.21831 -2.831e-02
+ 50 m1 40.01 41.21831 -1.208e+00
+ 75 m1 40.09 36.44703 3.643e+00
+ 75 m1 33.85 36.44703 -2.597e+00
+ 100 m1 31.04 31.98163 -9.416e-01
+ 100 m1 33.13 31.98163 1.148e+00
+ 120 m1 25.15 28.78984 -3.640e+00
+ 120 m1 33.31 28.78984 4.520e+00
diff --git a/tests/testthat/test_CAKE_export.R b/tests/testthat/test_CAKE_export.R
index 23b424fc..a95a27ee 100644
--- a/tests/testthat/test_CAKE_export.R
+++ b/tests/testthat/test_CAKE_export.R
@@ -19,8 +19,9 @@
context("Export dataset for reading into CAKE")
test_that("Exporting is reproducible", {
- CAKE_export(list("FOCUS C" = FOCUS_2006_C,
- "FOCUS D" = FOCUS_2006_D),
+ CAKE_export(
+ ds = list("FOCUS C" = FOCUS_2006_C,
+ "FOCUS D" = FOCUS_2006_D),
map = c(parent = "Parent", m1 = "M1"),
links = c(parent = "m1"),
filename = "FOCUS_2006_D.csf", overwrite = TRUE,
@@ -28,4 +29,7 @@ test_that("Exporting is reproducible", {
csf <- readLines(con = "FOCUS_2006_D.csf")
csf[8] <- "Date: Dummy date 0000-00-00"
expect_known_value(csf, file = "FOCUS_2006_D.rds")
+ expect_error(CAKE_export(ds = list("FOCUS C" = FOCUS_2006_C),
+ filename = "FOCUS_2006_D.csf", overwrite = FALSE),
+ "already exists")
})
diff --git a/tests/testthat/test_FOCUS_D_UBA_expertise.R b/tests/testthat/test_FOCUS_D_UBA_expertise.R
index a282f5e7..614305b1 100644
--- a/tests/testthat/test_FOCUS_D_UBA_expertise.R
+++ b/tests/testthat/test_FOCUS_D_UBA_expertise.R
@@ -19,12 +19,6 @@
context("Results for FOCUS D established in expertise for UBA (Ranke 2014)")
# Results are from p. 40
-SFO_SFO <- mkinmod(parent = list(type = "SFO", to = "m1"),
- m1 = list(type = "SFO"), quiet = TRUE)
-SFO_SFO.ff <- mkinmod(parent = list(type = "SFO", to = "m1"),
- m1 = list(type = "SFO"),
- use_of_ff = "max", quiet = TRUE)
-
test_that("Fits without formation fractions are correct for FOCUS D", {
fit.default <- expect_warning(mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE), "value of zero")
diff --git a/tests/testthat/test_SFORB.R b/tests/testthat/test_SFORB.R
new file mode 100644
index 00000000..49b3beed
--- /dev/null
+++ b/tests/testthat/test_SFORB.R
@@ -0,0 +1,32 @@
+# Copyright (C) 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/>
+
+context("Fitting the SFORB model")
+
+logistic <- mkinmod(parent = mkinsub("logistic"))
+
+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)
+ expect_equivalent(endpoints(f_sforb)$distimes, endpoints(f_dfop)$distimes,
+ tolerance = 1e-6)
+ s_sforb <- capture_output(print(summary(f_sforb)))
+ expect_match(s_sforb, "Estimated Eigenvalues of SFORB model\\(s\\):")
+ expect_match(s_sforb, "parent_b1 parent_b2")
+ expect_match(s_sforb, "0.45956 *0.01785")
+})
diff --git a/tests/testthat/test_confidence.R b/tests/testthat/test_confidence.R
index e5cc1954..0423302b 100644
--- a/tests/testthat/test_confidence.R
+++ b/tests/testthat/test_confidence.R
@@ -18,20 +18,8 @@
context("Confidence intervals and p-values")
-m_synth_SFO_lin <- mkinmod(
- parent = mkinsub("SFO", "M1"),
- M1 = mkinsub("SFO", "M2"),
- M2 = mkinsub("SFO"),
- use_of_ff = "max", quiet = TRUE)
-
-SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data
-
test_that("Confidence intervals are stable", {
- f_1_mkin_OLS <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE)
- f_1_mkin_ML <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE,
- error_model = "const", error_model_algorithm = "direct")
-
- bpar_1 <- summary(f_1_mkin_ML)$bpar[, c("Estimate", "Lower", "Upper")]
+ bpar_1 <- summary(f_SFO_lin_mkin_ML)$bpar[, c("Estimate", "Lower", "Upper")]
# The reference used here is mkin 0.9.48.1
bpar_1_mkin_0.9 <- read.table(text =
"parent_0 102.0000 98.6000 106.0000
@@ -47,5 +35,6 @@ col.names = c("parameter", "estimate", "lower", "upper"))
# Relative difference of lower bound of the confidence interval is < 0.02
expect_equivalent(bpar_1[1:6, "Lower"], bpar_1_mkin_0.9$lower,
scale = bpar_1_mkin_0.9$lower, tolerance = 0.02)
+ expect_equivalent(f_SFO_lin_mkin_OLS$bpar, f_SFO_lin_mkin_ML$bpar)
})
diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R
index f4015e00..ba40bae6 100644
--- a/tests/testthat/test_error_models.R
+++ b/tests/testthat/test_error_models.R
@@ -18,37 +18,6 @@
context("Error model fitting")
-m_synth_SFO_lin <- mkinmod(parent = mkinsub("SFO", "M1"),
- M1 = mkinsub("SFO", "M2"),
- M2 = mkinsub("SFO"),
- use_of_ff = "max", quiet = TRUE)
-
-m_synth_DFOP_par <- mkinmod(parent = mkinsub("DFOP", c("M1", "M2")),
- M1 = mkinsub("SFO"),
- M2 = mkinsub("SFO"),
- use_of_ff = "max", quiet = TRUE)
-
-SFO_lin_a <- synthetic_data_for_UBA_2014[[1]]$data
-
-DFOP_par_c <- synthetic_data_for_UBA_2014[[12]]$data
-
-test_that("Error model 'const' works", {
- skip_on_cran()
- fit_const_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "const", quiet = TRUE)
- bpar_1 <- fit_const_1$bparms.optim
- # The reference used here is mkin 0.9.48.1
- bpar_1_mkin_0.9 <- read.table(text =
-"parent_0 102.0000
-k_parent 0.7390
-k_M1 0.2990
-k_M2 0.0202
-f_parent_to_M1 0.7690
-f_M1_to_M2 0.7230",
-col.names = c("parameter", "estimate"))
-
- expect_equivalent(signif(bpar_1, 3), bpar_1_mkin_0.9$estimate)
-})
-
test_that("Error model 'obs' works", {
skip_on_cran()
fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TRUE)
diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R
index 43036f1a..1dcf49ac 100644
--- a/tests/testthat/test_plots_summary_twa.R
+++ b/tests/testthat/test_plots_summary_twa.R
@@ -16,11 +16,6 @@
# 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 = 1)
-
context("Calculation of maximum time weighted average concentrations (TWAs)")
test_that("Time weighted average concentrations are correct", {
@@ -49,7 +44,7 @@ test_that("Time weighted average concentrations are correct", {
context("Summary")
-test_that("The summary is reproducible", {
+test_that("Summaries are reproducible", {
fit <- fits[["DFOP", "FOCUS_C"]]
test_summary <- summary(fit)
test_summary$fit_version <- "Dummy 0.0 for testing"
@@ -63,6 +58,19 @@ test_that("The summary is reproducible", {
# and between Travis and my own Linux system
test_summary$Corr <- signif(test_summary$Corr, 1)
expect_known_output(print(test_summary), "summary_DFOP_FOCUS_C.txt")
+
+ test_summary_2 <- summary(f_sfo_sfo,)
+ test_summary_2$fit_version <- "Dummy 0.0 for testing"
+ test_summary_2$fit_Rversion <- "Dummy R version for testing"
+ test_summary_2$date.fit <- "Dummy date for testing"
+ test_summary_2$date.summary <- "Dummy date for testing"
+ test_summary_2$calls <- "test 0"
+ test_summary_2$time <- c(elapsed = "test time 0")
+ # The correlation matrix is quite platform dependent
+ # It differs between i386 and amd64 on Windows
+ # and between Travis and my own Linux system
+ test_summary_2$Corr <- signif(test_summary_2$Corr, 1)
+ expect_known_output(print(test_summary_2), "summary_DFOP_FOCUS_D.txt")
})
context("Plotting")
@@ -71,11 +79,13 @@ test_that("Plotting mmkin objects is reproducible", {
skip_on_cran()
plot_sep_FOCUS_C_SFO <- function() plot_sep(fits[["SFO", "FOCUS_C"]])
mkinparplot_FOCUS_C_SFO <- function() mkinparplot(fits[["SFO", "FOCUS_C"]])
+ mkinerrplot_FOCUS_C_SFO <- function() mkinerrplot(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("mkinparplot for FOCUS C SFO", mkinparplot_FOCUS_C_SFO)
+ vdiffr::expect_doppelganger("mkinerrplot for FOCUS C SFO", mkinerrplot_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)
})
@@ -84,7 +94,8 @@ context("AIC calculation")
test_that("The AIC is reproducible", {
expect_equivalent(AIC(fits[["SFO", "FOCUS_C"]]), 59.3, scale = 1, tolerance = 0.1)
- expect_equivalent(AIC(fits[, "FOCUS_C"]),
- data.frame(df = c(3, 4, 5, 5), AIC = c(59.3, 44.7, 29.0, 39.2)),
+ expect_equivalent(AIC(fits[, "FOCUS_C"]),
+ data.frame(df = c(3, 4, 5, 5), AIC = c(59.3, 44.7, 29.0, 39.2)),
scale = 1, tolerance = 0.1)
+ expect_error(AIC(fits["SFO", ]), "column object")
})

Contact - Imprint