From 5889cd78376e244f38e6c5acba8ffbc46e18f803 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 16 Nov 2022 13:50:54 +0100 Subject: Address platform dependence that surfaced on winbuilder --- tests/testthat/test_multistart.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index c1a10d10..5803b62c 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -9,7 +9,12 @@ test_that("multistart works for saem.mmkin models", { best(saem_sfo_s_multi), test = TRUE ) - expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.5) + # On winbuilder, sfo_saem_1 gives an AIC of 1310.8, while we get 1311.7 + # locally on Linux and Windows. The other, well-determined fits + # both give 1309.7 + expect_equal(round(anova_sfo, 1)["sfo_saem_1_reduced", "AIC"], 1309.7) + expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1309.7) + expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, CRAN: 0.4 skip_on_cran() # Save CRAN time set.seed(123456) -- cgit v1.2.3 From 90354f5cd9e095f9ef98424689a2716770b248d4 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 16 Nov 2022 22:44:34 +0100 Subject: Reduce testing on CRAN servers --- log/build.log | 1 - tests/testthat/test_dmta.R | 8 ++++---- tests/testthat/test_multistart.R | 2 +- tests/testthat/test_nafta.R | 2 ++ 4 files changed, 7 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/log/build.log b/log/build.log index c4f9b8a2..a56a64df 100644 --- a/log/build.log +++ b/log/build.log @@ -6,4 +6,3 @@ * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories * building ‘mkin_1.2.0.tar.gz’ - diff --git a/tests/testthat/test_dmta.R b/tests/testthat/test_dmta.R index 30c5d7c4..c44cdac8 100644 --- a/tests/testthat/test_dmta.R +++ b/tests/testthat/test_dmta.R @@ -11,13 +11,13 @@ names(dmta_ds) <- sapply(dimethenamid_2018$ds, function(ds) ds$title) dmta_ds[["Elliot"]] <- rbind(dmta_ds[["Elliot 1"]], dmta_ds[["Elliot 2"]]) dmta_ds[["Elliot 1"]] <- dmta_ds[["Elliot 2"]] <- NULL -# mkin -dmta_dfop <- mmkin("DFOP", dmta_ds, quiet = TRUE, cores = n_cores) -dmta_dfop_tc <- mmkin("DFOP", dmta_ds, error_model = "tc", quiet = TRUE, cores = n_cores) - test_that("Different backends get consistent results for DFOP tc, dimethenamid data", { skip_on_cran() # Time constraints + # mkin + dmta_dfop <- mmkin("DFOP", dmta_ds, quiet = TRUE, cores = n_cores) + dmta_dfop_tc <- mmkin("DFOP", dmta_ds, error_model = "tc", quiet = TRUE, cores = n_cores) + # nlme expect_warning( nlme_dfop_tc <- nlme(dmta_dfop_tc), diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 5803b62c..98d3fb6d 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -1,6 +1,7 @@ context("Multistart method for saem.mmkin models") test_that("multistart works for saem.mmkin models", { + skip_on_cran() # Save CRAN time set.seed(123456) saem_sfo_s_multi <- multistart(sfo_saem_1_reduced, n = 8, cores = n_cores, no_random_effect = "parent_0") @@ -16,7 +17,6 @@ test_that("multistart works for saem.mmkin models", { expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1309.7) expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, CRAN: 0.4 - skip_on_cran() # Save CRAN time set.seed(123456) saem_biphasic_m_multi <- multistart(saem_biphasic_m, n = 8, cores = n_cores) diff --git a/tests/testthat/test_nafta.R b/tests/testthat/test_nafta.R index 8eb052c5..b89ea342 100644 --- a/tests/testthat/test_nafta.R +++ b/tests/testthat/test_nafta.R @@ -4,6 +4,7 @@ test_that("Data for more than one compound are rejected", expect_error(nafta(FOCUS_2006_D, cores = 1))) test_that("Test data from Appendix B are correctly evaluated", { + skip_on_cran() expect_message(res <- nafta(NAFTA_SOP_Appendix_B, "aerobic aquatic", cores = 1)) # From Figure D.1 @@ -25,6 +26,7 @@ test_that("Test data from Appendix B are correctly evaluated", { }) test_that("Test data from Appendix D are correctly evaluated", { + skip_on_cran() # We are not interested in the warnings about non-normal residuals here suppressWarnings( res <- nafta(NAFTA_SOP_Appendix_D, "MRID 555555", -- cgit v1.2.3 From 549baaa3cef90ee9f256b14531d4de40d5131dc0 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 04:49:20 +0100 Subject: Typo that did not affect test results --- tests/testthat/test_AIC.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testthat/test_AIC.R b/tests/testthat/test_AIC.R index 57b9a673..7e97904d 100644 --- a/tests/testthat/test_AIC.R +++ b/tests/testthat/test_AIC.R @@ -8,6 +8,6 @@ test_that("The AIC is reproducible", { expect_error(AIC(fits["SFO", ]), "column object") expect_error(BIC(fits["SFO", ]), "column object") expect_equivalent(BIC(fits[, "FOCUS_C"]), - data.frame(df = c(3, 4, 5, 5), AIC = c(59.9, 45.5, 30.0, 40.2)), + data.frame(df = c(3, 4, 5, 5), BIC = c(59.9, 45.5, 30.0, 40.2)), scale = 1, tolerance = 0.1) }) -- cgit v1.2.3 From 1ba099d12ece70f77737505c41eaa7fd1c701140 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 06:50:00 +0100 Subject: Avoid ill-determined fit, it is platform dependent The previous test lead to an error on the Fedora test systems (gcc and clang) on CRAN: ... Results have changed from known value recorded in 'print_dfop_saemix_1.txt'. old[13:24] vs new[13:24] "" "Fitted parameters:" " estimate lower upper" - "parent_0 100.09 98.94 101.25" + "parent_0 100.17 99.01 101.33" - "log_k1 -2.68 -2.91 -2.45" + "log_k1 -2.66 -2.89 -2.43" "log_k2 -4.12 -4.24 -4.00" - "g_qlogis -0.41 -0.63 -0.20" + "g_qlogis -0.43 -0.65 -0.21" - "a.1 0.91 0.67 1.15" + "a.1 0.91 0.67 1.16" "b.1 0.05 0.04 0.06" - "SD.log_k1 0.36 0.21 0.50" + "SD.log_k1 0.35 0.21 0.50" and 2 more ... --- tests/testthat/print_dfop_saemix_1.txt | 21 ++++++++++----------- tests/testthat/setup_script.R | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/testthat/print_dfop_saemix_1.txt b/tests/testthat/print_dfop_saemix_1.txt index f6fda37c..bdc40065 100644 --- a/tests/testthat/print_dfop_saemix_1.txt +++ b/tests/testthat/print_dfop_saemix_1.txt @@ -9,16 +9,15 @@ Data: Likelihood computed by importance sampling AIC BIC logLik - 1409 1415 -695 + 1409 1415 -696 Fitted parameters: - estimate lower upper -parent_0 100.09 98.94 101.25 -log_k1 -2.68 -2.91 -2.45 -log_k2 -4.12 -4.24 -4.00 -g_qlogis -0.41 -0.63 -0.20 -a.1 0.91 0.67 1.15 -b.1 0.05 0.04 0.06 -SD.log_k1 0.36 0.21 0.50 -SD.log_k2 0.22 0.13 0.30 -SD.g_qlogis 0.15 -0.09 0.40 + estimate lower upper +parent_0 99.92 98.77 101.06 +log_k1 -2.72 -2.95 -2.50 +log_k2 -4.14 -4.27 -4.01 +g_qlogis -0.35 -0.53 -0.16 +a.1 0.92 0.68 1.16 +b.1 0.05 0.04 0.06 +SD.log_k1 0.37 0.23 0.51 +SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index 777c998a..362038c3 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -185,7 +185,7 @@ nlme_biphasic <- suppressWarnings(nlme(mmkin_biphasic)) 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") + no_random_effect = c("parent_0", "g_qlogis")) saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE) saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE) -- cgit v1.2.3 From df0cff4b829f1abf62f037591a24a8019174dd0a Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 08:37:40 +0100 Subject: Pass error.init to saemix_model, show in parplot Due to an oversight, error.init was not really passed to saemix_model in saem.mmkin. The new initial values were reverted to c(1, 1), in order to avoid changing the test results. Initial values for error model parameters are now shown in parplot.multistart. --- R/parplot.R | 19 ++++++++--- R/saem.R | 3 +- log/build.log | 1 + log/test.log | 38 +++++++++++----------- man/parplot.Rd | 5 +++ man/saem.Rd | 2 +- .../multistart/parplot-for-biphasic-saemix-fit.svg | 2 ++ .../_snaps/multistart/parplot-for-sfo-fit.svg | 2 ++ tests/testthat/test_multistart.R | 8 ++--- 9 files changed, 51 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/R/parplot.R b/R/parplot.R index 627a4eb8..98579779 100644 --- a/R/parplot.R +++ b/R/parplot.R @@ -4,6 +4,10 @@ #' either by the parameters of the run with the highest likelihood, #' or by their medians as proposed in the paper by Duchesne et al. (2021). #' +#' Starting values of degradation model parameters and error model parameters +#' are shown as green circles. The results obtained in the original run +#' are shown as red circles. +#' #' @param object The [multistart] object #' @param llmin The minimum likelihood of objects to be shown #' @param scale By default, scale parameters using the best available fit. @@ -32,7 +36,7 @@ parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, scale = c("best" orig <- attr(object, "orig") orig_parms <- parms(orig) - start_parms <- orig$mean_dp_start + start_degparms <- orig$mean_dp_start all_parms <- parms(object) if (inherits(object, "multistart.saem.mmkin")) { @@ -49,18 +53,18 @@ parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, scale = c("best" par(las = 1) if (orig$transformations == "mkin") { - degparm_names_transformed <- names(start_parms) + degparm_names_transformed <- names(start_degparms) degparm_index <- which(names(orig_parms) %in% degparm_names_transformed) orig_parms[degparm_names_transformed] <- backtransform_odeparms( orig_parms[degparm_names_transformed], orig$mmkin[[1]]$mkinmod, transform_rates = orig$mmkin[[1]]$transform_rates, transform_fractions = orig$mmkin[[1]]$transform_fractions) - start_parms <- backtransform_odeparms(start_parms, + start_degparms <- backtransform_odeparms(start_degparms, orig$mmkin[[1]]$mkinmod, transform_rates = orig$mmkin[[1]]$transform_rates, transform_fractions = orig$mmkin[[1]]$transform_fractions) - degparm_names <- names(start_parms) + degparm_names <- names(start_degparms) names(orig_parms) <- c(degparm_names, names(orig_parms[-degparm_index])) @@ -72,6 +76,13 @@ parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, scale = c("best" colnames(selected_parms)[1:length(degparm_names)] <- degparm_names } + start_errparms <- orig$so@model@error.init + names(start_errparms) <- orig$so@model@name.sigma + + start_omegaparms <- orig$so@model@omega.init + + start_parms <- c(start_degparms, start_errparms) + scale <- match.arg(scale) parm_scale <- switch(scale, best = selected_parms[which.best(object[selected]), ], diff --git a/R/saem.R b/R/saem.R index 696ea0ee..c77ff70f 100644 --- a/R/saem.R +++ b/R/saem.R @@ -149,7 +149,7 @@ saem.mmkin <- function(object, covariates = NULL, covariate_models = NULL, no_random_effect = NULL, - error.init = c(3, 0.1), + error.init = c(1, 1), nbiter.saemix = c(300, 100), control = list(displayProgress = FALSE, print = FALSE, nbiter.saemix = nbiter.saemix, @@ -708,6 +708,7 @@ saemix_model <- function(object, solution_type = "auto", covariance.model = covariance.model, covariate.model = covariate.model, omega.init = omega.init, + error.init = error.init, ... ) attr(res, "mean_dp_start") <- degparms_optim diff --git a/log/build.log b/log/build.log index a56a64df..c4f9b8a2 100644 --- a/log/build.log +++ b/log/build.log @@ -6,3 +6,4 @@ * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories * building ‘mkin_1.2.0.tar.gz’ + diff --git a/log/test.log b/log/test.log index b305bf58..af8e52fd 100644 --- a/log/test.log +++ b/log/test.log @@ -1,53 +1,53 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.5s] +✔ | 5 | Analytical solutions for coupled models [3.2s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE -✔ | 12 | Confidence intervals and p-values [1.1s] -✔ | 1 12 | Dimethenamid data from 2018 [34.5s] +✔ | 12 | Confidence intervals and p-values [1.0s] +✔ | 1 12 | Dimethenamid data from 2018 [31.4s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.3s] +✔ | 14 | Error model fitting [4.9s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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.4s] ✔ | 1 | Fitting the logistic model [0.2s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [25.6s] -✔ | 1 12 | Nonlinear mixed-effects models [0.4s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [23.9s] +✔ | 1 12 | Nonlinear mixed-effects models [0.3s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:74'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.6s] +✔ | 10 | Special cases of mkinfit calls [0.5s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] -✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 9 | Multistart method for saem.mmkin models [40.2s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.6s] -✔ | 9 | Nonlinear mixed-effects models with nlme [9.5s] -✔ | 16 | Plotting [10.5s] +✔ | 3 | Model predictions with mkinpredict [0.4s] +✔ | 9 | Multistart method for saem.mmkin models [37.0s] +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.5s] +✔ | 9 | Nonlinear mixed-effects models with nlme [8.8s] +✔ | 16 | Plotting [10.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [69.8s] +✔ | 1 36 | saemix parent models [66.0s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.6s] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.9s] +✔ | 10 | 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.5s] -✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.3s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] +✔ | 9 | Hypothesis tests [8.0s] +✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 225.9 s +Duration: 211.3 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) diff --git a/man/parplot.Rd b/man/parplot.Rd index 37c5841d..ac9e02cf 100644 --- a/man/parplot.Rd +++ b/man/parplot.Rd @@ -35,6 +35,11 @@ Produces a boxplot with all parameters from the multiple runs, scaled either by the parameters of the run with the highest likelihood, or by their medians as proposed in the paper by Duchesne et al. (2021). } +\details{ +Starting values of degradation model parameters and error model parameters +are shown as green circles. The results obtained in the original run +are shown as red circles. +} \references{ Duchesne R, Guillemin A, Gandrillon O, Crauste F. Practical identifiability in the frame of nonlinear mixed effects models: the example diff --git a/man/saem.Rd b/man/saem.Rd index 11463351..984d341b 100644 --- a/man/saem.Rd +++ b/man/saem.Rd @@ -24,7 +24,7 @@ saem(object, ...) covariates = NULL, covariate_models = NULL, no_random_effect = NULL, - error.init = c(3, 0.1), + error.init = c(1, 1), nbiter.saemix = c(300, 100), control = list(displayProgress = FALSE, print = FALSE, nbiter.saemix = nbiter.saemix, save = FALSE, save.graphs = FALSE), diff --git a/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg index c0332fd5..7017908e 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg @@ -173,6 +173,8 @@ + + diff --git a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg index f3373901..18eb7fcc 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg @@ -89,6 +89,8 @@ + + diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 98d3fb6d..502cee98 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -3,16 +3,16 @@ context("Multistart method for saem.mmkin models") test_that("multistart works for saem.mmkin models", { skip_on_cran() # Save CRAN time set.seed(123456) - saem_sfo_s_multi <- multistart(sfo_saem_1_reduced, n = 8, cores = n_cores, - no_random_effect = "parent_0") + saem_sfo_s_multi <- multistart(sfo_saem_1_reduced, n = 8, cores = n_cores) anova_sfo <- anova(sfo_saem_1, sfo_saem_1_reduced, best(saem_sfo_s_multi), test = TRUE ) # On winbuilder, sfo_saem_1 gives an AIC of 1310.8, while we get 1311.7 - # locally on Linux and Windows. The other, well-determined fits - # both give 1309.7 + # locally (using saemix 3.2, which likely makes the difference due to the + # error parameter patch) on Linux and Windows. The other, well-determined + # fits both give 1309.7. expect_equal(round(anova_sfo, 1)["sfo_saem_1_reduced", "AIC"], 1309.7) expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1309.7) expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, CRAN: 0.4 -- cgit v1.2.3 From a14237fc1580b09f8772cd3330b0a445785e48ac Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 10:09:28 +0100 Subject: Round parameters with signif() before printing This will hopefully make the test pass on all relevant platforms. --- NEWS.md | 4 +++- log/build.log | 2 +- log/test.log | 20 ++++++++++---------- tests/testthat/print_dfop_saemix_1.txt | 8 ++++---- tests/testthat/test_mixed.R | 7 ++++++- 5 files changed, 24 insertions(+), 17 deletions(-) (limited to 'tests') diff --git a/NEWS.md b/NEWS.md index a72a0d13..245a3973 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # mkin 1.2.1 (unreleased) -- 'tests/testthat/setup_script.R': Excluded another ill-defined random effect for the DFOP fit with 'saem', in an attempt to avoid a platform dependence that surfaced on Fedora systems on the CRAN check farm. +- 'tests/testthat/setup_script.R': Excluded another ill-defined random effect for the DFOP fit with 'saem', in an attempt to avoid a platform dependence that surfaced on Fedora systems on the CRAN check farm + +- 'tests/testthat/test_mixed.R': Round parameters found by saemix to two significant digits before printing, to also help to avoid platform dependence of tests - 'R/saem.R': Fix a bug that prevented that 'error.ini' is passed to 'saemix_model', and set default to c(1, 1) to avoid changing test results diff --git a/log/build.log b/log/build.log index c4f9b8a2..6be01938 100644 --- a/log/build.log +++ b/log/build.log @@ -5,5 +5,5 @@ * creating vignettes ... OK * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories -* building ‘mkin_1.2.0.tar.gz’ +* building ‘mkin_1.2.1.tar.gz’ diff --git a/log/test.log b/log/test.log index af8e52fd..87d24690 100644 --- a/log/test.log +++ b/log/test.log @@ -1,38 +1,38 @@ ℹ 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 [31.4s] +✔ | 1 12 | Dimethenamid data from 2018 [31.5s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [4.9s] +✔ | 14 | Error model fitting [5.0s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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.4s] ✔ | 1 | Fitting the logistic model [0.2s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [23.9s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.4s] ✔ | 1 12 | Nonlinear mixed-effects models [0.3s] ──────────────────────────────────────────────────────────────────────────────── -Skip ('test_mixed.R:74'): saemix results are reproducible for biphasic fits +Skip ('test_mixed.R:79'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg ✔ | 10 | Special cases of mkinfit calls [0.5s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] -✔ | 3 | Model predictions with mkinpredict [0.4s] -✔ | 9 | Multistart method for saem.mmkin models [37.0s] +✔ | 3 | Model predictions with mkinpredict [0.3s] +✔ | 9 | Multistart method for saem.mmkin models [36.2s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.5s] ✔ | 9 | Nonlinear mixed-effects models with nlme [8.8s] -✔ | 16 | Plotting [10.1s] +✔ | 16 | Plotting [10.0s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [66.0s] +✔ | 1 36 | saemix parent models [65.8s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): We can also use mkin solution methods for saem Reason: This still takes almost 2.5 minutes although we do not solve ODEs @@ -47,7 +47,7 @@ Reason: This still takes almost 2.5 minutes although we do not solve ODEs ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 211.3 s +Duration: 210.4 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) diff --git a/tests/testthat/print_dfop_saemix_1.txt b/tests/testthat/print_dfop_saemix_1.txt index bdc40065..1d399a52 100644 --- a/tests/testthat/print_dfop_saemix_1.txt +++ b/tests/testthat/print_dfop_saemix_1.txt @@ -13,11 +13,11 @@ Likelihood computed by importance sampling Fitted parameters: estimate lower upper -parent_0 99.92 98.77 101.06 -log_k1 -2.72 -2.95 -2.50 -log_k2 -4.14 -4.27 -4.01 +parent_0 100.00 99.00 100.00 +log_k1 -2.70 -3.00 -2.50 +log_k2 -4.10 -4.30 -4.00 g_qlogis -0.35 -0.53 -0.16 -a.1 0.92 0.68 1.16 +a.1 0.92 0.68 1.20 b.1 0.05 0.04 0.06 SD.log_k1 0.37 0.23 0.51 SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 646b6110..2d53c6dd 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -11,7 +11,12 @@ test_that("Print methods work", { expect_known_output(print(mixed(mmkin_sfo_1), digits = 2), "print_mmkin_sfo_1_mixed.txt") expect_known_output(print(dfop_nlme_1, digits = 1), "print_dfop_nlme_1.txt") - expect_known_output(print(dfop_saemix_1, digits = 1), "print_dfop_saemix_1.txt") + # In order to address the platform dependence of the results, we round to two + # significant digits before printing + dfop_saemix_1_print <- dfop_saemix_1 + dfop_saemix_1_print$so@results@conf.int[c("estimate", "lower", "upper")] <- + signif(dfop_saemix_1_print$so@results@conf.int[c("estimate", "lower", "upper")], 2) + expect_known_output(print(dfop_saemix_1_print, digits = 1), "print_dfop_saemix_1.txt") }) test_that("nlme results are reproducible to some degree", { -- cgit v1.2.3 From 5364f037a72863ef5ba81e14ba4417f68fd389f9 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 19:14:47 +0100 Subject: Make mixed model test data permanent to ensure reproducibility To ensure that tests on different platforms work on the same data, the mixed modelling test data previosly generated in tests/testthat/setup_script.R were generated once using the script in inst/dataset/generation/ds_mixed.R, and are now distributed with the package. --- R/ds_mixed.R | 17 ++ _pkgdown.yml | 3 +- data/ds_mixed.rda | Bin 0 -> 6935 bytes inst/dataset_generation/ds_mixed.R | 105 +++++++++++ log/check.log | 4 +- log/test.log | 28 +-- man/ds_mixed.Rd | 24 +++ .../multistart/llhist-for-biphasic-saemix-fit.svg | 62 ------- .../_snaps/multistart/llhist-for-dfop-sfo-fit.svg | 62 +++++++ .../_snaps/multistart/llhist-for-sfo-fit.svg | 30 +-- .../multistart/parplot-for-biphasic-saemix-fit.svg | 201 --------------------- .../_snaps/multistart/parplot-for-dfop-sfo-fit.svg | 201 +++++++++++++++++++++ .../_snaps/multistart/parplot-for-sfo-fit.svg | 90 ++++----- tests/testthat/anova_sfo_saem.txt | 10 +- tests/testthat/print_dfop_saem_1.txt | 23 +++ tests/testthat/print_dfop_saemix_1.txt | 23 --- tests/testthat/print_fits_synth_const.txt | 2 +- tests/testthat/print_mmkin_sfo_1_mixed.txt | 4 +- tests/testthat/print_multistart_biphasic.txt | 4 - tests/testthat/print_multistart_dfop_sfo.txt | 4 + tests/testthat/print_sfo_saem_1_reduced.txt | 12 +- tests/testthat/setup_script.R | 99 +--------- tests/testthat/summary_hfit_sfo_tc.txt | 26 +-- tests/testthat/summary_saem_biphasic_s.txt | 87 --------- tests/testthat/summary_saem_dfop_sfo_s.txt | 87 +++++++++ tests/testthat/test_mixed.R | 32 ++-- tests/testthat/test_multistart.R | 30 ++- tests/testthat/test_plot.R | 22 +-- tests/testthat/test_saemix_parent.R | 40 ++-- 29 files changed, 697 insertions(+), 635 deletions(-) create mode 100644 R/ds_mixed.R create mode 100644 data/ds_mixed.rda create mode 100644 inst/dataset_generation/ds_mixed.R create mode 100644 man/ds_mixed.Rd delete mode 100644 tests/testthat/_snaps/multistart/llhist-for-biphasic-saemix-fit.svg create mode 100644 tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg delete mode 100644 tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg create mode 100644 tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg create mode 100644 tests/testthat/print_dfop_saem_1.txt delete mode 100644 tests/testthat/print_dfop_saemix_1.txt delete mode 100644 tests/testthat/print_multistart_biphasic.txt create mode 100644 tests/testthat/print_multistart_dfop_sfo.txt delete mode 100644 tests/testthat/summary_saem_biphasic_s.txt create mode 100644 tests/testthat/summary_saem_dfop_sfo_s.txt (limited to 'tests') diff --git a/R/ds_mixed.R b/R/ds_mixed.R new file mode 100644 index 00000000..c5055712 --- /dev/null +++ b/R/ds_mixed.R @@ -0,0 +1,17 @@ +#' Synthetic data for hierarchical kinetic degradation models +#' +#' The R code used to create this data object is installed with this package in +#' the 'dataset_generation' directory. +#' +#' @name ds_mixed +#' @aliases ds_sfo ds_fomc ds_dfop ds_hs ds_dfop_sfo +#' @examples +#' \dontrun{ +#' sfo_mmkin <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = 15) +#' sfo_saem <- saem(sfo_mmkin, no_random_effect = "parent_0") +#' plot(sfo_saem) +#' } +#' +#' # This is the code used to generate the datasets +#' cat(readLines(system.file("dataset_generation/ds_mixed.R", package = "mkin")), sep = "\n") +NULL diff --git a/_pkgdown.yml b/_pkgdown.yml index 8aa44ed4..98ed84f2 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -67,7 +67,7 @@ reference: - parplot - title: Datasets and known results contents: - - focus_soil_moisture + - ds_mixed - D24_2014 - dimethenamid_2018 - FOCUS_2006_A @@ -82,6 +82,7 @@ reference: - synthetic_data_for_UBA_2014 - experimental_data_for_UBA_2019 - test_data_from_UBA_2014 + - focus_soil_moisture - mkinds - mkindsg - title: NAFTA guidance diff --git a/data/ds_mixed.rda b/data/ds_mixed.rda new file mode 100644 index 00000000..cf9f6463 Binary files /dev/null and b/data/ds_mixed.rda differ diff --git a/inst/dataset_generation/ds_mixed.R b/inst/dataset_generation/ds_mixed.R new file mode 100644 index 00000000..f2ae6e7e --- /dev/null +++ b/inst/dataset_generation/ds_mixed.R @@ -0,0 +1,105 @@ +# Synthetic data for hierarchical kinetic models +# Refactored version of the code previously in tests/testthat/setup_script.R +# The number of datasets was 3 for FOMC, and 10 for HS in that script, now it +# is always 15 for consistency + +library(mkin) # We use mkinmod and mkinpredict +sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) +n <- 15 +log_sd <- 0.3 +err_1 = list(const = 1, prop = 0.05) +tc <- function(value) sigma_twocomp(value, err_1$const, err_1$prop) +const <- function(value) 2 + +set.seed(123456) +SFO <- mkinmod(parent = mkinsub("SFO")) +sfo_pop <- list(parent_0 = 100, k_parent = 0.03) +sfo_parms <- as.matrix(data.frame( + k_parent = rlnorm(n, log(sfo_pop$k_parent), log_sd))) +set.seed(123456) +ds_sfo <- lapply(1:n, function(i) { + ds_mean <- mkinpredict(SFO, sfo_parms[i, ], + c(parent = sfo_pop$parent_0), sampling_times) + add_err(ds_mean, tc, n = 1)[[1]] +}) +attr(ds_sfo, "pop") <- sfo_pop +attr(ds_sfo, "parms") <- sfo_parms + +set.seed(123456) +FOMC <- mkinmod(parent = mkinsub("FOMC")) +fomc_pop <- list(parent_0 = 100, alpha = 2, beta = 8) +fomc_parms <- as.matrix(data.frame( + alpha = rlnorm(n, log(fomc_pop$alpha), 0.4), + beta = rlnorm(n, log(fomc_pop$beta), 0.2))) +set.seed(123456) +ds_fomc <- lapply(1:n, function(i) { + ds_mean <- mkinpredict(FOMC, fomc_parms[i, ], + c(parent = fomc_pop$parent_0), sampling_times) + add_err(ds_mean, tc, n = 1)[[1]] +}) +attr(ds_fomc, "pop") <- fomc_pop +attr(ds_fomc, "parms") <- fomc_parms + +set.seed(123456) +DFOP <- mkinmod(parent = mkinsub("DFOP")) +dfop_pop <- list(parent_0 = 100, k1 = 0.06, k2 = 0.015, g = 0.4) +dfop_parms <- as.matrix(data.frame( + k1 = rlnorm(n, log(dfop_pop$k1), log_sd), + k2 = rlnorm(n, log(dfop_pop$k2), log_sd), + g = plogis(rnorm(n, qlogis(dfop_pop$g), log_sd)))) +set.seed(123456) +ds_dfop <- lapply(1:n, function(i) { + ds_mean <- mkinpredict(DFOP, dfop_parms[i, ], + c(parent = dfop_pop$parent_0), sampling_times) + add_err(ds_mean, tc, n = 1)[[1]] +}) +attr(ds_dfop, "pop") <- dfop_pop +attr(ds_dfop, "parms") <- dfop_parms + +set.seed(123456) +HS <- mkinmod(parent = mkinsub("HS")) +hs_pop <- list(parent_0 = 100, k1 = 0.08, k2 = 0.01, tb = 15) +hs_parms <- as.matrix(data.frame( + k1 = rlnorm(n, log(hs_pop$k1), log_sd), + k2 = rlnorm(n, log(hs_pop$k2), log_sd), + tb = rlnorm(n, log(hs_pop$tb), 0.1))) +set.seed(123456) +ds_hs <- lapply(1:n, function(i) { + ds_mean <- mkinpredict(HS, hs_parms[i, ], + c(parent = hs_pop$parent_0), sampling_times) + add_err(ds_mean, const, n = 1)[[1]] +}) +attr(ds_hs, "pop") <- hs_pop +attr(ds_hs, "parms") <- hs_parms + +set.seed(123456) +DFOP_SFO <- mkinmod( + parent = mkinsub("DFOP", "m1"), + m1 = mkinsub("SFO"), + quiet = TRUE) +dfop_sfo_pop <- list(parent_0 = 100, + k_m1 = 0.007, f_parent_to_m1 = 0.5, + k1 = 0.1, k2 = 0.02, g = 0.5) +dfop_sfo_parms <- as.matrix(data.frame( + k1 = rlnorm(n, log(dfop_sfo_pop$k1), log_sd), + k2 = rlnorm(n, log(dfop_sfo_pop$k2), log_sd), + g = plogis(rnorm(n, qlogis(dfop_sfo_pop$g), log_sd)), + f_parent_to_m1 = plogis(rnorm(n, + qlogis(dfop_sfo_pop$f_parent_to_m1), log_sd)), + k_m1 = rlnorm(n, log(dfop_sfo_pop$k_m1), log_sd))) +ds_dfop_sfo_mean <- lapply(1:n, + function(i) { + mkinpredict(DFOP_SFO, dfop_sfo_parms[i, ], + c(parent = dfop_sfo_pop$parent_0, m1 = 0), sampling_times) + } +) +set.seed(123456) +ds_dfop_sfo <- lapply(ds_dfop_sfo_mean, function(ds) { + add_err(ds, + sdfunc = function(value) sqrt(err_1$const^2 + value^2 * err_1$prop^2), + n = 1, secondary = "m1")[[1]] +}) +attr(ds_dfop_sfo, "pop") <- dfop_sfo_pop +attr(ds_dfop_sfo, "parms") <- dfop_sfo_parms + +#save(ds_sfo, ds_fomc, ds_dfop, ds_hs, ds_dfop_sfo, file = "data/ds_mixed.rda", version = 2) diff --git a/log/check.log b/log/check.log index 7aa4610c..31fc31eb 100644 --- a/log/check.log +++ b/log/check.log @@ -5,7 +5,7 @@ * using options ‘--no-tests --as-cran’ * checking for file ‘mkin/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘mkin’ version ‘1.2.0’ +* this is package ‘mkin’ version ‘1.2.1’ * package encoding: UTF-8 * checking CRAN incoming feasibility ... Note_to_CRAN_maintainers Maintainer: ‘Johannes Ranke ’ @@ -41,7 +41,7 @@ Maintainer: ‘Johannes Ranke ’ * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK -* checking R code for possible problems ... [18s/18s] OK +* checking R code for possible problems ... [17s/17s] OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd line widths ... OK diff --git a/log/test.log b/log/test.log index 87d24690..d1de270e 100644 --- a/log/test.log +++ b/log/test.log @@ -5,19 +5,19 @@ ✔ | 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 [31.5s] +✔ | 1 12 | Dimethenamid data from 2018 [32.6s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.0s] +✔ | 14 | Error model fitting [5.1s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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.4s] ✔ | 1 | Fitting the logistic model [0.2s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.4s] -✔ | 1 12 | Nonlinear mixed-effects models [0.3s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.6s] +✔ | 1 13 | Nonlinear mixed-effects models [0.4s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:79'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve @@ -26,32 +26,32 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve ✔ | 10 | Special cases of mkinfit calls [0.5s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] -✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 9 | Multistart method for saem.mmkin models [36.2s] +✔ | 3 | Model predictions with mkinpredict [0.4s] +✔ | 9 | Multistart method for saem.mmkin models [37.3s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.5s] -✔ | 9 | Nonlinear mixed-effects models with nlme [8.8s] -✔ | 16 | Plotting [10.0s] +✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] +✔ | 16 | Plotting [10.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [65.8s] +✔ | 1 36 | saemix parent models [71.4s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.4s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.7s] +✔ | 10 | Fitting the SFORB model [3.9s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] -✔ | 9 | Hypothesis tests [8.0s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.3s] +✔ | 9 | Hypothesis tests [8.3s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 210.4 s +Duration: 220.0 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 269 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 270 ] diff --git a/man/ds_mixed.Rd b/man/ds_mixed.Rd new file mode 100644 index 00000000..227b8e7f --- /dev/null +++ b/man/ds_mixed.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ds_mixed.R +\name{ds_mixed} +\alias{ds_mixed} +\alias{ds_sfo} +\alias{ds_fomc} +\alias{ds_dfop} +\alias{ds_hs} +\alias{ds_dfop_sfo} +\title{Synthetic data for hierarchical kinetic degradation models} +\description{ +The R code used to create this data object is installed with this package in +the 'dataset_generation' directory. +} +\examples{ +\dontrun{ + sfo_mmkin <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = 15) + sfo_saem <- saem(sfo_mmkin, no_random_effect = "parent_0") + plot(sfo_saem) +} + +# This is the code used to generate the datasets +cat(readLines(system.file("dataset_generation/ds_mixed.R", package = "mkin")), sep = "\n") +} diff --git a/tests/testthat/_snaps/multistart/llhist-for-biphasic-saemix-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-biphasic-saemix-fit.svg deleted file mode 100644 index 6015aed8..00000000 --- a/tests/testthat/_snaps/multistart/llhist-for-biphasic-saemix-fit.svg +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - -Frequency of log likelihoods - - - - - - - --1149.5 --1149.4 --1149.3 --1149.2 --1149.1 --1149.0 - - - - - - -0 -1 -2 -3 -4 - - - - - - - - - - - - - - -original fit - - diff --git a/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg new file mode 100644 index 00000000..6015aed8 --- /dev/null +++ b/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg @@ -0,0 +1,62 @@ + + + + + + + + + + + + +Frequency of log likelihoods + + + + + + + +-1149.5 +-1149.4 +-1149.3 +-1149.2 +-1149.1 +-1149.0 + + + + + + +0 +1 +2 +3 +4 + + + + + + + + + + + + + + +original fit + + diff --git a/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg index 98513d06..028c69de 100644 --- a/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg @@ -25,20 +25,22 @@ --649.836 --649.834 --649.832 --649.830 --649.828 +-646.124 +-646.123 +-646.122 +-646.121 +-646.120 - - + + + 0 -1 -2 -3 +1 +2 +3 +4 @@ -46,11 +48,11 @@ - + - - - + + + original fit diff --git a/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg deleted file mode 100644 index 7017908e..00000000 --- a/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg +++ /dev/null @@ -1,201 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -parent_0 -f_parent_to_m1 -k2 -g -a.1 -b.1 -SD.log_k_m1 -SD.log_k1 -SD.g_qlogis - - - - - -0.5 -1.0 -1.5 -2.0 -Normalised parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Starting parameters -Original run -Multistart runs - - diff --git a/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg new file mode 100644 index 00000000..7017908e --- /dev/null +++ b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +parent_0 +f_parent_to_m1 +k2 +g +a.1 +b.1 +SD.log_k_m1 +SD.log_k1 +SD.g_qlogis + + + + + +0.5 +1.0 +1.5 +2.0 +Normalised parameters + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Starting parameters +Original run +Multistart runs + + diff --git a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg index 18eb7fcc..a47a585a 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg @@ -25,42 +25,44 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -87,15 +89,15 @@ - - - - - - - - - + + + + + + + + + diff --git a/tests/testthat/anova_sfo_saem.txt b/tests/testthat/anova_sfo_saem.txt index 9e4bf71f..0ccd6d5c 100644 --- a/tests/testthat/anova_sfo_saem.txt +++ b/tests/testthat/anova_sfo_saem.txt @@ -1,7 +1,7 @@ -Data: 262 observations of 1 variable(s) grouped in 15 datasets +Data: 263 observations of 1 variable(s) grouped in 15 datasets npar AIC BIC Lik Chisq Df Pr(>Chisq) -sfo_saem_1_reduced 5 1310 1313 -650 -sfo_saem_1_reduced_mkin 5 1310 1313 -650 0 0 -sfo_saem_1 6 1312 1316 -650 0 1 1 -sfo_saem_1_mkin 6 1312 1316 -650 0 0 +sfo_saem_1_reduced 5 1302 1306 -646 +sfo_saem_1_reduced_mkin 5 1302 1306 -646 0 0 +sfo_saem_1 6 1304 1308 -646 0 1 1 +sfo_saem_1_mkin 6 1303 1308 -646 1 0 diff --git a/tests/testthat/print_dfop_saem_1.txt b/tests/testthat/print_dfop_saem_1.txt new file mode 100644 index 00000000..bdc40065 --- /dev/null +++ b/tests/testthat/print_dfop_saem_1.txt @@ -0,0 +1,23 @@ +Kinetic nonlinear mixed-effects model fit by SAEM +Structural model: +d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * + time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time))) + * parent + +Data: +270 observations of 1 variable(s) grouped in 15 datasets + +Likelihood computed by importance sampling + AIC BIC logLik + 1409 1415 -696 + +Fitted parameters: + estimate lower upper +parent_0 99.92 98.77 101.06 +log_k1 -2.72 -2.95 -2.50 +log_k2 -4.14 -4.27 -4.01 +g_qlogis -0.35 -0.53 -0.16 +a.1 0.92 0.68 1.16 +b.1 0.05 0.04 0.06 +SD.log_k1 0.37 0.23 0.51 +SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/print_dfop_saemix_1.txt b/tests/testthat/print_dfop_saemix_1.txt deleted file mode 100644 index 1d399a52..00000000 --- a/tests/testthat/print_dfop_saemix_1.txt +++ /dev/null @@ -1,23 +0,0 @@ -Kinetic nonlinear mixed-effects model fit by SAEM -Structural model: -d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * - time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time))) - * parent - -Data: -270 observations of 1 variable(s) grouped in 15 datasets - -Likelihood computed by importance sampling - AIC BIC logLik - 1409 1415 -696 - -Fitted parameters: - estimate lower upper -parent_0 100.00 99.00 100.00 -log_k1 -2.70 -3.00 -2.50 -log_k2 -4.10 -4.30 -4.00 -g_qlogis -0.35 -0.53 -0.16 -a.1 0.92 0.68 1.20 -b.1 0.05 0.04 0.06 -SD.log_k1 0.37 0.23 0.51 -SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/print_fits_synth_const.txt b/tests/testthat/print_fits_synth_const.txt index 2ea1f133..b4bbe6ca 100644 --- a/tests/testthat/print_fits_synth_const.txt +++ b/tests/testthat/print_fits_synth_const.txt @@ -4,7 +4,7 @@ Status of individual fits: dataset model 1 2 3 4 5 6 SFO OK OK OK OK OK OK - FOMC C C OK OK OK OK + FOMC C OK OK OK OK C C: Optimisation did not converge: false convergence (8) diff --git a/tests/testthat/print_mmkin_sfo_1_mixed.txt b/tests/testthat/print_mmkin_sfo_1_mixed.txt index 33e5bf5c..c12cfe2b 100644 --- a/tests/testthat/print_mmkin_sfo_1_mixed.txt +++ b/tests/testthat/print_mmkin_sfo_1_mixed.txt @@ -3,7 +3,7 @@ Structural model: d_parent/dt = - k_parent * parent Data: -262 observations of 1 variable(s) grouped in 15 datasets +263 observations of 1 variable(s) grouped in 15 datasets object Status of individual fits: @@ -16,4 +16,4 @@ OK: No warnings Mean fitted parameters: parent_0 log_k_parent - 99.9 -3.3 + 100.0 -3.4 diff --git a/tests/testthat/print_multistart_biphasic.txt b/tests/testthat/print_multistart_biphasic.txt deleted file mode 100644 index b4344f22..00000000 --- a/tests/testthat/print_multistart_biphasic.txt +++ /dev/null @@ -1,4 +0,0 @@ - object with 8 fits: -OK - 8 -OK: Fit terminated successfully diff --git a/tests/testthat/print_multistart_dfop_sfo.txt b/tests/testthat/print_multistart_dfop_sfo.txt new file mode 100644 index 00000000..b4344f22 --- /dev/null +++ b/tests/testthat/print_multistart_dfop_sfo.txt @@ -0,0 +1,4 @@ + object with 8 fits: +OK + 8 +OK: Fit terminated successfully diff --git a/tests/testthat/print_sfo_saem_1_reduced.txt b/tests/testthat/print_sfo_saem_1_reduced.txt index bac8848e..1c7fb588 100644 --- a/tests/testthat/print_sfo_saem_1_reduced.txt +++ b/tests/testthat/print_sfo_saem_1_reduced.txt @@ -3,16 +3,16 @@ Structural model: d_parent/dt = - k_parent * parent Data: -262 observations of 1 variable(s) grouped in 15 datasets +263 observations of 1 variable(s) grouped in 15 datasets Likelihood computed by importance sampling AIC BIC logLik - 1310 1313 -650 + 1302 1306 -646 Fitted parameters: estimate lower upper -parent_0 1e+02 99.08 1e+02 -k_parent 4e-02 0.03 4e-02 -a.1 9e-01 0.75 1e+00 +parent_0 1e+02 99.03 1e+02 +k_parent 3e-02 0.03 4e-02 +a.1 9e-01 0.71 1e+00 b.1 5e-02 0.04 5e-02 -SD.k_parent 3e-01 0.20 4e-01 +SD.k_parent 2e-01 0.14 3e-01 diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index 362038c3..c554800d 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -81,112 +81,27 @@ fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TR fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE, error_model_algorithm = "threestep") -# Mixed models data and fits -sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) -n <- n_biphasic <- 15 -log_sd <- 0.3 -err_1 = list(const = 1, prop = 0.05) -tc <- function(value) sigma_twocomp(value, err_1$const, err_1$prop) -const <- function(value) 2 - -set.seed(123456) -SFO <- mkinmod(parent = mkinsub("SFO")) -k_parent = rlnorm(n, log(0.03), log_sd) -set.seed(123456) -ds_sfo <- lapply(1:n, function(i) { - ds_mean <- mkinpredict(SFO, c(k_parent = k_parent[i]), - c(parent = 100), sampling_times) - add_err(ds_mean, tc, n = 1)[[1]] -}) - -set.seed(123456) -FOMC <- mkinmod(parent = mkinsub("FOMC")) -fomc_pop <- list(parent_0 = 100, alpha = 2, beta = 8) -fomc_parms <- as.matrix(data.frame( - alpha = rlnorm(n, log(fomc_pop$alpha), 0.4), - beta = rlnorm(n, log(fomc_pop$beta), 0.2))) -set.seed(123456) -ds_fomc <- lapply(1:3, function(i) { - ds_mean <- mkinpredict(FOMC, fomc_parms[i, ], - c(parent = 100), sampling_times) - add_err(ds_mean, tc, n = 1)[[1]] -}) - -set.seed(123456) -DFOP <- mkinmod(parent = mkinsub("DFOP")) -dfop_pop <- list(parent_0 = 100, k1 = 0.06, k2 = 0.015, g = 0.4) -dfop_parms <- as.matrix(data.frame( - k1 = rlnorm(n, log(dfop_pop$k1), log_sd), - k2 = rlnorm(n, log(dfop_pop$k2), log_sd), - g = plogis(rnorm(n, qlogis(dfop_pop$g), log_sd)))) -set.seed(123456) -ds_dfop <- lapply(1:n, function(i) { - ds_mean <- mkinpredict(DFOP, dfop_parms[i, ], - c(parent = dfop_pop$parent_0), sampling_times) - add_err(ds_mean, tc, n = 1)[[1]] -}) - -set.seed(123456) -HS <- mkinmod(parent = mkinsub("HS")) -hs_pop <- list(parent_0 = 100, k1 = 0.08, k2 = 0.01, tb = 15) -hs_parms <- as.matrix(data.frame( - k1 = rlnorm(n, log(hs_pop$k1), log_sd), - k2 = rlnorm(n, log(hs_pop$k2), log_sd), - tb = rlnorm(n, log(hs_pop$tb), 0.1))) -set.seed(123456) -ds_hs <- lapply(1:10, function(i) { - ds_mean <- mkinpredict(HS, hs_parms[i, ], - c(parent = hs_pop$parent_0), sampling_times) - add_err(ds_mean, const, n = 1)[[1]] -}) - -set.seed(123456) -DFOP_SFO <- mkinmod( - parent = mkinsub("DFOP", "m1"), - m1 = mkinsub("SFO"), - quiet = TRUE) -dfop_sfo_pop <- list(parent_0 = 100, - k_m1 = 0.007, f_parent_to_m1 = 0.5, - k1 = 0.1, k2 = 0.02, g = 0.5) -syn_biphasic_parms <- as.matrix(data.frame( - k1 = rlnorm(n_biphasic, log(dfop_sfo_pop$k1), log_sd), - k2 = rlnorm(n_biphasic, log(dfop_sfo_pop$k2), log_sd), - g = plogis(rnorm(n_biphasic, qlogis(dfop_sfo_pop$g), log_sd)), - f_parent_to_m1 = plogis(rnorm(n_biphasic, - qlogis(dfop_sfo_pop$f_parent_to_m1), log_sd)), - k_m1 = rlnorm(n_biphasic, log(dfop_sfo_pop$k_m1), log_sd))) -ds_biphasic_mean <- lapply(1:n_biphasic, - function(i) { - mkinpredict(DFOP_SFO, syn_biphasic_parms[i, ], - c(parent = 100, m1 = 0), sampling_times) - } -) -set.seed(123456) -ds_biphasic <- lapply(ds_biphasic_mean, function(ds) { - add_err(ds, - sdfunc = function(value) sqrt(err_1$const^2 + value^2 * err_1$prop^2), - n = 1, secondary = "m1")[[1]] -}) - # Mixed model fits mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = n_cores) mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE, cores = n_cores, error_model = "tc") -mmkin_biphasic <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_biphasic, quiet = TRUE, cores = n_cores, +DFOP_SFO <- mkinmod(parent = mkinsub("DFOP", "m1"), + m1 = mkinsub("SFO"), quiet = TRUE) +mmkin_dfop_sfo <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_dfop_sfo, quiet = TRUE, cores = n_cores, control = list(eval.max = 500, iter.max = 400), error_model = "tc") # nlme dfop_nlme_1 <- suppressWarnings(nlme(mmkin_dfop_1)) -nlme_biphasic <- suppressWarnings(nlme(mmkin_biphasic)) +nlme_dfop_sfo <- suppressWarnings(nlme(mmkin_dfop_sfo)) # 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", +dfop_saem_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", no_random_effect = c("parent_0", "g_qlogis")) -saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE) -saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE) +saem_dfop_sfo_m <- saem(mmkin_dfop_sfo, transformations = "mkin", quiet = TRUE) +saem_dfop_sfo_s <- saem(mmkin_dfop_sfo, transformations = "saemix", quiet = TRUE) diff --git a/tests/testthat/summary_hfit_sfo_tc.txt b/tests/testthat/summary_hfit_sfo_tc.txt index 41743091..bb5bf6fb 100644 --- a/tests/testthat/summary_hfit_sfo_tc.txt +++ b/tests/testthat/summary_hfit_sfo_tc.txt @@ -8,7 +8,7 @@ Equations: d_parent/dt = - k_parent * parent Data: -106 observations of 1 variable(s) grouped in 6 datasets +104 observations of 1 variable(s) grouped in 6 datasets Model predictions using solution type analytical @@ -28,15 +28,15 @@ Results: Likelihood computed by importance sampling AIC BIC logLik - 533 531 -261 + 524 523 -257 Optimised parameters: - est. lower upper -parent_0 101.02 99.58 102.46 -log_k_parent -3.32 -3.53 -3.11 -a.1 0.91 0.64 1.17 -b.1 0.05 0.04 0.06 -SD.log_k_parent 0.27 0.11 0.42 + est. lower upper +parent_0 100.68 99.27 102.08 +log_k_parent -3.38 -3.55 -3.21 +a.1 0.87 0.59 1.14 +b.1 0.05 0.04 0.06 +SD.log_k_parent 0.21 0.09 0.33 Correlation: pr_0 @@ -44,18 +44,18 @@ log_k_parent 0.1 Random effects: est. lower upper -SD.log_k_parent 0.3 0.1 0.4 +SD.log_k_parent 0.2 0.09 0.3 Variance model: est. lower upper -a.1 0.91 0.64 1.17 +a.1 0.87 0.59 1.14 b.1 0.05 0.04 0.06 Backtransformed parameters: est. lower upper -parent_0 1e+02 1e+02 1e+02 -k_parent 4e-02 3e-02 4e-02 +parent_0 1e+02 99.27 1e+02 +k_parent 3e-02 0.03 4e-02 Estimated disappearance times: DT50 DT90 -parent 19 64 +parent 20 68 diff --git a/tests/testthat/summary_saem_biphasic_s.txt b/tests/testthat/summary_saem_biphasic_s.txt deleted file mode 100644 index 7c337843..00000000 --- a/tests/testthat/summary_saem_biphasic_s.txt +++ /dev/null @@ -1,87 +0,0 @@ -saemix version used for fitting: Dummy 0.0 for testing -mkin version used for pre-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 -d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g) - * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * - exp(-k2 * time))) * parent - k_m1 * m1 - -Data: -510 observations of 2 variable(s) grouped in 15 datasets - -Model predictions using solution type analytical - -Fitted in test time 0 s -Using 300, 100 iterations and 4 chains - -Variance model: Two-component variance function - -Mean of starting values for individual parameters: - parent_0 k_m1 f_parent_to_m1 k1 k2 - 1e+02 7e-03 5e-01 1e-01 2e-02 - g - 5e-01 - -Fixed degradation parameter values: -None - -Results: - -Likelihood computed by importance sampling - AIC BIC logLik - 2334 2344 -1153 - -Optimised parameters: - est. lower upper -parent_0 1e+02 1e+02 1e+02 -k_m1 7e-03 6e-03 7e-03 -f_parent_to_m1 5e-01 4e-01 5e-01 -k1 1e-01 9e-02 1e-01 -k2 2e-02 2e-02 3e-02 -g 5e-01 5e-01 5e-01 -a.1 9e-01 8e-01 1e+00 -b.1 5e-02 5e-02 6e-02 -SD.parent_0 3e-02 -5e+01 5e+01 -SD.k_m1 2e-01 1e-01 3e-01 -SD.f_parent_to_m1 3e-01 2e-01 4e-01 -SD.k1 4e-01 2e-01 5e-01 -SD.k2 3e-01 2e-01 5e-01 -SD.g 2e-01 6e-02 4e-01 - -Correlation: - pr_0 k_m1 f___ k1 k2 -k_m1 -0.2 -f_parent_to_m1 -0.3 0.1 -k1 0.1 0.0 0.0 -k2 0.0 0.0 0.0 0.1 -g 0.1 -0.1 0.0 -0.2 -0.2 - -Random effects: - est. lower upper -SD.parent_0 0.03 -49.24 49.3 -SD.k_m1 0.23 0.13 0.3 -SD.f_parent_to_m1 0.30 0.19 0.4 -SD.k1 0.40 0.25 0.5 -SD.k2 0.34 0.21 0.5 -SD.g 0.21 0.06 0.4 - -Variance model: - est. lower upper -a.1 0.93 0.79 1.06 -b.1 0.05 0.05 0.06 - -Resulting formation fractions: - ff -parent_m1 0.5 -parent_sink 0.5 - -Estimated disappearance times: - DT50 DT90 DT50back DT50_k1 DT50_k2 -parent 13 73 22 6 32 -m1 105 348 NA NA NA diff --git a/tests/testthat/summary_saem_dfop_sfo_s.txt b/tests/testthat/summary_saem_dfop_sfo_s.txt new file mode 100644 index 00000000..7c337843 --- /dev/null +++ b/tests/testthat/summary_saem_dfop_sfo_s.txt @@ -0,0 +1,87 @@ +saemix version used for fitting: Dummy 0.0 for testing +mkin version used for pre-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 +d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g) + * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * + exp(-k2 * time))) * parent - k_m1 * m1 + +Data: +510 observations of 2 variable(s) grouped in 15 datasets + +Model predictions using solution type analytical + +Fitted in test time 0 s +Using 300, 100 iterations and 4 chains + +Variance model: Two-component variance function + +Mean of starting values for individual parameters: + parent_0 k_m1 f_parent_to_m1 k1 k2 + 1e+02 7e-03 5e-01 1e-01 2e-02 + g + 5e-01 + +Fixed degradation parameter values: +None + +Results: + +Likelihood computed by importance sampling + AIC BIC logLik + 2334 2344 -1153 + +Optimised parameters: + est. lower upper +parent_0 1e+02 1e+02 1e+02 +k_m1 7e-03 6e-03 7e-03 +f_parent_to_m1 5e-01 4e-01 5e-01 +k1 1e-01 9e-02 1e-01 +k2 2e-02 2e-02 3e-02 +g 5e-01 5e-01 5e-01 +a.1 9e-01 8e-01 1e+00 +b.1 5e-02 5e-02 6e-02 +SD.parent_0 3e-02 -5e+01 5e+01 +SD.k_m1 2e-01 1e-01 3e-01 +SD.f_parent_to_m1 3e-01 2e-01 4e-01 +SD.k1 4e-01 2e-01 5e-01 +SD.k2 3e-01 2e-01 5e-01 +SD.g 2e-01 6e-02 4e-01 + +Correlation: + pr_0 k_m1 f___ k1 k2 +k_m1 -0.2 +f_parent_to_m1 -0.3 0.1 +k1 0.1 0.0 0.0 +k2 0.0 0.0 0.0 0.1 +g 0.1 -0.1 0.0 -0.2 -0.2 + +Random effects: + est. lower upper +SD.parent_0 0.03 -49.24 49.3 +SD.k_m1 0.23 0.13 0.3 +SD.f_parent_to_m1 0.30 0.19 0.4 +SD.k1 0.40 0.25 0.5 +SD.k2 0.34 0.21 0.5 +SD.g 0.21 0.06 0.4 + +Variance model: + est. lower upper +a.1 0.93 0.79 1.06 +b.1 0.05 0.05 0.06 + +Resulting formation fractions: + ff +parent_m1 0.5 +parent_sink 0.5 + +Estimated disappearance times: + DT50 DT90 DT50back DT50_k1 DT50_k2 +parent 13 73 22 6 32 +m1 105 348 NA NA NA diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 2d53c6dd..ab8dfc27 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -1,22 +1,23 @@ context("Nonlinear mixed-effects models") + # Round error model parameters as they are not rounded in print methods dfop_nlme_1$modelStruct$varStruct$const <- signif(dfop_nlme_1$modelStruct$varStruct$const, 3) dfop_nlme_1$modelStruct$varStruct$prop <- signif(dfop_nlme_1$modelStruct$varStruct$prop, 4) +dfop_sfo_pop <- attr(ds_dfop_sfo, "pop") + test_that("Print methods work", { expect_known_output(print(fits[, 2:3], digits = 2), "print_mmkin_parent.txt") expect_known_output(print(mixed(mmkin_sfo_1), digits = 2), "print_mmkin_sfo_1_mixed.txt") expect_known_output(print(dfop_nlme_1, digits = 1), "print_dfop_nlme_1.txt") + expect_known_output(print(sfo_saem_1_reduced, digits = 1), "print_sfo_saem_1_reduced.txt") - # In order to address the platform dependence of the results, we round to two - # significant digits before printing - dfop_saemix_1_print <- dfop_saemix_1 - dfop_saemix_1_print$so@results@conf.int[c("estimate", "lower", "upper")] <- - signif(dfop_saemix_1_print$so@results@conf.int[c("estimate", "lower", "upper")], 2) - expect_known_output(print(dfop_saemix_1_print, digits = 1), "print_dfop_saemix_1.txt") + skip_on_cran() # The following test is platform dependent and fails on + # win-builder with current (18 Nov 2022) R-devel and on the Fedora CRAN check systems + expect_known_output(print(dfop_saem_1, digits = 1), "print_dfop_saem_1.txt") }) test_that("nlme results are reproducible to some degree", { @@ -36,17 +37,16 @@ test_that("nlme results are reproducible to some degree", { # k1 and k2 just fail the first test (lower bound of the ci), so we need to exclude it dfop_no_k1_k2 <- c("parent_0", "k_m1", "f_parent_to_m1", "g") dfop_sfo_pop_no_k1_k2 <- as.numeric(dfop_sfo_pop[dfop_no_k1_k2]) - dfop_sfo_pop <- as.numeric(dfop_sfo_pop) # to remove names - ci_dfop_sfo_n <- summary(nlme_biphasic)$confint_back + ci_dfop_sfo_n <- summary(nlme_dfop_sfo)$confint_back expect_true(all(ci_dfop_sfo_n[dfop_no_k1_k2, "lower"] < dfop_sfo_pop_no_k1_k2)) - expect_true(all(ci_dfop_sfo_n[, "upper"] > dfop_sfo_pop)) + expect_true(all(ci_dfop_sfo_n[, "upper"] > as.numeric(dfop_sfo_pop))) }) test_that("saemix results are reproducible for biphasic fits", { - test_summary <- summary(saem_biphasic_s) + test_summary <- summary(saem_dfop_sfo_s) test_summary$saemixversion <- "Dummy 0.0 for testing" test_summary$mkinversion <- "Dummy 0.0 for testing" test_summary$Rversion <- "Dummy R version for testing" @@ -54,33 +54,33 @@ test_that("saemix results are reproducible for biphasic fits", { test_summary$date.summary <- "Dummy date for testing" test_summary$time <- c(elapsed = "test time 0") - expect_known_output(print(test_summary, digits = 1), "summary_saem_biphasic_s.txt") + expect_known_output(print(test_summary, digits = 1), "summary_saem_dfop_sfo_s.txt") dfop_sfo_pop <- as.numeric(dfop_sfo_pop) no_k1 <- c(1, 2, 3, 5, 6) no_k2 <- c(1, 2, 3, 4, 6) no_k1_k2 <- c(1, 2, 3, 6) - ci_dfop_sfo_s_s <- summary(saem_biphasic_s)$confint_back + ci_dfop_sfo_s_s <- summary(saem_dfop_sfo_s)$confint_back expect_true(all(ci_dfop_sfo_s_s[, "lower"] < dfop_sfo_pop)) expect_true(all(ci_dfop_sfo_s_s[, "upper"] > dfop_sfo_pop)) # k2 is not fitted well - ci_dfop_sfo_s_m <- summary(saem_biphasic_m)$confint_back + ci_dfop_sfo_s_m <- summary(saem_dfop_sfo_m)$confint_back expect_true(all(ci_dfop_sfo_s_m[no_k2, "lower"] < dfop_sfo_pop[no_k2])) expect_true(all(ci_dfop_sfo_s_m[no_k1, "upper"] > dfop_sfo_pop[no_k1])) # I tried to only do few iterations in routine tests as this is so slow # but then deSolve fails at some point (presumably at the switch between # the two types of iterations) - #saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve", + #saem_dfop_sfo_2 <- saem(mmkin_biphasic, solution_type = "deSolve", # control = list(nbiter.saemix = c(10, 5), nbiter.burn = 5), quiet = TRUE) skip("Fitting with saemix takes around 10 minutes when using deSolve") - saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve", quiet = TRUE) + saem_dfop_sfo_2 <- saem(mmkin_dfop_sfo, solution_type = "deSolve", quiet = TRUE) # As with the analytical solution, k1 and k2 are not fitted well - ci_dfop_sfo_s_d <- summary(saem_biphasic_2)$confint_back + ci_dfop_sfo_s_d <- summary(saem_dfop_sfo_2)$confint_back expect_true(all(ci_dfop_sfo_s_d[no_k2, "lower"] < dfop_sfo_pop[no_k2])) expect_true(all(ci_dfop_sfo_s_d[no_k1, "upper"] > dfop_sfo_pop[no_k1])) }) diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 502cee98..3a511e06 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -9,26 +9,22 @@ test_that("multistart works for saem.mmkin models", { best(saem_sfo_s_multi), test = TRUE ) - # On winbuilder, sfo_saem_1 gives an AIC of 1310.8, while we get 1311.7 - # locally (using saemix 3.2, which likely makes the difference due to the - # error parameter patch) on Linux and Windows. The other, well-determined - # fits both give 1309.7. - expect_equal(round(anova_sfo, 1)["sfo_saem_1_reduced", "AIC"], 1309.7) - expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1309.7) - expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, CRAN: 0.4 + expect_equal(round(anova_sfo, 1)["sfo_saem_1_reduced", "AIC"], 1302.2) + expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1302.2) + expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, win-builder: 0.4 set.seed(123456) - saem_biphasic_m_multi <- multistart(saem_biphasic_m, n = 8, + saem_dfop_sfo_m_multi <- multistart(saem_dfop_sfo_m, n = 8, cores = n_cores) - expect_known_output(print(saem_biphasic_m_multi), - file = "print_multistart_biphasic.txt") + expect_known_output(print(saem_dfop_sfo_m_multi), + file = "print_multistart_dfop_sfo.txt") - anova_biphasic <- anova(saem_biphasic_m, - best(saem_biphasic_m_multi)) + anova_dfop_sfo <- anova(saem_dfop_sfo_m, + best(saem_dfop_sfo_m_multi)) # With the new starting parameters we do not improve # with multistart any more - expect_equal(anova_biphasic[2, "AIC"], anova_biphasic[1, "AIC"], + expect_equal(anova_dfop_sfo[2, "AIC"], anova_dfop_sfo[1, "AIC"], tolerance = 1e-4) skip_on_travis() # Plots are platform dependent @@ -37,10 +33,10 @@ test_that("multistart works for saem.mmkin models", { vdiffr::expect_doppelganger("llhist for sfo fit", llhist_sfo) vdiffr::expect_doppelganger("parplot for sfo fit", parplot_sfo) - llhist_biphasic <- function() llhist(saem_biphasic_m_multi) - parplot_biphasic <- function() parplot(saem_biphasic_m_multi, + llhist_dfop_sfo <- function() llhist(saem_dfop_sfo_m_multi) + parplot_dfop_sfo <- function() parplot(saem_dfop_sfo_m_multi, ylim = c(0.5, 2)) - vdiffr::expect_doppelganger("llhist for biphasic saemix fit", llhist_biphasic) - vdiffr::expect_doppelganger("parplot for biphasic saemix fit", parplot_biphasic) + vdiffr::expect_doppelganger("llhist for dfop sfo fit", llhist_dfop_sfo) + vdiffr::expect_doppelganger("parplot for dfop sfo fit", parplot_dfop_sfo) }) diff --git a/tests/testthat/test_plot.R b/tests/testthat/test_plot.R index 13058c00..01b0c1ee 100644 --- a/tests/testthat/test_plot.R +++ b/tests/testthat/test_plot.R @@ -44,24 +44,24 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", { f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix") - plot_biphasic_mmkin <- function() plot(f_uba_dfop_sfo_mixed, pop_curve = TRUE) - vdiffr::expect_doppelganger("mixed model fit for mmkin object", plot_biphasic_mmkin) + plot_dfop_sfo_mmkin <- function() plot(f_uba_dfop_sfo_mixed, pop_curve = TRUE) + vdiffr::expect_doppelganger("mixed model fit for mmkin object", plot_dfop_sfo_mmkin) - plot_biphasic_saem_s <- function() plot(f_uba_dfop_sfo_saem) - vdiffr::expect_doppelganger("mixed model fit for saem object with saemix transformations", plot_biphasic_saem_s) + plot_dfop_sfo_saem_s <- function() plot(f_uba_dfop_sfo_saem) + vdiffr::expect_doppelganger("mixed model fit for saem object with saemix transformations", plot_dfop_sfo_saem_s) skip_on_travis() - plot_biphasic_nlme <- function() plot(dfop_nlme_1) - vdiffr::expect_doppelganger("mixed model fit for nlme object", plot_biphasic_nlme) + plot_dfop_sfo_nlme <- function() plot(dfop_nlme_1) + vdiffr::expect_doppelganger("mixed model fit for nlme object", plot_dfop_sfo_nlme) - #plot_biphasic_mmkin <- function() plot(mixed(mmkin_biphasic)) + #plot_dfop_sfo_mmkin <- function() plot(mixed(mmkin_dfop_sfo)) # Biphasic fits with lots of data and fits have lots of potential for differences - plot_biphasic_nlme <- function() plot(nlme_biphasic) - #plot_biphasic_saem_s <- function() plot(saem_biphasic_s) - plot_biphasic_saem_m <- function() plot(saem_biphasic_m) + plot_dfop_sfo_nlme <- function() plot(nlme_dfop_sfo) + #plot_dfop_sfo_saem_s <- function() plot(saem_dfop_sfo_s) + plot_dfop_sfo_saem_m <- function() plot(saem_dfop_sfo_m) - vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_biphasic_saem_m) + vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_dfop_sfo_saem_m) # different results when working with eigenvalues plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE) diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index 20889c6c..31605931 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -38,11 +38,11 @@ test_that("Parent fits using saemix are correctly implemented", { s_sfo_nlme_1 <- summary(sfo_nlme_1) # Compare with input - expect_equal(round(s_sfo_saem_1$confint_ranef["SD.k_parent", "est."], 1), 0.3) - expect_equal(round(s_sfo_saem_1_mkin$confint_ranef["SD.log_k_parent", "est."], 1), 0.3) + expect_equal(round(s_sfo_saem_1$confint_ranef["SD.k_parent", "est."], 1), 0.3, tol = 0.1) + expect_equal(round(s_sfo_saem_1_mkin$confint_ranef["SD.log_k_parent", "est."], 1), 0.3, tol = 0.1) # k_parent is a bit different from input 0.03 here - expect_equal(round(s_sfo_saem_1$confint_back["k_parent", "est."], 3), 0.035) - expect_equal(round(s_sfo_saem_1_mkin$confint_back["k_parent", "est."], 3), 0.035) + expect_equal(round(s_sfo_saem_1$confint_back["k_parent", "est."], 3), 0.033) + expect_equal(round(s_sfo_saem_1_mkin$confint_back["k_parent", "est."], 3), 0.033) # But the result is pretty unanimous between methods expect_equal(round(s_sfo_saem_1_reduced$confint_back["k_parent", "est."], 3), @@ -74,7 +74,7 @@ test_that("Parent fits using saemix are correctly implemented", { mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc", cores = n_cores) fomc_saem_1 <- saem(mmkin_fomc_1, quiet = TRUE, transformations = "saemix", no_random_effect = "parent_0") - fomc_pop <- as.numeric(fomc_pop) + fomc_pop <- as.numeric(attr(ds_fomc, "pop")) ci_fomc_s1 <- summary(fomc_saem_1)$confint_back expect_true(all(ci_fomc_s1[, "lower"] < fomc_pop)) expect_true(all(ci_fomc_s1[, "upper"] > fomc_pop)) @@ -87,14 +87,14 @@ test_that("Parent fits using saemix are correctly implemented", { expect_equal(endpoints(fomc_saem_1), endpoints(fomc_saem_2), tol = 0.01) # DFOP - dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix", + dfop_saem_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix", no_random_effect = "parent_0") - s_dfop_s1 <- summary(dfop_saemix_1) # mkin transformations - s_dfop_s2 <- summary(dfop_saemix_2) # saemix transformations + s_dfop_s1 <- summary(dfop_saem_1) # mkin transformations + s_dfop_s2 <- summary(dfop_saem_2) # saemix transformations s_dfop_n <- summary(dfop_nlme_1) - dfop_pop <- as.numeric(dfop_pop) + dfop_pop <- as.numeric(attr(ds_dfop, "pop")) expect_true(all(s_dfop_s1$confint_back[, "lower"] < dfop_pop)) expect_true(all(s_dfop_s1$confint_back[, "upper"] > dfop_pop)) @@ -111,18 +111,18 @@ test_that("Parent fits using saemix are correctly implemented", { # SFORB mmkin_sforb_1 <- mmkin("SFORB", ds_dfop, quiet = TRUE, cores = n_cores) - sforb_saemix_1 <- saem(mmkin_sforb_1, quiet = TRUE, + sforb_saem_1 <- saem(mmkin_sforb_1, quiet = TRUE, no_random_effect = c("parent_free_0"), transformations = "mkin") - sforb_saemix_2 <- saem(mmkin_sforb_1, quiet = TRUE, + sforb_saem_2 <- saem(mmkin_sforb_1, quiet = TRUE, no_random_effect = c("parent_free_0"), transformations = "saemix") expect_equal( - log(endpoints(dfop_saemix_1)$distimes[1:2]), - log(endpoints(sforb_saemix_1)$distimes[1:2]), tolerance = 0.01) + log(endpoints(dfop_saem_1)$distimes[1:2]), + log(endpoints(sforb_saem_1)$distimes[1:2]), tolerance = 0.01) expect_equal( - log(endpoints(sforb_saemix_1)$distimes[1:2]), - log(endpoints(sforb_saemix_2)$distimes[1:2]), tolerance = 0.01) + log(endpoints(sforb_saem_1)$distimes[1:2]), + log(endpoints(sforb_saem_2)$distimes[1:2]), tolerance = 0.01) mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const", cores = n_cores) hs_saem_1 <- saem(mmkin_hs_1, quiet = TRUE, no_random_effect = "parent_0") @@ -131,7 +131,7 @@ test_that("Parent fits using saemix are correctly implemented", { expect_equal(endpoints(hs_saem_1), endpoints(hs_saem_2), tol = 0.01) ci_hs_s1 <- summary(hs_saem_1)$confint_back - hs_pop <- as.numeric(hs_pop) + hs_pop <- as.numeric(attr(ds_hs, "pop")) #expect_true(all(ci_hs_s1[, "lower"] < hs_pop)) # k1 is overestimated expect_true(all(ci_hs_s1[, "upper"] > hs_pop)) }) @@ -141,10 +141,10 @@ test_that("We can also use mkin solution methods for saem", { "saemix transformations is only supported if an analytical solution is implemented" ) skip("This still takes almost 2.5 minutes although we do not solve ODEs") - dfop_saemix_3 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", - solution_type = "analytical", no_random_effect = "parent_0") - distimes_dfop <- endpoints(dfop_saemix_1)$distimes - distimes_dfop_analytical <- endpoints(dfop_saemix_3)$distimes + dfop_saem_3 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", + solution_type = "analytical", no_random_effect = c("parent_0", "g_qlogis")) + distimes_dfop <- endpoints(dfop_saem_1)$distimes + distimes_dfop_analytical <- endpoints(dfop_saem_3)$distimes rel_diff <- abs(distimes_dfop_analytical - distimes_dfop) / distimes_dfop expect_true(all(rel_diff < 0.01)) }) -- cgit v1.2.3 From b6b7e387261e5483f1bdfafaaa975e2f24c6567c Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 20:35:06 +0100 Subject: Use cluster with two cores to reduce windows check time --- NEWS.md | 2 ++ docs/news/index.html | 3 ++- docs/pkgdown.yml | 2 +- log/test.log | 37 +++++++++++++++++++------------------ tests/testthat/setup_script.R | 22 +++++++++++++++------- tests/testthat/test_saemix_parent.R | 2 +- 6 files changed, 40 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/NEWS.md b/NEWS.md index 245a3973..c4c3ddee 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # mkin 1.2.1 (unreleased) +- '{data,R}/ds_mixed.rda': Include the test data in the package instead of generating it in 'tests/testthat/setup_script.R'. Refactor the generating code to make it consistent and update tests. + - 'tests/testthat/setup_script.R': Excluded another ill-defined random effect for the DFOP fit with 'saem', in an attempt to avoid a platform dependence that surfaced on Fedora systems on the CRAN check farm - 'tests/testthat/test_mixed.R': Round parameters found by saemix to two significant digits before printing, to also help to avoid platform dependence of tests diff --git a/docs/news/index.html b/docs/news/index.html index 6b9a7d51..f6883766 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -89,7 +89,8 @@
-
  • ‘tests/testthat/setup_script.R’: Excluded another ill-defined random effect for the DFOP fit with ‘saem’, in an attempt to avoid a platform dependence that surfaced on Fedora systems on the CRAN check farm

  • +
    • ‘{data,R}/ds_mixed.rda’: Include the test data in the package instead of generating it in ‘tests/testthat/setup_script.R’. Refactor the generating code to make it consistent and update tests.

    • +
    • ‘tests/testthat/setup_script.R’: Excluded another ill-defined random effect for the DFOP fit with ‘saem’, in an attempt to avoid a platform dependence that surfaced on Fedora systems on the CRAN check farm

    • ‘tests/testthat/test_mixed.R’: Round parameters found by saemix to two significant digits before printing, to also help to avoid platform dependence of tests

    • ‘R/saem.R’: Fix a bug that prevented that ‘error.ini’ is passed to ‘saemix_model’, and set default to c(1, 1) to avoid changing test results

    • ‘R/parplot.R’: Show initial values for error model parameters

    • diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index b6c8f1cc..7cf87069 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -13,7 +13,7 @@ articles: dimethenamid_2018: web_only/dimethenamid_2018.html multistart: web_only/multistart.html saem_benchmarks: web_only/saem_benchmarks.html -last_built: 2022-11-18T18:18Z +last_built: 2022-11-18T18:28Z urls: reference: https://pkgdown.jrwb.de/mkin/reference article: https://pkgdown.jrwb.de/mkin/articles diff --git a/log/test.log b/log/test.log index d1de270e..8fdaec48 100644 --- a/log/test.log +++ b/log/test.log @@ -1,53 +1,53 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.3s] +✔ | 5 | Analytical solutions for coupled models [3.4s] ✔ | 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.6s] +✔ | 12 | Confidence intervals and p-values [1.2s] +✔ | 1 12 | Dimethenamid data from 2018 [34.0s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.1s] +✔ | 14 | Error model fitting [5.4s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] -✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.8s] +✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.9s] ✔ | 4 | Test fitting the decline of metabolites from their maximum [0.4s] -✔ | 1 | Fitting the logistic model [0.2s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.6s] +✔ | 1 | Fitting the logistic model [0.3s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [25.8s] ✔ | 1 13 | Nonlinear mixed-effects models [0.4s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:79'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.5s] +✔ | 10 | Special cases of mkinfit calls [0.6s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] ✔ | 3 | Model predictions with mkinpredict [0.4s] -✔ | 9 | Multistart method for saem.mmkin models [37.3s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.5s] +✔ | 9 | Multistart method for saem.mmkin models [38.2s] +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.4s] ✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] -✔ | 16 | Plotting [10.1s] +✔ | 16 | Plotting [10.5s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [71.4s] +✔ | 1 36 | saemix parent models [75.0s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.4s] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.6s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.9s] +✔ | 10 | Fitting the SFORB model [4.0s] ✔ | 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.3s] -✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.5s] +✔ | 9 | Hypothesis tests [9.0s] +✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.3s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 220.0 s +Duration: 229.5 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) @@ -55,3 +55,4 @@ Duration: 220.0 s • This still takes almost 2.5 minutes although we do not solve ODEs (1) [ FAIL 0 | WARN 0 | SKIP 3 | PASS 270 ] +Error while shutting down parallel: unable to terminate some child processes diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index c554800d..2448886d 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -2,17 +2,23 @@ require(mkin) require(testthat) # Per default (on my box where I set NOT_CRAN in .Rprofile) use all cores minus one +# Otherwise (CRAN check systems) use the allowed maximum of two cores if (identical(Sys.getenv("NOT_CRAN"), "true")) { n_cores <- parallel::detectCores() - 1 } else { - n_cores <- 1 + n_cores <- 2 } # Use the two available cores on travis if (Sys.getenv("TRAVIS") != "") n_cores = 2 -# On Windows we would need to make a cluster first -if (Sys.info()["sysname"] == "Windows") n_cores = 1 +# On Windows we need to make a cluster, or use one core +if (Sys.info()["sysname"] == "Windows") { + cl <- parallel::makePSOCKcluster(n_cores) + n_cores = 1 +} else { + cl <- parallel::makeForkCluster(n_cores) +} # Very simple example fits f_1_mkin_trans <- mkinfit("SFO", FOCUS_2006_A, quiet = TRUE) @@ -24,7 +30,7 @@ models <- c("SFO", "FOMC", "DFOP", "HS") fits <- suppressWarnings( # FOCUS A FOMC was, it seems, in testthat output mmkin(models, list(FOCUS_A = FOCUS_2006_A, FOCUS_C = FOCUS_2006_C, FOCUS_D = FOCUS_2006_D), - quiet = TRUE, cores = n_cores)) + quiet = TRUE, cluster = cl)) # One metabolite SFO_SFO <- mkinmod(parent = mkinsub("SFO", to = "m1"), @@ -82,13 +88,14 @@ fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE error_model_algorithm = "threestep") # Mixed model fits -mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = n_cores) -mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE, cores = n_cores, +mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cluster = cl) +mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE, cluster = cl, error_model = "tc") DFOP_SFO <- mkinmod(parent = mkinsub("DFOP", "m1"), m1 = mkinsub("SFO"), quiet = TRUE) -mmkin_dfop_sfo <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_dfop_sfo, quiet = TRUE, cores = n_cores, +mmkin_dfop_sfo <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_dfop_sfo, quiet = TRUE, + cluster = cl, control = list(eval.max = 500, iter.max = 400), error_model = "tc") @@ -105,3 +112,4 @@ dfop_saem_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", saem_dfop_sfo_m <- saem(mmkin_dfop_sfo, transformations = "mkin", quiet = TRUE) saem_dfop_sfo_s <- saem(mmkin_dfop_sfo, transformations = "saemix", quiet = TRUE) +parallel::stopCluster(cl) diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index 31605931..7fbecd0c 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -15,7 +15,7 @@ test_that("Parent fits using saemix are correctly implemented", { expect_silent(print(illparms(sfo_saem_1_reduced))) # We cannot currently do the fit with completely fixed initial values - mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100)) + mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100), cluster = NULL, cores = n_cores) sfo_saem_3 <- expect_error(saem(mmkin_sfo_2, quiet = TRUE), "at least two parameters") # We get an error if we do not supply a suitable model specification -- cgit v1.2.3 From 5ec8e1bad1aa7d79ee9c19bdd50be07f81a14278 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 22:11:02 +0100 Subject: Move two saem fits from setup script to skipped tests Save winbuilder/CRAN check time... --- log/test.log | 44 +- ...t-for-saem-object-with-mkin-transformations.svg | 2502 ++++++++++++++++++++ ...t-for-saem-object-with-mkin-transformations.svg | 2502 -------------------- tests/testthat/setup_script.R | 3 - tests/testthat/test_mixed.R | 8 +- tests/testthat/test_multistart.R | 15 + tests/testthat/test_plot.R | 4 - 7 files changed, 2542 insertions(+), 2536 deletions(-) create mode 100644 tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg delete mode 100644 tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg (limited to 'tests') diff --git a/log/test.log b/log/test.log index 8fdaec48..897bf896 100644 --- a/log/test.log +++ b/log/test.log @@ -1,53 +1,53 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.4s] +✔ | 5 | Analytical solutions for coupled models [3.5s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE ✔ | 12 | Confidence intervals and p-values [1.2s] -✔ | 1 12 | Dimethenamid data from 2018 [34.0s] +✔ | 1 12 | Dimethenamid data from 2018 [33.2s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.4s] +✔ | 14 | Error model fitting [5.0s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] -✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.9s] -✔ | 4 | Test fitting the decline of metabolites from their maximum [0.4s] -✔ | 1 | Fitting the logistic model [0.3s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [25.8s] -✔ | 1 13 | Nonlinear mixed-effects models [0.4s] +✔ | 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] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.7s] +✔ | 1 11 | Nonlinear mixed-effects models [13.1s] ──────────────────────────────────────────────────────────────────────────────── -Skip ('test_mixed.R:79'): saemix results are reproducible for biphasic fits +Skip ('test_mixed.R:77'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.6s] +✔ | 10 | Special cases of mkinfit calls [0.4s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] -✔ | 3 | Model predictions with mkinpredict [0.4s] -✔ | 9 | Multistart method for saem.mmkin models [38.2s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.4s] -✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] -✔ | 16 | Plotting [10.5s] +✔ | 3 | Model predictions with mkinpredict [0.3s] +✔ | 12 | Multistart method for saem.mmkin models [49.5s] +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.3s] +✔ | 9 | Nonlinear mixed-effects models with nlme [8.8s] +✔ | 15 | Plotting [10.3s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [75.0s] +✔ | 1 36 | saemix parent models [72.5s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.6s] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [4.0s] +✔ | 10 | Fitting the SFORB model [3.8s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.5s] -✔ | 9 | Hypothesis tests [9.0s] -✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.3s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] +✔ | 9 | Hypothesis tests [8.2s] +✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 229.5 s +Duration: 246.1 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) diff --git a/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg b/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg new file mode 100644 index 00000000..69fa6a4d --- /dev/null +++ b/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg @@ -0,0 +1,2502 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Population +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + + + +Time +Residues parent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + + + +-3 +-2 +-1 +0 +1 +2 +3 + + + + + + + + +Predicted +Standardized residual + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + +0 +10 +20 +30 +40 + + + + + + + + +Time +Residues m1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +10 +20 +30 +40 + + + + + + + + +-3 +-2 +-1 +0 +1 +2 +3 + + + + + + + + +Predicted +Standardized residual + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg b/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg deleted file mode 100644 index 69fa6a4d..00000000 --- a/tests/testthat/_snaps/plot/mixed-model-fit-for-saem-object-with-mkin-transformations.svg +++ /dev/null @@ -1,2502 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Population -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 - - - - - - - - - - - - - - - - - -0 -20 -40 -60 -80 -100 -120 - - - - - - - -0 -20 -40 -60 -80 -100 - - - - - - - - -Time -Residues parent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -20 -40 -60 -80 -100 - - - - - - - - --3 --2 --1 -0 -1 -2 -3 - - - - - - - - -Predicted -Standardized residual - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -20 -40 -60 -80 -100 -120 - - - - - - -0 -10 -20 -30 -40 - - - - - - - - -Time -Residues m1 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -0 -10 -20 -30 -40 - - - - - - - - --3 --2 --1 -0 -1 -2 -3 - - - - - - - - -Predicted -Standardized residual - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index 2448886d..4e2f76ab 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -109,7 +109,4 @@ sfo_saem_1_reduced <- update(sfo_saem_1, no_random_effect = "parent_0") dfop_saem_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", no_random_effect = c("parent_0", "g_qlogis")) -saem_dfop_sfo_m <- saem(mmkin_dfop_sfo, transformations = "mkin", quiet = TRUE) -saem_dfop_sfo_s <- saem(mmkin_dfop_sfo, transformations = "saemix", quiet = TRUE) - parallel::stopCluster(cl) diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index ab8dfc27..8c257738 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -46,6 +46,9 @@ test_that("nlme results are reproducible to some degree", { test_that("saemix results are reproducible for biphasic fits", { + skip_on_cran() + saem_dfop_sfo_s <- saem(mmkin_dfop_sfo, transformations = "saemix", quiet = TRUE) + test_summary <- summary(saem_dfop_sfo_s) test_summary$saemixversion <- "Dummy 0.0 for testing" test_summary$mkinversion <- "Dummy 0.0 for testing" @@ -65,11 +68,6 @@ test_that("saemix results are reproducible for biphasic fits", { expect_true(all(ci_dfop_sfo_s_s[, "lower"] < dfop_sfo_pop)) expect_true(all(ci_dfop_sfo_s_s[, "upper"] > dfop_sfo_pop)) - # k2 is not fitted well - ci_dfop_sfo_s_m <- summary(saem_dfop_sfo_m)$confint_back - expect_true(all(ci_dfop_sfo_s_m[no_k2, "lower"] < dfop_sfo_pop[no_k2])) - expect_true(all(ci_dfop_sfo_s_m[no_k1, "upper"] > dfop_sfo_pop[no_k1])) - # I tried to only do few iterations in routine tests as this is so slow # but then deSolve fails at some point (presumably at the switch between # the two types of iterations) diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 3a511e06..91ef71f0 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -4,6 +4,7 @@ test_that("multistart works for saem.mmkin models", { skip_on_cran() # Save CRAN time set.seed(123456) saem_sfo_s_multi <- multistart(sfo_saem_1_reduced, n = 8, cores = n_cores) + anova_sfo <- anova(sfo_saem_1, sfo_saem_1_reduced, best(saem_sfo_s_multi), @@ -13,6 +14,17 @@ test_that("multistart works for saem.mmkin models", { expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1302.2) expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, win-builder: 0.4 + saem_dfop_sfo_m <- saem(mmkin_dfop_sfo, transformations = "mkin", quiet = TRUE) + dfop_sfo_pop <- attr(ds_dfop_sfo, "pop") + + # k2 is not fitted well (compare saem_dfop_sfo_s in test_mixed.R) + ci_dfop_sfo_s_m <- summary(saem_dfop_sfo_m)$confint_back + no_k1 <- c(1, 2, 3, 5, 6) + no_k2 <- c(1, 2, 3, 4, 6) + expect_true(all(ci_dfop_sfo_s_m[no_k2, "lower"] < dfop_sfo_pop[no_k2])) + expect_true(all(ci_dfop_sfo_s_m[no_k1, "upper"] > dfop_sfo_pop[no_k1])) + + set.seed(123456) saem_dfop_sfo_m_multi <- multistart(saem_dfop_sfo_m, n = 8, cores = n_cores) @@ -28,6 +40,9 @@ test_that("multistart works for saem.mmkin models", { tolerance = 1e-4) skip_on_travis() # Plots are platform dependent + plot_dfop_sfo_saem_m <- function() plot(saem_dfop_sfo_m) + vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_dfop_sfo_saem_m) + llhist_sfo <- function() llhist(saem_sfo_s_multi) parplot_sfo <- function() parplot(saem_sfo_s_multi, ylim = c(0.5, 2)) vdiffr::expect_doppelganger("llhist for sfo fit", llhist_sfo) diff --git a/tests/testthat/test_plot.R b/tests/testthat/test_plot.R index 01b0c1ee..f5da5982 100644 --- a/tests/testthat/test_plot.R +++ b/tests/testthat/test_plot.R @@ -41,7 +41,6 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", { f_uba_mmkin <- mmkin(list("DFOP-SFO" = dfop_sfo_uba), ds_uba, quiet = TRUE, cores = n_cores) f_uba_dfop_sfo_mixed <- mixed(f_uba_mmkin["DFOP-SFO", ]) - f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix") plot_dfop_sfo_mmkin <- function() plot(f_uba_dfop_sfo_mixed, pop_curve = TRUE) @@ -59,9 +58,6 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", { # Biphasic fits with lots of data and fits have lots of potential for differences plot_dfop_sfo_nlme <- function() plot(nlme_dfop_sfo) #plot_dfop_sfo_saem_s <- function() plot(saem_dfop_sfo_s) - plot_dfop_sfo_saem_m <- function() plot(saem_dfop_sfo_m) - - vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_dfop_sfo_saem_m) # different results when working with eigenvalues plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE) -- cgit v1.2.3 From 64e245a16ec22cf864fcb5bae3b4b2fb2eee5905 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 19 Nov 2022 00:17:33 +0100 Subject: Confirm which test fail on R-devel --- log/test.log | 32 ++++++------- log/test_dev.log | 114 ++++++++++++++++++++++++++++++++++++-------- tests/testthat/test_mixed.R | 3 +- 3 files changed, 112 insertions(+), 37 deletions(-) (limited to 'tests') diff --git a/log/test.log b/log/test.log index 897bf896..0b9aa7eb 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.5s] +✔ | 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.2s] -✔ | 1 12 | Dimethenamid data from 2018 [33.2s] +✔ | 12 | Confidence intervals and p-values [1.1s] +✔ | 1 12 | Dimethenamid data from 2018 [33.3s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system @@ -14,40 +14,40 @@ Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.7s] -✔ | 1 11 | Nonlinear mixed-effects models [13.1s] +✔ | 4 | Test fitting the decline of metabolites from their maximum [0.4s] +✔ | 1 | Fitting the logistic model [0.3s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [25.5s] +✔ | 1 11 | Nonlinear mixed-effects models [13.2s] ──────────────────────────────────────────────────────────────────────────────── -Skip ('test_mixed.R:77'): saemix results are reproducible for biphasic fits +Skip ('test_mixed.R:78'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.4s] +✔ | 10 | Special cases of mkinfit calls [0.5s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] ✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 12 | Multistart method for saem.mmkin models [49.5s] +✔ | 12 | Multistart method for saem.mmkin models [51.1s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.3s] -✔ | 9 | Nonlinear mixed-effects models with nlme [8.8s] +✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] ✔ | 15 | Plotting [10.3s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [72.5s] +✔ | 1 36 | saemix parent models [73.7s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.4s] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.5s] ✔ | 11 | Processing of residue series ✔ | 10 | Fitting the SFORB model [3.8s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] -✔ | 9 | Hypothesis tests [8.2s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.4s] +✔ | 9 | Hypothesis tests [8.8s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 246.1 s +Duration: 251.2 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) diff --git a/log/test_dev.log b/log/test_dev.log index 527d28ed..1612e32d 100644 --- a/log/test_dev.log +++ b/log/test_dev.log @@ -1,57 +1,131 @@ ℹ 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 [31.3s] +✔ | 12 | Confidence intervals and p-values [1.1s] +✔ | 1 12 | Dimethenamid data from 2018 [33.8s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.2s] +✔ | 14 | Error model fitting [5.7s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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] +✔ | 4 | Test fitting the decline of metabolites from their maximum [0.4s] ✔ | 1 | Fitting the logistic model [0.2s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [23.5s] -✔ | 1 12 | Nonlinear mixed-effects models [0.3s] +✖ | 1 9 | Batch fitting and diagnosing hierarchical kinetic models [25.5s] ──────────────────────────────────────────────────────────────────────────────── -Skip ('test_mixed.R:74'): saemix results are reproducible for biphasic fits +Failure ('test_mhmkin.R:55'): Multiple hierarchical kinetic models can be fitted and diagnosed +Results have changed from known value recorded in 'illparms_hfits_synth_no_ranef_auto.txt'. + + old | new +[1] " error" | " error" [1] +[2] "degradation const tc " | "degradation const tc " [2] +[3] " SFO sd(parent_0)" | " SFO sd(parent_0)" [3] +[4] " FOMC b.1 " - " FOMC " [4] +──────────────────────────────────────────────────────────────────────────────── +✖ | 1 1 10 | Nonlinear mixed-effects models [13.4s] +──────────────────────────────────────────────────────────────────────────────── +Failure ('test_mixed.R:20'): Print methods work +Results have changed from known value recorded in 'print_dfop_saem_1.txt'. + +old[13:23] vs new[13:23] + "" + "Fitted parameters:" + " estimate lower upper" +- "parent_0 99.92 98.77 101.06" ++ "parent_0 99.96 98.82 101.11" +- "log_k1 -2.72 -2.95 -2.50" ++ "log_k1 -2.71 -2.94 -2.49" +- "log_k2 -4.14 -4.27 -4.01" ++ "log_k2 -4.14 -4.26 -4.01" +- "g_qlogis -0.35 -0.53 -0.16" ++ "g_qlogis -0.36 -0.54 -0.17" +- "a.1 0.92 0.68 1.16" ++ "a.1 0.93 0.69 1.17" + "b.1 0.05 0.04 0.06" + "SD.log_k1 0.37 0.23 0.51" +and 1 more ... + +Skip ('test_mixed.R:77'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg ✔ | 10 | Special cases of mkinfit calls [0.5s] -✔ | 3 | mkinfit features [0.7s] +✔ | 3 | mkinfit features [0.8s] ✔ | 8 | mkinmod model generation and printing [0.2s] ✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 9 | Multistart method for saem.mmkin models [35.2s] +✖ | 4 8 | Multistart method for saem.mmkin models [53.5s] +──────────────────────────────────────────────────────────────────────────────── +Failure ('test_multistart.R:44'): multistart works for saem.mmkin models +Snapshot of `testcase` to 'multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg' has changed +Run `testthat::snapshot_review('multistart/')` to review changes +Backtrace: + 1. vdiffr::expect_doppelganger(...) + at test_multistart.R:44:2 + 3. testthat::expect_snapshot_file(...) + +Failure ('test_multistart.R:49'): multistart works for saem.mmkin models +Snapshot of `testcase` to 'multistart/parplot-for-sfo-fit.svg' has changed +Run `testthat::snapshot_review('multistart/')` to review changes +Backtrace: + 1. vdiffr::expect_doppelganger("parplot for sfo fit", parplot_sfo) + at test_multistart.R:49:2 + 3. testthat::expect_snapshot_file(...) + +Failure ('test_multistart.R:55'): multistart works for saem.mmkin models +Snapshot of `testcase` to 'multistart/llhist-for-dfop-sfo-fit.svg' has changed +Run `testthat::snapshot_review('multistart/')` to review changes +Backtrace: + 1. vdiffr::expect_doppelganger("llhist for dfop sfo fit", llhist_dfop_sfo) + at test_multistart.R:55:2 + 3. testthat::expect_snapshot_file(...) + +Failure ('test_multistart.R:56'): multistart works for saem.mmkin models +Snapshot of `testcase` to 'multistart/parplot-for-dfop-sfo-fit.svg' has changed +Run `testthat::snapshot_review('multistart/')` to review changes +Backtrace: + 1. vdiffr::expect_doppelganger("parplot for dfop sfo fit", parplot_dfop_sfo) + at test_multistart.R:56:2 + 3. testthat::expect_snapshot_file(...) +──────────────────────────────────────────────────────────────────────────────── ✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.5s] -✔ | 9 | Nonlinear mixed-effects models with nlme [8.3s] -✔ | 16 | Plotting [10.0s] +✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] +✖ | 1 14 | Plotting [10.5s] +──────────────────────────────────────────────────────────────────────────────── +Failure ('test_plot.R:55'): Plotting mkinfit, mmkin and mixed model objects is reproducible +Snapshot of `testcase` to 'plot/mixed-model-fit-for-nlme-object.svg' has changed +Run `testthat::snapshot_review('plot/')` to review changes +Backtrace: + 1. vdiffr::expect_doppelganger(...) + at test_plot.R:55:2 + 3. testthat::expect_snapshot_file(...) +──────────────────────────────────────────────────────────────────────────────── ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [63.3s] +✔ | 1 36 | saemix parent models [74.3s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.3s] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.5s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.5s] +✔ | 10 | Fitting the SFORB model [3.9s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.1s] -✔ | 9 | Hypothesis tests [7.5s] -✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.0s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.4s] +✔ | 9 | Hypothesis tests [8.8s] +✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.1s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 204.4 s +Duration: 256.2 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 269 ] +[ FAIL 7 | WARN 0 | SKIP 3 | PASS 263 ] +Error while shutting down parallel: unable to terminate some child processes diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 8c257738..39a332f5 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -16,7 +16,8 @@ test_that("Print methods work", { expect_known_output(print(sfo_saem_1_reduced, digits = 1), "print_sfo_saem_1_reduced.txt") skip_on_cran() # The following test is platform dependent and fails on - # win-builder with current (18 Nov 2022) R-devel and on the Fedora CRAN check systems + # win-builder with current (18 Nov 2022) R-devel, on the Linux R-devel CRAN check systems + # and also using R-devel locally expect_known_output(print(dfop_saem_1, digits = 1), "print_dfop_saem_1.txt") }) -- cgit v1.2.3 From aaa4cab7e0c7212f91147a9789af54b97fe342ca Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 29 Nov 2022 20:23:17 +0100 Subject: Complete starting values in summary for saem.mmkin fits Also update tests to the changes in mhmkin (see NEWS) --- NEWS.md | 4 ++- R/summary.saem.mmkin.R | 11 ++++++- log/build.log | 2 +- log/test.log | 34 +++++++++++----------- .../illparms_hfits_synth_no_ranef_auto.txt | 4 --- tests/testthat/print_hfits_synth_no_ranef_auto.txt | 9 ------ tests/testthat/summary_hfit_sfo_tc.txt | 11 ++++++- tests/testthat/summary_saem_dfop_sfo_s.txt | 15 +++++++++- tests/testthat/test_mhmkin.R | 10 ------- 9 files changed, 55 insertions(+), 45 deletions(-) delete mode 100644 tests/testthat/illparms_hfits_synth_no_ranef_auto.txt delete mode 100644 tests/testthat/print_hfits_synth_no_ranef_auto.txt (limited to 'tests') diff --git a/NEWS.md b/NEWS.md index f07c6983..35f499d5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # mkin 1.2.2 -- 'R/mhmkin.R': Allow an 'illparms.mhmkin' object as value of the argument 'no_random_effects', making it possible to exclude random effects that were ill-defined in simpler variants of the set of degradation models. +- 'R/mhmkin.R': Allow an 'illparms.mhmkin' object as value of the argument 'no_random_effects', making it possible to exclude random effects that were ill-defined in simpler variants of the set of degradation models. Remove the possibility to exclude random effects based on separate fits, as it did not work well. + +- 'R/summary.saem.mmkin.R': List all initial parameter values in the summary, including random effects and error model parameters # mkin 1.2.1 (2022-11-19) diff --git a/R/summary.saem.mmkin.R b/R/summary.saem.mmkin.R index 2754e9f0..7337b0f3 100644 --- a/R/summary.saem.mmkin.R +++ b/R/summary.saem.mmkin.R @@ -225,13 +225,22 @@ print.summary.saem.mmkin <- function(x, digits = max(3, getOption("digits") - 3) obs = "Variance unique to each observed variable", tc = "Two-component variance function"), "\n") - cat("\nMean of starting values for individual parameters:\n") + cat("\nStarting values for degradation parameters:\n") print(x$mean_dp_start, digits = digits) cat("\nFixed degradation parameter values:\n") if(length(x$fixed$value) == 0) cat("None\n") else print(x$fixed, digits = digits) + cat("\nStarting values for random effects (square root of initial entries in omega):\n") + print(sqrt(x$so@model@omega.init), digits = digits) + + cat("\nStarting values for error model parameters:\n") + errparms <- x$so@model@error.init + names(errparms) <- x$so@model@name.sigma + errparms <- errparms[x$so@model@indx.res] + print(errparms, digits = digits) + cat("\nResults:\n\n") cat("Likelihood computed by importance sampling\n") print(data.frame(AIC = x$AIC, BIC = x$BIC, logLik = x$logLik, diff --git a/log/build.log b/log/build.log index 6be01938..dbe0cd5b 100644 --- a/log/build.log +++ b/log/build.log @@ -5,5 +5,5 @@ * creating vignettes ... OK * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories -* building ‘mkin_1.2.1.tar.gz’ +* building ‘mkin_1.2.2.tar.gz’ diff --git a/log/test.log b/log/test.log index 0b9aa7eb..e17ecc1f 100644 --- a/log/test.log +++ b/log/test.log @@ -5,54 +5,54 @@ ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE ✔ | 12 | Confidence intervals and p-values [1.1s] -✔ | 1 12 | Dimethenamid data from 2018 [33.3s] +✔ | 1 12 | Dimethenamid data from 2018 [32.2s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.0s] +✔ | 14 | Error model fitting [4.9s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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.4s] -✔ | 1 | Fitting the logistic model [0.3s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [25.5s] -✔ | 1 11 | Nonlinear mixed-effects models [13.2s] +✔ | 4 | Test fitting the decline of metabolites from their maximum [0.3s] +✔ | 1 | Fitting the logistic model [0.2s] +✔ | 8 | Batch fitting and diagnosing hierarchical kinetic models [14.5s] +✔ | 1 11 | Nonlinear mixed-effects models [13.1s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:78'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.5s] +✔ | 10 | Special cases of mkinfit calls [0.4s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] ✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 12 | Multistart method for saem.mmkin models [51.1s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.3s] -✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] -✔ | 15 | Plotting [10.3s] +✔ | 12 | Multistart method for saem.mmkin models [50.1s] +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.2s] +✔ | 9 | Nonlinear mixed-effects models with nlme [8.7s] +✔ | 15 | Plotting [10.2s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [73.7s] +✔ | 1 36 | saemix parent models [103.8s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s] ✔ | 11 | Processing of residue series ✔ | 10 | Fitting the SFORB model [3.8s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.4s] -✔ | 9 | Hypothesis tests [8.8s] +✔ | 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: 251.2 s +Duration: 266.0 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 270 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 268 ] Error while shutting down parallel: unable to terminate some child processes diff --git a/tests/testthat/illparms_hfits_synth_no_ranef_auto.txt b/tests/testthat/illparms_hfits_synth_no_ranef_auto.txt deleted file mode 100644 index a64ed222..00000000 --- a/tests/testthat/illparms_hfits_synth_no_ranef_auto.txt +++ /dev/null @@ -1,4 +0,0 @@ - error -degradation const tc - SFO sd(parent_0) - FOMC b.1 diff --git a/tests/testthat/print_hfits_synth_no_ranef_auto.txt b/tests/testthat/print_hfits_synth_no_ranef_auto.txt deleted file mode 100644 index 9af1cbcd..00000000 --- a/tests/testthat/print_hfits_synth_no_ranef_auto.txt +++ /dev/null @@ -1,9 +0,0 @@ - object -Status of individual fits: - - error -degradation const tc - SFO OK OK - FOMC OK OK - -OK: Fit terminated successfully diff --git a/tests/testthat/summary_hfit_sfo_tc.txt b/tests/testthat/summary_hfit_sfo_tc.txt index bb5bf6fb..0a61f75f 100644 --- a/tests/testthat/summary_hfit_sfo_tc.txt +++ b/tests/testthat/summary_hfit_sfo_tc.txt @@ -17,13 +17,22 @@ Using 300, 100 iterations and 9 chains Variance model: Two-component variance function -Mean of starting values for individual parameters: +Starting values for degradation parameters: parent_0 log_k_parent 101 -3 Fixed degradation parameter values: None +Starting values for random effects (square root of initial entries in omega): + parent_0 log_k_parent +parent_0 4 0.0 +log_k_parent 0 0.4 + +Starting values for error model parameters: +a.1 b.1 + 1 1 + Results: Likelihood computed by importance sampling diff --git a/tests/testthat/summary_saem_dfop_sfo_s.txt b/tests/testthat/summary_saem_dfop_sfo_s.txt index 7c337843..6468ff17 100644 --- a/tests/testthat/summary_saem_dfop_sfo_s.txt +++ b/tests/testthat/summary_saem_dfop_sfo_s.txt @@ -22,7 +22,7 @@ Using 300, 100 iterations and 4 chains Variance model: Two-component variance function -Mean of starting values for individual parameters: +Starting values for degradation parameters: parent_0 k_m1 f_parent_to_m1 k1 k2 1e+02 7e-03 5e-01 1e-01 2e-02 g @@ -31,6 +31,19 @@ Mean of starting values for individual parameters: Fixed degradation parameter values: None +Starting values for random effects (square root of initial entries in omega): + parent_0 k_m1 f_parent_to_m1 k1 k2 g +parent_0 101 0 0 0 0 0 +k_m1 0 1 0 0 0 0 +f_parent_to_m1 0 0 1 0 0 0 +k1 0 0 0 1 0 0 +k2 0 0 0 0 1 0 +g 0 0 0 0 0 1 + +Starting values for error model parameters: +a.1 b.1 + 1 1 + Results: Likelihood computed by importance sampling diff --git a/tests/testthat/test_mhmkin.R b/tests/testthat/test_mhmkin.R index 93333ac1..e2339f28 100644 --- a/tests/testthat/test_mhmkin.R +++ b/tests/testthat/test_mhmkin.R @@ -46,14 +46,4 @@ test_that("Multiple hierarchical kinetic models can be fitted and diagnosed", { print(fits_synth_const), "print_fits_synth_const.txt") - hfits_no_ranef_auto <- update(hfits, no_random_effect = "auto", auto_ranef_threshold = 2) - - expect_known_output( - print(hfits_no_ranef_auto), - "print_hfits_synth_no_ranef_auto.txt") - - expect_known_output( - print(illparms(hfits_no_ranef_auto)), - "illparms_hfits_synth_no_ranef_auto.txt") - }) -- cgit v1.2.3 From 74e44dfed5af6e6fd421abe82d3e3f190771f85a Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 1 Dec 2022 11:20:00 +0100 Subject: Possibility to manually specify no_random_effects in mhmkin --- NEWS.md | 2 +- R/mhmkin.R | 91 ++++++++++++++++++++++++------- log/check.log | 8 +-- log/test.log | 48 ++++++++-------- man/mhmkin.Rd | 50 +++++++++++++++-- tests/testthat/illparms_hfits_synth.txt | 10 +--- tests/testthat/print_fits_synth_const.txt | 4 +- tests/testthat/summary_hfit_sfo_tc.txt | 34 ++++++------ tests/testthat/test_mhmkin.R | 34 ++++++++---- 9 files changed, 187 insertions(+), 94 deletions(-) (limited to 'tests') diff --git a/NEWS.md b/NEWS.md index 35f499d5..65df4191 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # mkin 1.2.2 -- 'R/mhmkin.R': Allow an 'illparms.mhmkin' object as value of the argument 'no_random_effects', making it possible to exclude random effects that were ill-defined in simpler variants of the set of degradation models. Remove the possibility to exclude random effects based on separate fits, as it did not work well. +- 'R/mhmkin.R': Allow an 'illparms.mhmkin' object or a list with suitable dimensions as value of the argument 'no_random_effects', making it possible to exclude random effects that were ill-defined in simpler variants of the set of degradation models. Remove the possibility to exclude random effects based on separate fits, as it did not work well. - 'R/summary.saem.mmkin.R': List all initial parameter values in the summary, including random effects and error model parameters diff --git a/R/mhmkin.R b/R/mhmkin.R index 6a61e8bb..a9798ff4 100644 --- a/R/mhmkin.R +++ b/R/mhmkin.R @@ -14,11 +14,12 @@ #' supported #' @param no_random_effect Default is NULL and will be passed to [saem]. If a #' character vector is supplied, it will be passed to all calls to [saem], -#' regardless if the corresponding parameter is in the model. Alternatively, -#' an object of class [illparms.mhmkin] can be specified. This has to have -#' the same dimensions as the return object of the current call. In this way, -#' ill-defined parameters found in corresponding simpler versions of the -#' degradation model can be specified. +#' which will exclude random effects for all matching parameters. Alternatively, +#' a list of character vectors or an object of class [illparms.mhmkin] can be +#' specified. They have to have the same dimensions that the return object of +#' the current call will have, i.e. the number of rows must match the number +#' of degradation models in the mmkin object(s), and the number of columns must +#' match the number of error models used in the mmkin object(s). #' @param algorithm The algorithm to be used for fitting (currently not used) #' @param \dots Further arguments that will be passed to the nonlinear mixed-effects #' model fitting function. @@ -50,6 +51,42 @@ mhmkin.mmkin <- function(objects, ...) { #' @export #' @rdname mhmkin +#' @examples +#' \dontrun{ +#' # We start with separate evaluations of all the first six datasets with two +#' # degradation models and two error models +#' f_sep_const <- mmkin(c("SFO", "FOMC"), ds_fomc[1:6], cores = 2, quiet = TRUE) +#' f_sep_tc <- update(f_sep_const, error_model = "tc") +#' # The mhmkin function sets up hierarchical degradation models aka +#' # nonlinear mixed-effects models for all four combinations, specifying +#' # uncorrelated random effects for all degradation parameters +#' f_saem_1 <- mhmkin(list(f_sep_const, f_sep_tc), cores = 2) +#' status(f_saem_1) +#' # The 'illparms' function shows that in all hierarchical fits, at least +#' # one random effect is ill-defined (the confidence interval for the +#' # random effect expressed as standard deviation includes zero) +#' illparms(f_saem_1) +#' # Therefore we repeat the fits, excluding the ill-defined random effects +#' f_saem_2 <- update(f_saem_1, no_random_effect = illparms(f_saem_1)) +#' status(f_saem_2) +#' illparms(f_saem_2) +#' # Model comparisons show that FOMC with two-component error is preferable, +#' # and confirms our reduction of the default parameter model +#' anova(f_saem_1) +#' anova(f_saem_2) +#' # The convergence plot for the selected model looks fine +#' saemix::plot(f_saem_2[["FOMC", "tc"]]$so, plot.type = "convergence") +#' # The plot of predictions versus data shows that we have a pretty data-rich +#' # situation with homogeneous distribution of residuals, because we used the +#' # same degradation model, error model and parameter distribution model that +#' # was used in the data generation. +#' plot(f_saem_2[["FOMC", "tc"]]) +#' # We can specify the same parameter model reductions manually +#' no_ranef <- list("parent_0", "log_beta", "parent_0", c("parent_0", "log_beta")) +#' dim(no_ranef) <- c(2, 2) +#' f_saem_2m <- update(f_saem_1, no_random_effect = no_ranef) +#' anova(f_saem_2m) +#' } mhmkin.list <- function(objects, backend = "saemix", algorithm = "saem", no_random_effect = NULL, ..., @@ -97,25 +134,38 @@ mhmkin.list <- function(objects, backend = "saemix", algorithm = "saem", dimnames(fit_indices) <- list(degradation = names(deg_models), error = error_models) - fit_function <- function(fit_index) { - w <- which(fit_indices == fit_index, arr.ind = TRUE) - deg_index <- w[1] - error_index <- w[2] - mmkin_row <- objects[[error_index]][deg_index, ] + if (is.null(no_random_effect) || length(dim(no_random_effect)) == 1) { + no_ranef <- rep(list(no_random_effect), n.fits) + dim(no_ranef) <- dim(fit_indices) + } else { + if (!identical(dim(no_random_effect), dim(fit_indices))) { + stop("Dimensions of argument 'no_random_effect' are not suitable") + } if (is(no_random_effect, "illparms.mhmkin")) { - if (identical(dim(no_random_effect), dim(fit_indices))) { - no_ranef_split <- strsplit(no_random_effect[[fit_index]], ", ") - no_ranef <- sapply(no_ranef_split, function(x) { - gsub("sd\\((.*)\\)", "\\1", x) + no_ranef_dim <- dim(no_random_effect) + no_ranef <- lapply(no_random_effect, function(x) { + no_ranef_split <- strsplit(x, ", ") + ret <- sapply(no_ranef_split, function(y) { + gsub("sd\\((.*)\\)", "\\1", y) }) - } else { - stop("Dimensions of illparms.mhmkin object given as 'no_random_effect' are not suitable") - } + return(ret) + }) + dim(no_ranef) <- no_ranef_dim } else { no_ranef <- no_random_effect } + } + + fit_function <- function(fit_index) { + w <- which(fit_indices == fit_index, arr.ind = TRUE) + deg_index <- w[1] + error_index <- w[2] + mmkin_row <- objects[[error_index]][deg_index, ] res <- try(do.call(backend_function, - args = c(list(mmkin_row), dot_args, list(no_random_effect = no_ranef)))) + args = c( + list(mmkin_row), + dot_args, + list(no_random_effect = no_ranef[[deg_index, error_index]])))) return(res) } @@ -145,15 +195,16 @@ mhmkin.list <- function(objects, backend = "saemix", algorithm = "saem", #' @param j Column index selecting the fits to specific datasets #' @param drop If FALSE, the method always returns an mhmkin object, otherwise #' either a list of fit objects or a single fit object. -#' @return An object of class \code{\link{mhmkin}}. +#' @return An object inheriting from \code{\link{mhmkin}}. #' @rdname mhmkin #' @export `[.mhmkin` <- function(x, i, j, ..., drop = FALSE) { + original_class <- class(x) class(x) <- NULL x_sub <- x[i, j, drop = drop] if (!drop) { - class(x_sub) <- "mhmkin" + class(x_sub) <- original_class } return(x_sub) } diff --git a/log/check.log b/log/check.log index 31fc31eb..42365918 100644 --- a/log/check.log +++ b/log/check.log @@ -5,7 +5,7 @@ * using options ‘--no-tests --as-cran’ * checking for file ‘mkin/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘mkin’ version ‘1.2.1’ +* this is package ‘mkin’ version ‘1.2.2’ * package encoding: UTF-8 * checking CRAN incoming feasibility ... Note_to_CRAN_maintainers Maintainer: ‘Johannes Ranke ’ @@ -18,7 +18,7 @@ Maintainer: ‘Johannes Ranke ’ * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking serialization versions ... OK -* checking whether package ‘mkin’ can be installed ... OK +* checking whether package ‘mkin’ can be installed ... [11s/11s] OK * checking installed package size ... OK * checking package directory ... OK * checking for future file timestamps ... OK @@ -41,7 +41,7 @@ Maintainer: ‘Johannes Ranke ’ * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK -* checking R code for possible problems ... [17s/17s] OK +* checking R code for possible problems ... [19s/19s] OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd line widths ... OK @@ -57,7 +57,7 @@ Maintainer: ‘Johannes Ranke ’ * checking data for ASCII and uncompressed saves ... OK * checking installed files from ‘inst/doc’ ... OK * checking files in ‘vignettes’ ... OK -* checking examples ... [20s/20s] OK +* checking examples ... [24s/24s] OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... SKIPPED * checking for unstated dependencies in vignettes ... OK diff --git a/log/test.log b/log/test.log index e17ecc1f..84fa49b9 100644 --- a/log/test.log +++ b/log/test.log @@ -1,58 +1,58 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.3s] +✔ | 5 | Analytical solutions for coupled models [4.2s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE -✔ | 12 | Confidence intervals and p-values [1.1s] -✔ | 1 12 | Dimethenamid data from 2018 [32.2s] +✔ | 12 | Confidence intervals and p-values [1.2s] +✔ | 1 12 | Dimethenamid data from 2018 [42.0s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [4.9s] +✔ | 14 | Error model fitting [6.5s] ✔ | 5 | Time step normalisation -✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] -✔ | 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] -✔ | 8 | Batch fitting and diagnosing hierarchical kinetic models [14.5s] -✔ | 1 11 | Nonlinear mixed-effects models [13.1s] +✔ | 4 | Calculation of FOCUS chi2 error levels [0.7s] +✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.1s] +✔ | 4 | Test fitting the decline of metabolites from their maximum [0.5s] +✔ | 1 | Fitting the logistic model [0.3s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [54.1s] +✔ | 1 11 | Nonlinear mixed-effects models [14.3s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:78'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.4s] -✔ | 3 | mkinfit features [0.7s] -✔ | 8 | mkinmod model generation and printing [0.2s] +✔ | 10 | Special cases of mkinfit calls [0.8s] +✔ | 3 | mkinfit features [0.9s] +✔ | 8 | mkinmod model generation and printing [0.3s] ✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 12 | Multistart method for saem.mmkin models [50.1s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.2s] -✔ | 9 | Nonlinear mixed-effects models with nlme [8.7s] -✔ | 15 | Plotting [10.2s] +✔ | 12 | Multistart method for saem.mmkin models [80.1s] +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.8s] +✔ | 9 | Nonlinear mixed-effects models with nlme [11.4s] +✔ | 15 | Plotting [12.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [103.8s] +✔ | 1 36 | saemix parent models [85.9s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.4s] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.9s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.8s] +✔ | 10 | Fitting the SFORB model [4.6s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] -✔ | 9 | Hypothesis tests [8.1s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.9s] +✔ | 9 | Hypothesis tests [11.0s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 266.0 s +Duration: 342.6 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 268 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 270 ] Error while shutting down parallel: unable to terminate some child processes diff --git a/man/mhmkin.Rd b/man/mhmkin.Rd index 4230e44f..c77f4289 100644 --- a/man/mhmkin.Rd +++ b/man/mhmkin.Rd @@ -43,11 +43,12 @@ supported} \item{no_random_effect}{Default is NULL and will be passed to \link{saem}. If a character vector is supplied, it will be passed to all calls to \link{saem}, -regardless if the corresponding parameter is in the model. Alternatively, -an object of class \link{illparms.mhmkin} can be specified. This has to have -the same dimensions as the return object of the current call. In this way, -ill-defined parameters found in corresponding simpler versions of the -degradation model can be specified.} +which will exclude random effects for all matching parameters. Alternatively, +a list of character vectors or an object of class \link{illparms.mhmkin} can be +specified. They have to have the same dimensions that the return object of +the current call will have, i.e. the number of rows must match the number +of degradation models in the mmkin object(s), and the number of columns must +match the number of error models used in the mmkin object(s).} \item{cores}{The number of cores to be used for multicore processing. This is only used when the \code{cluster} argument is \code{NULL}. On Windows @@ -74,7 +75,7 @@ be indexed using the degradation model names for the first index (row index) and the error model names for the second index (column index), with class attribute 'mhmkin'. -An object of class \code{\link{mhmkin}}. +An object inheriting from \code{\link{mhmkin}}. } \description{ The name of the methods expresses that (\strong{m}ultiple) \strong{h}ierarchichal @@ -82,6 +83,43 @@ The name of the methods expresses that (\strong{m}ultiple) \strong{h}ierarchicha fitted. Our kinetic models are nonlinear, so we can use various nonlinear mixed-effects model fitting functions. } +\examples{ +\dontrun{ +# We start with separate evaluations of all the first six datasets with two +# degradation models and two error models +f_sep_const <- mmkin(c("SFO", "FOMC"), ds_fomc[1:6], cores = 2, quiet = TRUE) +f_sep_tc <- update(f_sep_const, error_model = "tc") +# The mhmkin function sets up hierarchical degradation models aka +# nonlinear mixed-effects models for all four combinations, specifying +# uncorrelated random effects for all degradation parameters +f_saem_1 <- mhmkin(list(f_sep_const, f_sep_tc), cores = 2) +status(f_saem_1) +# The 'illparms' function shows that in all hierarchical fits, at least +# one random effect is ill-defined (the confidence interval for the +# random effect expressed as standard deviation includes zero) +illparms(f_saem_1) +# Therefore we repeat the fits, excluding the ill-defined random effects +f_saem_2 <- update(f_saem_1, no_random_effect = illparms(f_saem_1)) +status(f_saem_2) +illparms(f_saem_2) +# Model comparisons show that FOMC with two-component error is preferable, +# and confirms our reduction of the default parameter model +anova(f_saem_1) +anova(f_saem_2) +# The convergence plot for the selected model looks fine +saemix::plot(f_saem_2[["FOMC", "tc"]]$so, plot.type = "convergence") +# The plot of predictions versus data shows that we have a pretty data-rich +# situation with homogeneous distribution of residuals, because we used the +# same degradation model, error model and parameter distribution model that +# was used in the data generation. +plot(f_saem_2[["FOMC", "tc"]]) +# We can specify the same parameter model reductions manually +no_ranef <- list("parent_0", "log_beta", "parent_0", c("parent_0", "log_beta")) +dim(no_ranef) <- c(2, 2) +f_saem_2m <- update(f_saem_1, no_random_effect = no_ranef) +anova(f_saem_2m) +} +} \seealso{ \code{\link{[.mhmkin}} for subsetting \link{mhmkin} objects } diff --git a/tests/testthat/illparms_hfits_synth.txt b/tests/testthat/illparms_hfits_synth.txt index affd1318..7a69645b 100644 --- a/tests/testthat/illparms_hfits_synth.txt +++ b/tests/testthat/illparms_hfits_synth.txt @@ -1,8 +1,4 @@ error -degradation const - SFO - FOMC sd(log_alpha), sd(log_beta) - error -degradation tc - SFO sd(parent_0) - FOMC sd(parent_0), sd(log_alpha), sd(log_beta) +degradation const tc + SFO sd(parent_0) sd(parent_0) + FOMC sd(log_beta) sd(parent_0), sd(log_beta) diff --git a/tests/testthat/print_fits_synth_const.txt b/tests/testthat/print_fits_synth_const.txt index b4bbe6ca..5d076d3d 100644 --- a/tests/testthat/print_fits_synth_const.txt +++ b/tests/testthat/print_fits_synth_const.txt @@ -4,8 +4,6 @@ Status of individual fits: dataset model 1 2 3 4 5 6 SFO OK OK OK OK OK OK - FOMC C OK OK OK OK C + FOMC OK OK OK OK OK OK -C: Optimisation did not converge: -false convergence (8) OK: No warnings diff --git a/tests/testthat/summary_hfit_sfo_tc.txt b/tests/testthat/summary_hfit_sfo_tc.txt index 0a61f75f..0618c715 100644 --- a/tests/testthat/summary_hfit_sfo_tc.txt +++ b/tests/testthat/summary_hfit_sfo_tc.txt @@ -8,7 +8,7 @@ Equations: d_parent/dt = - k_parent * parent Data: -104 observations of 1 variable(s) grouped in 6 datasets +95 observations of 1 variable(s) grouped in 6 datasets Model predictions using solution type analytical @@ -19,7 +19,7 @@ Variance model: Two-component variance function Starting values for degradation parameters: parent_0 log_k_parent - 101 -3 + 94 -2 Fixed degradation parameter values: None @@ -27,7 +27,7 @@ None Starting values for random effects (square root of initial entries in omega): parent_0 log_k_parent parent_0 4 0.0 -log_k_parent 0 0.4 +log_k_parent 0 0.7 Starting values for error model parameters: a.1 b.1 @@ -37,15 +37,15 @@ Results: Likelihood computed by importance sampling AIC BIC logLik - 524 523 -257 + 542 541 -266 Optimised parameters: - est. lower upper -parent_0 100.68 99.27 102.08 -log_k_parent -3.38 -3.55 -3.21 -a.1 0.87 0.59 1.14 -b.1 0.05 0.04 0.06 -SD.log_k_parent 0.21 0.09 0.33 + est. lower upper +parent_0 92.52 89.11 95.9 +log_k_parent -1.66 -2.07 -1.3 +a.1 2.03 1.60 2.5 +b.1 0.09 0.07 0.1 +SD.log_k_parent 0.51 0.22 0.8 Correlation: pr_0 @@ -53,18 +53,18 @@ log_k_parent 0.1 Random effects: est. lower upper -SD.log_k_parent 0.2 0.09 0.3 +SD.log_k_parent 0.5 0.2 0.8 Variance model: est. lower upper -a.1 0.87 0.59 1.14 -b.1 0.05 0.04 0.06 +a.1 2.03 1.60 2.5 +b.1 0.09 0.07 0.1 Backtransformed parameters: - est. lower upper -parent_0 1e+02 99.27 1e+02 -k_parent 3e-02 0.03 4e-02 + est. lower upper +parent_0 92.5 89.1 95.9 +k_parent 0.2 0.1 0.3 Estimated disappearance times: DT50 DT90 -parent 20 68 +parent 4 12 diff --git a/tests/testthat/test_mhmkin.R b/tests/testthat/test_mhmkin.R index e2339f28..da063326 100644 --- a/tests/testthat/test_mhmkin.R +++ b/tests/testthat/test_mhmkin.R @@ -3,8 +3,11 @@ context("Batch fitting and diagnosing hierarchical kinetic models") test_that("Multiple hierarchical kinetic models can be fitted and diagnosed", { skip_on_cran() - fits_synth_const <- suppressWarnings( - mmkin(c("SFO", "FOMC"), ds_sfo[1:6], cores = n_cores, quiet = TRUE)) + fits_synth_const <- mmkin(c("SFO", "FOMC"), ds_fomc[1:6], cores = n_cores, quiet = TRUE) + + expect_known_output( + print(fits_synth_const), + "print_fits_synth_const.txt") fits_synth_tc <- suppressWarnings( update(fits_synth_const, error_model = "tc")) @@ -19,8 +22,8 @@ test_that("Multiple hierarchical kinetic models can be fitted and diagnosed", { print(illparms(hfits)), "illparms_hfits_synth.txt") - expect_equal(which.min(AIC(hfits)), 3) - expect_equal(which.min(BIC(hfits)), 3) + expect_equal(which.min(AIC(hfits)), 4) + expect_equal(which.min(BIC(hfits)), 4) hfit_sfo_tc <- update(hfits[["SFO", "tc"]], covariance.model = diag(c(0, 1))) @@ -38,12 +41,19 @@ test_that("Multiple hierarchical kinetic models can be fitted and diagnosed", { expect_known_output(print(test_summary, digits = 1), "summary_hfit_sfo_tc.txt") - # It depends on the platform exactly which of the datasets fail to converge - # with FOMC, because they were generated to be SFO - skip_on_travis() - - expect_known_output( - print(fits_synth_const), - "print_fits_synth_const.txt") - + hfits_sfo_reduced <- update(hfits, + no_random_effect = illparms(hfits)) + expect_equal( + as.character(illparms(hfits_sfo_reduced)), + rep("", 4)) + + # We can also manually set up an object specifying random effects to be + # excluded. Entries in the inital list have to be by column + no_ranef <- list("parent_0", "log_beta", "parent_0", c("parent_0", "log_beta")) + dim(no_ranef) <- c(2, 2) + + hfits_sfo_reduced_2 <- update(hfits, + no_random_effect = no_ranef) + expect_equivalent(round(anova(hfits_sfo_reduced), 0), + round(anova(hfits_sfo_reduced_2), 0)) }) -- cgit v1.2.3 From 478c6d5eec4c84b22b43adcbdf36888b302ead00 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 6 Dec 2022 10:33:24 +0100 Subject: Some parplot improvements llquant argument, improved legend text, tests --- NEWS.md | 2 + R/parplot.R | 16 +- log/test.log | 41 +++-- man/parplot.Rd | 7 +- .../_snaps/multistart/parplot-for-dfop-sfo-fit.svg | 169 ++++++++++----------- .../_snaps/multistart/parplot-for-sfo-fit.svg | 4 +- tests/testthat/test_multistart.R | 2 +- vignettes/FOCUS_D.html | 37 ++--- vignettes/FOCUS_L.html | 83 +++++----- 9 files changed, 183 insertions(+), 178 deletions(-) (limited to 'tests') diff --git a/NEWS.md b/NEWS.md index 15c45cc9..c7929fbe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ - 'R/summary.saem.mmkin.R': List all initial parameter values in the summary, including random effects and error model parameters. Avoid redundant warnings that occurred in the calculation of correlations of the fixed effects in the case that the Fisher information matrix could not be inverted. +- 'R/parplot.R': Possibility to select the top 'llquant' fraction of the fits for the parameter plots, and improved legend text. + # mkin 1.2.1 (2022-11-19) - '{data,R}/ds_mixed.rda': Include the test data in the package instead of generating it in 'tests/testthat/setup_script.R'. Refactor the generating code to make it consistent and update tests. diff --git a/R/parplot.R b/R/parplot.R index 98579779..63306ac2 100644 --- a/R/parplot.R +++ b/R/parplot.R @@ -10,7 +10,10 @@ #' #' @param object The [multistart] object #' @param llmin The minimum likelihood of objects to be shown -#' @param scale By default, scale parameters using the best available fit. +#' @param llquant Fractional value for selecting only the fits with higher +#' likelihoods. Overrides 'llmin'. +#' @param scale By default, scale parameters using the best +#' available fit. #' If 'median', parameters are scaled using the median parameters from all fits. #' @param main Title of the plot #' @param lpos Positioning of the legend. @@ -28,7 +31,8 @@ parplot <- function(object, ...) { #' @rdname parplot #' @export -parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, scale = c("best", "median"), +parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, llquant = NA, + scale = c("best", "median"), lpos = "bottomleft", main = "", ...) { oldpar <- par(no.readonly = TRUE) @@ -48,6 +52,10 @@ parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, scale = c("best" stop("parplot is only implemented for multistart.saem.mmkin objects") } ll <- sapply(object, llfunc) + if (!is.na(llquant[1])) { + if (llmin != -Inf) warning("Overriding 'llmin' because 'llquant' was specified") + llmin <- quantile(ll, 1 - llquant) + } selected <- which(ll > llmin) selected_parms <- all_parms[selected, ] @@ -110,7 +118,7 @@ parplot.multistart.saem.mmkin <- function(object, llmin = -Inf, scale = c("best" legend(lpos, inset = c(0.05, 0.05), bty = "n", pch = 1, col = 3:1, lty = c(NA, NA, 1), legend = c( - "Starting parameters", - "Original run", + "Original start", + "Original results", "Multistart runs")) } diff --git a/log/test.log b/log/test.log index 5764f209..7614b136 100644 --- a/log/test.log +++ b/log/test.log @@ -1,22 +1,22 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [3.3s] +✔ | 5 | Analytical solutions for coupled models [3.2s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE ✔ | 12 | Confidence intervals and p-values [1.1s] -✔ | 1 12 | Dimethenamid data from 2018 [31.9s] +✔ | 1 12 | Dimethenamid data from 2018 [32.0s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [4.9s] +✔ | 14 | Error model fitting [4.8s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [41.4s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [42.2s] ✔ | 1 11 | Nonlinear mixed-effects models [13.3s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:78'): saemix results are reproducible for biphasic fits @@ -26,32 +26,41 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve ✔ | 10 | Special cases of mkinfit calls [0.6s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] -✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 12 | Multistart method for saem.mmkin models [47.5s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.3s] -✔ | 9 | Nonlinear mixed-effects models with nlme [9.5s] -✔ | 15 | Plotting [10.2s] +✔ | 3 | Model predictions with mkinpredict [0.4s] +✖ | 1 11 | Multistart method for saem.mmkin models [46.7s] +──────────────────────────────────────────────────────────────────────────────── +Failure ('test_multistart.R:56'): multistart works for saem.mmkin models +Snapshot of `testcase` to 'multistart/parplot-for-dfop-sfo-fit.svg' has changed +Run `testthat::snapshot_review('multistart/')` to review changes +Backtrace: + 1. vdiffr::expect_doppelganger("parplot for dfop sfo fit", parplot_dfop_sfo) + at test_multistart.R:56:2 + 3. testthat::expect_snapshot_file(...) +──────────────────────────────────────────────────────────────────────────────── +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.2s] +✔ | 9 | Nonlinear mixed-effects models with nlme [9.4s] +✔ | 15 | Plotting [10.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [73.0s] +✔ | 1 36 | saemix parent models [73.6s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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] +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.9s] +✔ | 10 | 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.2s] -✔ | 9 | Hypothesis tests [8.4s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.3s] +✔ | 9 | Hypothesis tests [8.1s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 261.1 s +Duration: 260.9 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 270 ] +[ FAIL 1 | WARN 0 | SKIP 3 | PASS 269 ] diff --git a/man/parplot.Rd b/man/parplot.Rd index ac9e02cf..67bf0cc1 100644 --- a/man/parplot.Rd +++ b/man/parplot.Rd @@ -10,6 +10,7 @@ parplot(object, ...) \method{parplot}{multistart.saem.mmkin}( object, llmin = -Inf, + llquant = NA, scale = c("best", "median"), lpos = "bottomleft", main = "", @@ -23,7 +24,11 @@ parplot(object, ...) \item{llmin}{The minimum likelihood of objects to be shown} -\item{scale}{By default, scale parameters using the best available fit. +\item{llquant}{Fractional value for selecting only the fits with higher +likelihoods. Overrides 'llmin'.} + +\item{scale}{By default, scale parameters using the best +available fit. If 'median', parameters are scaled using the median parameters from all fits.} \item{lpos}{Positioning of the legend.} diff --git a/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg index 7017908e..b01dac74 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg @@ -25,109 +25,104 @@ - - - - + + + + - - - - - - - - + + + + + + - - - - - + + + + + - + - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - - - - - + + + + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - + + + + + - + @@ -194,8 +189,8 @@ -Starting parameters -Original run +Original start +Original results Multistart runs diff --git a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg index a47a585a..c8d4970b 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg @@ -103,8 +103,8 @@ -Starting parameters -Original run +Original start +Original results Multistart runs diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 91ef71f0..dda0ea23 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -50,7 +50,7 @@ test_that("multistart works for saem.mmkin models", { llhist_dfop_sfo <- function() llhist(saem_dfop_sfo_m_multi) parplot_dfop_sfo <- function() parplot(saem_dfop_sfo_m_multi, - ylim = c(0.5, 2)) + ylim = c(0.5, 2), llquant = 0.5) vdiffr::expect_doppelganger("llhist for dfop sfo fit", llhist_dfop_sfo) vdiffr::expect_doppelganger("parplot for dfop sfo fit", parplot_dfop_sfo) diff --git a/vignettes/FOCUS_D.html b/vignettes/FOCUS_D.html index 9f768b06..b8a63a7b 100644 --- a/vignettes/FOCUS_D.html +++ b/vignettes/FOCUS_D.html @@ -299,8 +299,8 @@ pre code { border-radius: 4px; } -.tabset-dropdown > .nav-tabs > li.active:before { - content: ""; +.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before { + content: "\e259"; font-family: 'Glyphicons Halflings'; display: inline-block; padding: 10px; @@ -308,16 +308,9 @@ pre code { } .tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before { - content: ""; - border: none; -} - -.tabset-dropdown > .nav-tabs.nav-tabs-open:before { - content: ""; + content: "\e258"; font-family: 'Glyphicons Halflings'; - display: inline-block; - padding: 10px; - border-right: 1px solid #ddd; + border: none; } .tabset-dropdown > .nav-tabs > li.active { @@ -364,7 +357,7 @@ pre code {

      Example evaluation of FOCUS Example Dataset D

      Johannes Ranke

      -

      Last change 31 January 2019 (rebuilt 2022-07-08)

      +

      Last change 31 January 2019 (rebuilt 2022-12-06)

