From 3c5b2596daef4ed0ee5c38a7141fdf48dbe7c070 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 26 Oct 2022 09:07:04 +0200 Subject: Reduced sfo model for multistart.saem.mkin tests --- log/test.log | 26 ++--- .../_snaps/multistart/llhist-for-sfo-fit.svg | 48 ++++------ .../_snaps/multistart/parhist-for-sfo-fit.svg | 106 +++++++++++++++++++++ tests/testthat/setup_script.R | 1 + tests/testthat/test_multistart.R | 8 +- tests/testthat/test_saemix_parent.R | 3 +- 6 files changed, 147 insertions(+), 45 deletions(-) create mode 100644 tests/testthat/_snaps/multistart/parhist-for-sfo-fit.svg diff --git a/log/test.log b/log/test.log index c5bc0e44..d9dcffb9 100644 --- a/log/test.log +++ b/log/test.log @@ -1,11 +1,11 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.2s] +✔ | 5 | Analytical solutions for coupled models [3.3s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE ✔ | 12 | Confidence intervals and p-values [1.0s] -✔ | 1 12 | Dimethenamid data from 2018 [32.0s] +✔ | 1 12 | Dimethenamid data from 2018 [32.1s] ──────────────────────────────────────────────────────────────────────────────── Skip (test_dmta.R:98:3): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system @@ -16,7 +16,7 @@ Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.8s] ✔ | 4 | Test fitting the decline of metabolites from their maximum [0.3s] ✔ | 1 | Fitting the logistic model [0.2s] -✔ | 7 | Batch fitting and diagnosing hierarchical kinetic models [14.1s] +✔ | 7 | Batch fitting and diagnosing hierarchical kinetic models [14.2s] ✔ | 1 12 | Nonlinear mixed-effects models [0.3s] ──────────────────────────────────────────────────────────────────────────────── Skip (test_mixed.R:74:3): saemix results are reproducible for biphasic fits @@ -27,31 +27,31 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] ✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 4 | Multistart method for saem.mmkin models [33.5s] +✔ | 5 | Multistart method for saem.mmkin models [34.8s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.3s] ✔ | 9 | Nonlinear mixed-effects models with nlme [8.5s] -✔ | 16 | Plotting [9.9s] +✔ | 16 | Plotting [10.0s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 35 | saemix parent models [71.4s] +✔ | 1 35 | saemix parent models [65.3s] ──────────────────────────────────────────────────────────────────────────────── -Skip (test_saemix_parent.R:143:3): We can also use mkin solution methods for saem +Skip (test_saemix_parent.R:142:3): We can also use mkin solution methods for saem Reason: This still takes almost 2.5 minutes although we do not solve ODEs ──────────────────────────────────────────────────────────────────────────────── ✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.5s] ✔ | 11 | Processing of residue series -✔ | 7 | Fitting the SFORB model [3.8s] +✔ | 7 | Fitting the SFORB model [3.7s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.3s] -✔ | 9 | Hypothesis tests [8.2s] -✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.1s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] +✔ | 9 | Hypothesis tests [8.1s] +✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 203.0 s +Duration: 198.3 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) • Fitting with saemix takes around 10 minutes when using deSolve (1) • This still takes almost 2.5 minutes although we do not solve ODEs (1) -[ FAIL 0 | WARN 0 | SKIP 3 | PASS 257 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 258 ] diff --git a/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg index 21fa8af8..4342df9b 100644 --- a/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg @@ -19,32 +19,26 @@ Frequency of log likelihoods - - - - - - - + --644.0 --644.5 --645.0 --645.5 --646.0 --646.5 --647.0 + + + + +-649.836 +-649.834 +-649.832 +-649.830 +-649.828 - - - + + 0 -1 -2 -3 -4 +1 +2 +3 @@ -52,13 +46,11 @@ - - - - - - - + + + + + original fit diff --git a/tests/testthat/_snaps/multistart/parhist-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/parhist-for-sfo-fit.svg new file mode 100644 index 00000000..f3373901 --- /dev/null +++ b/tests/testthat/_snaps/multistart/parhist-for-sfo-fit.svg @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +parent_0 +k_parent +a.1 +b.1 +SD.k_parent + + + + + +0.5 +1.0 +1.5 +2.0 +Normalised parameters + + + + + + + + + + + + + + + +Starting parameters +Original run +Multistart runs + + diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index 4de2674f..777c998a 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -183,6 +183,7 @@ nlme_biphasic <- suppressWarnings(nlme(mmkin_biphasic)) # saemix sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix") +sfo_saem_1_reduced <- update(sfo_saem_1, no_random_effect = "parent_0") dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", no_random_effect = "parent_0") diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 60fdefdc..e5b44e78 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -1,10 +1,14 @@ context("Multistart method for saem.mmkin models") test_that("multistart works for saem.mmkin models", { - saem_sfo_s_multi <- multistart(sfo_saem_1, n = 8, cores = n_cores) + set.seed(123456) + saem_sfo_s_multi <- multistart(sfo_saem_1_reduced, n = 8, cores = n_cores, + no_random_effect = "parent_0") - llhist_sfo <- function() llhist(saem_sfo_s_multi, xlim = c(-644, -647)) + llhist_sfo <- function() llhist(saem_sfo_s_multi) + parhist_sfo <- function() parhist(saem_sfo_s_multi, ylim = c(0.5, 2)) vdiffr::expect_doppelganger("llhist for sfo fit", llhist_sfo) + vdiffr::expect_doppelganger("parhist for sfo fit", parhist_sfo) set.seed(123456) saem_biphasic_m_multi <- multistart(saem_biphasic_m, n = 8, diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index d8b6b19e..193dcdcd 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -10,8 +10,7 @@ test_that("Parent fits using saemix are correctly implemented", { # We did not introduce variance of parent_0 in the data generation # This is correctly detected expect_equal(illparms(sfo_saem_1), "sd(parent_0)") - # So we remove this variance - sfo_saem_1_reduced <- update(sfo_saem_1, no_random_effect = "parent_0") + # So we have also done a fit without this variance expect_equal(illparms(sfo_saem_1_reduced), character(0)) # We cannot currently do the fit with completely fixed initial values -- cgit v1.2.1