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/testthat/test_multistart.R') 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_multistart.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/testthat/test_multistart.R') 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) -- 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. --- tests/testthat/test_multistart.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/testthat/test_multistart.R') 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 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. --- tests/testthat/test_multistart.R | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'tests/testthat/test_multistart.R') 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) }) -- 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... --- tests/testthat/test_multistart.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests/testthat/test_multistart.R') 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) -- 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 --- tests/testthat/test_multistart.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/testthat/test_multistart.R') 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