@@ -438,10 +431,10 @@ print(FOCUS_2006_D)

A comprehensive report of the results is obtained using the summary method for mkinfit objects.

summary(fit)
-
## mkin version used for fitting:    1.1.0 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Fri Jul  8 15:44:37 2022 
-## Date of summary: Fri Jul  8 15:44:38 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:42 2022 
+## Date of summary: Tue Dec  6 09:39:42 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent * parent
@@ -449,7 +442,7 @@ print(FOCUS_2006_D)
## ## Model predictions using solution type analytical ## -## Fitted using 401 model solutions performed in 0.13 s +## Fitted using 401 model solutions performed in 0.158 s ## ## Error model: Constant variance ## @@ -492,11 +485,11 @@ print(FOCUS_2006_D)
## ## Parameter correlation: ## parent_0 log_k_parent log_k_m1 f_parent_qlogis sigma -## parent_0 1.000e+00 5.174e-01 -1.688e-01 -5.471e-01 -1.174e-06 -## log_k_parent 5.174e-01 1.000e+00 -3.263e-01 -5.426e-01 -8.492e-07 -## log_k_m1 -1.688e-01 -3.263e-01 1.000e+00 7.478e-01 8.220e-07 -## f_parent_qlogis -5.471e-01 -5.426e-01 7.478e-01 1.000e+00 1.307e-06 -## sigma -1.174e-06 -8.492e-07 8.220e-07 1.307e-06 1.000e+00 +## parent_0 1.000e+00 5.174e-01 -1.688e-01 -5.471e-01 -1.172e-06 +## log_k_parent 5.174e-01 1.000e+00 -3.263e-01 -5.426e-01 -8.483e-07 +## log_k_m1 -1.688e-01 -3.263e-01 1.000e+00 7.478e-01 8.205e-07 +## f_parent_qlogis -5.471e-01 -5.426e-01 7.478e-01 1.000e+00 1.305e-06 +## sigma -1.172e-06 -8.483e-07 8.205e-07 1.305e-06 1.000e+00 ## ## Backtransformed parameters: ## Confidence intervals for internally transformed parameters are asymmetric. diff --git a/vignettes/FOCUS_L.html b/vignettes/FOCUS_L.html index da6c11fe..b8c9ba0c 100644 --- a/vignettes/FOCUS_L.html +++ b/vignettes/FOCUS_L.html @@ -1373,8 +1373,8 @@ pre code { border-radius: 4px; } -.tabset-dropdown > .nav-tabs > li.active:before { - content: ""; +.tabset-dropdown > .nav-tabs > li.active:before, .tabset-dropdown > .nav-tabs.nav-tabs-open:before { + content: "\e259"; font-family: 'Glyphicons Halflings'; display: inline-block; padding: 10px; @@ -1382,16 +1382,9 @@ pre code { } .tabset-dropdown > .nav-tabs.nav-tabs-open > li.active:before { - content: ""; - border: none; -} - -.tabset-dropdown > .nav-tabs.nav-tabs-open:before { - content: ""; + content: "\e258"; font-family: 'Glyphicons Halflings'; - display: inline-block; - padding: 10px; - border-right: 1px solid #ddd; + border: none; } .tabset-dropdown > .nav-tabs > li.active { @@ -1517,7 +1510,7 @@ div.tocify {

