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.1 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 --- tests/testthat/test_dmta.R | 8 ++++---- tests/testthat/test_multistart.R | 2 +- tests/testthat/test_nafta.R | 2 ++ 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'tests') 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.1 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.1 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.1 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. --- .../_snaps/multistart/parplot-for-biphasic-saemix-fit.svg | 2 ++ tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg | 2 ++ tests/testthat/test_multistart.R | 8 ++++---- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'tests') 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.1 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. --- tests/testthat/print_dfop_saemix_1.txt | 8 ++++---- tests/testthat/test_mixed.R | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'tests') 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.1 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. --- .../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 ++-- 22 files changed, 533 insertions(+), 618 deletions(-) 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/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.1 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 --- tests/testthat/setup_script.R | 22 +++++++++++++++------- tests/testthat/test_saemix_parent.R | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'tests') 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.1 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... --- ...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 - 6 files changed, 2520 insertions(+), 2514 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/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.1 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 --- tests/testthat/test_mixed.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') 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.1 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) --- tests/testthat/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 ---------- 5 files changed, 24 insertions(+), 25 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/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.1 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 --- 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 ++++++++++++++++++++----------- 4 files changed, 43 insertions(+), 39 deletions(-) (limited to 'tests') 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.1 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 --- .../_snaps/multistart/parplot-for-dfop-sfo-fit.svg | 169 ++++++++++----------- .../_snaps/multistart/parplot-for-sfo-fit.svg | 4 +- tests/testthat/test_multistart.R | 2 +- 3 files changed, 85 insertions(+), 90 deletions(-) (limited to 'tests') 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) -- cgit v1.2.1