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_saemix_parent.R | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'tests/testthat/test_saemix_parent.R') 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