Example evaluation of FOCUS Laboratory Data L1 to L3

Johannes Ranke

-

Last change 18 May 2022 (rebuilt 2022-09-14)

+

Last change 18 May 2022 (rebuilt 2022-12-06)

@@ -1536,17 +1529,17 @@ FOCUS_2006_L1_mkin <- mkin_wide_to_long(FOCUS_2006_L1)

Since mkin version 0.9-32 (July 2014), we can use shorthand notation like "SFO" for parent only degradation models. The following two lines fit the model and produce the summary report of the model fit. This covers the numerical analysis given in the FOCUS report.

m.L1.SFO <- mkinfit("SFO", FOCUS_2006_L1_mkin, quiet = TRUE)
 summary(m.L1.SFO)
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:35 2022 
-## Date of summary: Wed Sep 14 22:28:35 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:45 2022 
+## Date of summary: Tue Dec  6 09:39:45 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted using 133 model solutions performed in 0.032 s
+## Fitted using 133 model solutions performed in 0.033 s
 ## 
 ## Error model: Constant variance 
 ## 
@@ -1637,10 +1630,10 @@ summary(m.L1.SFO)
## Warning in sqrt(1/diag(V)): NaNs produced
## Warning in cov2cor(ans$covar): diag(.) had 0 or NA entries; non-finite result is
 ## doubtful
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:35 2022 
-## Date of summary: Wed Sep 14 22:28:35 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:45 2022 
+## Date of summary: Tue Dec  6 09:39:45 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
@@ -1742,17 +1735,17 @@ plot(m.L2.FOMC, show_residuals = TRUE,
      main = "FOCUS L2 - FOMC")

