aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-04-16 14:56:36 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-04-16 14:56:36 +0200
commit5f5ffc8730b262e64577dc6e4cef836bae862a81 (patch)
tree58490b1ac94f16858a6fcb59af6ecba25e84eef2
parent5b42ee1eb78ae981a2d45ece36def66925b14324 (diff)
Increase test coverage
-rw-r--r--test.log20
-rw-r--r--tests/testthat/FOCUS_2006_D.csf2
-rw-r--r--tests/testthat/test_nlme.R27
3 files changed, 37 insertions, 12 deletions
diff --git a/test.log b/test.log
index 5dae193a..128ea38b 100644
--- a/test.log
+++ b/test.log
@@ -6,30 +6,30 @@ Testing mkin
✔ | 4 | Calculation of FOCUS chi2 error levels [2.2 s]
✔ | 4 | Fitting the SFORB model [1.7 s]
✔ | 5 | Calculation of Akaike weights
-✔ | 10 | Confidence intervals and p-values [9.5 s]
-✔ | 14 | Error model fitting [38.0 s]
+✔ | 10 | Confidence intervals and p-values [9.4 s]
+✔ | 14 | Error model fitting [38.1 s]
✔ | 6 | Test fitting the decline of metabolites from their maximum [0.8 s]
✔ | 1 | Fitting the logistic model [0.9 s]
✔ | 1 | Test dataset class mkinds used in gmkin
✔ | 12 | Special cases of mkinfit calls [2.3 s]
✔ | 9 | mkinmod model generation and printing [0.2 s]
-✔ | 3 | Model predictions with mkinpredict [0.3 s]
+✔ | 3 | Model predictions with mkinpredict [0.4 s]
✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.1 s]
-✔ | 5 | Nonlinear mixed-effects models [11.1 s]
-✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.3 s]
+✔ | 8 | Nonlinear mixed-effects models [11.9 s]
+✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2 s]
✔ | 3 | Summary
-✔ | 14 | Plotting [4.8 s]
+✔ | 14 | Plotting [4.9 s]
✔ | 4 | AIC calculation
✔ | 4 | Residuals extracted from mkinfit models
✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.3 s]
✔ | 1 | Summaries of old mkinfit objects
-✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [6.9 s]
-✔ | 9 | Hypothesis tests [36.8 s]
+✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.1 s]
+✔ | 9 | Hypothesis tests [36.9 s]
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 130.9 s
+Duration: 132.2 s
-OK: 150
+OK: 153
Failed: 0
Warnings: 0
Skipped: 0
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index de5ee0a4..dfccc13f 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-04-09
+Date: 2020-04-16
Optimiser: IRLS
[Data]
diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R
index efbc231a..d272af38 100644
--- a/tests/testthat/test_nlme.R
+++ b/tests/testthat/test_nlme.R
@@ -1,5 +1,7 @@
context("Nonlinear mixed-effects models")
+library(nlme)
+
test_that("nlme_function works correctly", {
sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120)
@@ -47,8 +49,27 @@ test_that("nlme_function works correctly", {
expect_equal(m_nlme_raw$coefficients, m_nlme_mkin$coefficients)
+ m_nlme_mmkin <- nlme(f)
+
+ m_nlme_raw_2 <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink),
+ data = grouped_data,
+ fixed = parent_0 + log_k_parent_sink ~ 1,
+ random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
+ start = mean_degparms(f, random = TRUE))
+
+ expect_equal(m_nlme_raw_2$coefficients, m_nlme_mmkin$coefficients)
+
+ anova_nlme <- anova(m_nlme_mmkin, m_nlme_raw) # mmkin needs to go first as we had
+ # to adapt the method due to
+ # https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17761
+
+ # We get a slightly lower AIC with the improved starting values used within
+ # nlme.mmkin
+ expect_lt(anova_nlme["m_nlme_mmkin", "AIC"],
+ anova_nlme["m_nlme_raw", "AIC"])
+
m_nlme_raw_up_1 <- update(m_nlme_raw, random = log_k_parent_sink ~ 1)
- # The following two calls give an error although they should
+ # The following three calls give an error although they should
# do the same as the call above
# The error occurs in the evaluation of the modelExpression in the
# call to .C(fit_nlme, ...)
@@ -58,16 +79,20 @@ test_that("nlme_function works correctly", {
# fixed = parent_0 + log_k_parent_sink ~ 1,
# random = log_k_parent_sink ~ 1,
# start = mean_dp)
+ # update(m_nlme_mmkin, random = pdDiag(log_k_parent_sink ~ 1),
+ # start = c(parent_0 = 100, log_k_parent_sink = 0.1))
m_nlme_raw_up_2 <- update(m_nlme_raw, random = parent_0 ~ 1)
m_nlme_mkin_up_2 <- update(m_nlme_mkin, random = parent_0 ~ 1)
expect_equal(m_nlme_raw_up_2$coefficients, m_nlme_mkin_up_2$coefficients)
expect_silent(tmp <- update(m_nlme_mkin))
+ expect_silent(tmp <- update(m_nlme_mmkin))
})
test_that("nlme_function works correctly in other cases", {
+ skip_on_cran()
dt50_in <- c(400, 800, 1200, 1600, 2000)
k_in <- log(2) / dt50_in
SFO <- mkinmod(parent = mkinsub("SFO"))

Contact - Imprint