From a1b5d63e031d22b190e9e9fc30753b699ad6b4ea Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 23 Nov 2023 05:20:17 +0100 Subject: fix: 'R/illparms.R': An ill-defined random effect is now also found if there is only one random effect in the model. Also add a test for this. --- tests/testthat/test_saemix_parent.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests') diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index 7fbecd0c..c80b4fa1 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -148,3 +148,30 @@ test_that("We can also use mkin solution methods for saem", { rel_diff <- abs(distimes_dfop_analytical - distimes_dfop) / distimes_dfop expect_true(all(rel_diff < 0.01)) }) + +test_that("illparms finds a single random effect that is ill-defined", { + set.seed(123456) + n <- 4 + SFO <- mkinmod(parent = mkinsub("SFO")) + sfo_pop <- list(parent_0 = 100, k_parent = 0.03) + sfo_parms <- as.matrix(data.frame( + k_parent = rlnorm(n, log(sfo_pop$k_parent), 0.001))) + sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) + err_1 = list(const = 1, prop = 0.05) + tc <- function(value) sigma_twocomp(value, err_1$const, err_1$prop) + set.seed(123456) + ds_sfo <- lapply(1:n, function(i) { + ds_mean <- mkinpredict(SFO, sfo_parms[i, ], + c(parent = sfo_pop$parent_0), sampling_times) + add_err(ds_mean, tc, n = 1)[[1]] + }) + m_mmkin <- mmkin("SFO", ds_sfo, error_model = "tc", quiet = TRUE) + m_saem_1 <- saem(m_mmkin) + expect_equal( + as.character(illparms(m_saem_1)), + c("sd(parent_0)", "sd(log_k_parent)")) + m_saem_2 <- saem(m_mmkin, no_random_effect = "parent_0") + expect_equal( + as.character(illparms(m_saem_2)), + "sd(log_k_parent)") +} -- cgit v1.2.1 From 43af185533b11327368148a44e9295ea3eb3abb1 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 23 Nov 2023 06:17:28 +0100 Subject: Bump version, fix test from last commit, check and test --- tests/testthat/test_saemix_parent.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index c80b4fa1..88b406b6 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -174,4 +174,4 @@ test_that("illparms finds a single random effect that is ill-defined", { expect_equal( as.character(illparms(m_saem_2)), "sd(log_k_parent)") -} +}) -- cgit v1.2.1 From e18c8da322ddb11105b7fdf93e9dd538673fb946 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 27 Apr 2024 19:22:10 +0200 Subject: Fix bug in R/create_deg_func.R Closes #13 --- tests/testthat/print_dfop_saem_1.txt | 2 +- tests/testthat/summary_hfit_sfo_tc.txt | 4 ++-- tests/testthat/summary_saem_dfop_sfo_s.txt | 2 +- tests/testthat/test_water-sediment.R | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/testthat/test_water-sediment.R (limited to 'tests') diff --git a/tests/testthat/print_dfop_saem_1.txt b/tests/testthat/print_dfop_saem_1.txt index f7354320..3a1f1667 100644 --- a/tests/testthat/print_dfop_saem_1.txt +++ b/tests/testthat/print_dfop_saem_1.txt @@ -18,6 +18,6 @@ log_k1 -2.71 -2.94 -2.49 log_k2 -4.14 -4.26 -4.01 g_qlogis -0.36 -0.54 -0.17 a.1 0.93 0.69 1.17 -b.1 0.05 0.04 0.06 +b.1 0.05 0.04 0.05 SD.log_k1 0.37 0.23 0.51 SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/summary_hfit_sfo_tc.txt b/tests/testthat/summary_hfit_sfo_tc.txt index 0618c715..ba7d1362 100644 --- a/tests/testthat/summary_hfit_sfo_tc.txt +++ b/tests/testthat/summary_hfit_sfo_tc.txt @@ -43,7 +43,7 @@ Optimised parameters: 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 +a.1 2.03 1.61 2.5 b.1 0.09 0.07 0.1 SD.log_k_parent 0.51 0.22 0.8 @@ -57,7 +57,7 @@ SD.log_k_parent 0.5 0.2 0.8 Variance model: est. lower upper -a.1 2.03 1.60 2.5 +a.1 2.03 1.61 2.5 b.1 0.09 0.07 0.1 Backtransformed parameters: diff --git a/tests/testthat/summary_saem_dfop_sfo_s.txt b/tests/testthat/summary_saem_dfop_sfo_s.txt index 6468ff17..a19824ce 100644 --- a/tests/testthat/summary_saem_dfop_sfo_s.txt +++ b/tests/testthat/summary_saem_dfop_sfo_s.txt @@ -86,7 +86,7 @@ SD.g 0.21 0.06 0.4 Variance model: est. lower upper -a.1 0.93 0.79 1.06 +a.1 0.93 0.80 1.06 b.1 0.05 0.05 0.06 Resulting formation fractions: diff --git a/tests/testthat/test_water-sediment.R b/tests/testthat/test_water-sediment.R new file mode 100644 index 00000000..6d5693c9 --- /dev/null +++ b/tests/testthat/test_water-sediment.R @@ -0,0 +1,17 @@ +# Issue #13 on github +water_sed_no_sed_sink <- mkinmod( + use_of_ff = "min", + water = mkinsub("SFO", "sediment"), + sediment = mkinsub("SFO", "water", sink = FALSE)) + +ws_data <- FOCUS_D +levels(ws_data$name) <- c("water", "sediment") + +test_that("An reversible reaction with the sink turned off in the second compartment works", { + # Solution method "analytical" was previously available, but erroneous + expect_error( + ws_fit_no_sed_sink <- mkinfit(water_sed_no_sed_sink, ws_data, quiet = TRUE, solution_type = "analytical"), + "Analytical solution not implemented") + ws_fit_no_sed_sink_default <- mkinfit(water_sed_no_sed_sink, ws_data, quiet = TRUE) + expect_equal(ws_fit_no_sed_sink_default$solution_type, "deSolve") +}) -- cgit v1.2.1 From 272b3863d1463dfaf62c6e06ea22610c0540237f Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sun, 28 Jul 2024 09:25:18 +0200 Subject: Make sure test work on my desktop, skip more tests on travis --- tests/testthat/test_mixed.R | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index d8ad4417..b9715096 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -89,6 +89,7 @@ test_that("saemix results are reproducible for biphasic fits", { test_that("Reading spreadsheets, finding ill-defined parameters and covariate modelling", { skip_on_cran() + skip_on_travis() data_path <- system.file( "testdata", "lambda-cyhalothrin_soil_efsa_2014.xlsx", @@ -115,6 +116,7 @@ test_that("Reading spreadsheets, finding ill-defined parameters and covariate mo test_that("SFO-SFO saemix specific analytical solution work", { skip_on_cran() + skip_on_travis() SFO_SFO <- mkinmod(DMTA = mkinsub("SFO", "M23"), M23 = mkinsub("SFO"), quiet = TRUE) -- cgit v1.2.1 From 4c3ce8a3e77969162a6717cb2c5d2dd9f02ef1c9 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 13 Feb 2025 14:57:25 +0100 Subject: Restrict number of cores for CRAN checks --- tests/testthat/test_saemix_parent.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index 88b406b6..8ac04614 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -165,7 +165,7 @@ test_that("illparms finds a single random effect that is ill-defined", { c(parent = sfo_pop$parent_0), sampling_times) add_err(ds_mean, tc, n = 1)[[1]] }) - m_mmkin <- mmkin("SFO", ds_sfo, error_model = "tc", quiet = TRUE) + m_mmkin <- mmkin("SFO", ds_sfo, error_model = "tc", quiet = TRUE, cores = n_cores) m_saem_1 <- saem(m_mmkin) expect_equal( as.character(illparms(m_saem_1)), -- cgit v1.2.1 From e8db0cdb378fe4f429f935221c4eb50b178b84a5 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 13 Feb 2025 15:46:49 +0100 Subject: Improve legend in parplots of multistart objects --- .../_snaps/multistart/parplot-for-dfop-sfo-fit.svg | 339 +++++++++++---------- tests/testthat/test_multistart.R | 9 +- 2 files changed, 178 insertions(+), 170 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 ed9168fb..c733f84f 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg @@ -20,177 +20,182 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - -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 - + + + + + + + + + + + + + + + +parent_0 +k_m1 +f_parent_to_m1 +k1 +k2 +g +a.1 +b.1 +SD.parent_0 +SD.log_k_m1 +SD.f_parent_qlogis +SD.log_k1 +SD.log_k2 +SD.g_qlogis + + + + + +0.5 +1.0 +1.5 +2.0 +Normalised parameters + - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Original start -Original results -Multistart runs + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Original start +Original results +Multistart runs diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index dda0ea23..36aa63f7 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -44,13 +44,16 @@ test_that("multistart works for saem.mmkin models", { 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)) + parplot_sfo <- function() parplot(saem_sfo_s_multi, ylim = c(0.5, 2), las = 1) vdiffr::expect_doppelganger("llhist for sfo fit", llhist_sfo) vdiffr::expect_doppelganger("parplot for sfo fit", parplot_sfo) 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), llquant = 0.5) + parplot_dfop_sfo <- function() { + par(mar = c(10.1, 4.1, 2.1, 2.1)) + parplot(saem_dfop_sfo_m_multi, + ylim = c(0.5, 2), llquant = 0.5, las = 2) + } 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 6476f5f49b373cd4cf05f2e73389df83e437d597 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 13 Feb 2025 16:30:31 +0100 Subject: Axis legend formatting, update vignettes --- tests/testthat/Rplots.pdf | Bin 0 -> 3611 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/testthat/Rplots.pdf (limited to 'tests') diff --git a/tests/testthat/Rplots.pdf b/tests/testthat/Rplots.pdf new file mode 100644 index 00000000..2638aff8 Binary files /dev/null and b/tests/testthat/Rplots.pdf differ -- cgit v1.2.1