summary(m.L2.FOMC, data = FALSE)
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:35 2022 
-## Date of summary: Wed Sep 14 22:28:35 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:45 2022 
+## Date of summary: Tue Dec  6 09:39:45 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted using 239 model solutions performed in 0.049 s
+## Fitted using 239 model solutions performed in 0.048 s
 ## 
 ## Error model: Constant variance 
 ## 
@@ -1820,10 +1813,10 @@ plot(m.L2.DFOP, show_residuals = TRUE, show_errmin = TRUE,
      main = "FOCUS L2 - DFOP")

summary(m.L2.DFOP, data = FALSE)
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:36 2022 
-## Date of summary: Wed Sep 14 22:28:36 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:46 2022 
+## Date of summary: Tue Dec  6 09:39:46 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
@@ -1832,7 +1825,7 @@ plot(m.L2.DFOP, show_residuals = TRUE, show_errmin = TRUE,
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted using 581 model solutions performed in 0.135 s
+## Fitted using 581 model solutions performed in 0.131 s
 ## 
 ## Error model: Constant variance 
 ## 
@@ -1920,10 +1913,10 @@ plot(mm.L3)

The objects returned by mmkin are arranged like a matrix, with models as a row index and datasets as a column index.

We can extract the summary and plot for e.g. the DFOP fit, using square brackets for indexing which will result in the use of the summary and plot functions working on mkinfit objects.

summary(mm.L3[["DFOP", 1]])
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:36 2022 
-## Date of summary: Wed Sep 14 22:28:36 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:46 2022 
+## Date of summary: Tue Dec  6 09:39:46 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
@@ -1932,7 +1925,7 @@ plot(mm.L3)
## ## Model predictions using solution type analytical ## -## Fitted using 376 model solutions performed in 0.081 s +## Fitted using 376 model solutions performed in 0.078 s ## ## Error model: Constant variance ## @@ -2028,17 +2021,17 @@ plot(mm.L4)

The χ2 error level of 3.3% as well as the plot suggest that the SFO model fits very well. The error level at which the χ2 test passes is slightly lower for the FOMC model. However, the difference appears negligible.

summary(mm.L4[["SFO", 1]], data = FALSE)
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:36 2022 
-## Date of summary: Wed Sep 14 22:28:37 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:47 2022 
+## Date of summary: Tue Dec  6 09:39:47 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted using 142 model solutions performed in 0.034 s
+## Fitted using 142 model solutions performed in 0.03 s
 ## 
 ## Error model: Constant variance 
 ## 
@@ -2092,10 +2085,10 @@ plot(mm.L4)
## DT50 DT90 ## parent 106 352
summary(mm.L4[["FOMC", 1]], data = FALSE)
-
## mkin version used for fitting:    1.1.2 
-## R version used for fitting:       4.2.1 
-## Date of fit:     Wed Sep 14 22:28:37 2022 
-## Date of summary: Wed Sep 14 22:28:37 2022 
+
## mkin version used for fitting:    1.2.2 
+## R version used for fitting:       4.2.2 
+## Date of fit:     Tue Dec  6 09:39:47 2022 
+## Date of summary: Tue Dec  6 09:39:47 2022 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
-- 
cgit v1.2.3