From f215080efba4097ccdaa2d1208edd36c26d7978a Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Sat, 15 Apr 2023 20:00:00 +0200 Subject: Increase test coverage Also, using mkin analytical solutions for more than one observed variable is not supported (but could be if out_values would be reordered). --- R/saem.R | 4 ++ .../hierarchical_kinetics/skeleton/skeleton.Rmd | 16 ++++++- log/check.log | 9 +++- log/test.log | 30 ++++++------- tests/testthat/test_compiled_symbols.R | 2 +- tests/testthat/test_mixed.R | 51 ++++++++++++++++++++++ 6 files changed, 92 insertions(+), 20 deletions(-) diff --git a/R/saem.R b/R/saem.R index 83de97b0..a9f97d23 100644 --- a/R/saem.R +++ b/R/saem.R @@ -307,6 +307,10 @@ saemix_model <- function(object, solution_type = "auto", mkin_model <- object[[1]]$mkinmod + if (length(mkin_model$spec) > 1 & solution_type[1] == "analytical") { + stop("mkin analytical solutions not supported for more thane one observed variable") + } + degparms_optim <- mean_degparms(object, test_log_parms = test_log_parms) na_degparms <- names(which(is.na(degparms_optim))) if (length(na_degparms) > 0) { diff --git a/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd index cb328308..71d62677 100644 --- a/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/hierarchical_kinetics/skeleton/skeleton.Rmd @@ -15,7 +15,6 @@ library(mkin) library(knitr) library(saemix) library(parallel) -library(readxl) ``` ```{r n_cores, cache = FALSE} @@ -186,6 +185,13 @@ illparms(parent_best_pH_2) parms(parent_best_pH_2, ci = TRUE) |> kable(digits = 3) ``` +The endpoints corresponding to the median pH in the tested soils +are shown below. + +```{r dependson = "parent-best-pH"} +endpoints(parent_best_pH_2) +``` + ```{r} stopCluster(cl) ``` @@ -280,6 +286,13 @@ plot(path_1_refined) parms(path_1_refined, ci = TRUE) |> kable(digits = 3) ``` +The pathway endpoints corresponding to the median pH in the tested soils +are shown below. + +```{r dependson = "parent-best-pH"} +endpoints(parent_best_pH_2) +``` + ```{r} stopCluster(cl) ``` @@ -324,7 +337,6 @@ tex_listing(path_1_refined, ## Session info ```{r echo = FALSE, cache = FALSE} -parallel::stopCluster(cl) sessionInfo() ``` diff --git a/log/check.log b/log/check.log index b7f6068c..b58119ef 100644 --- a/log/check.log +++ b/log/check.log @@ -21,7 +21,8 @@ Maintainer: ‘Johannes Ranke ’ * checking whether package ‘mkin’ can be installed ... OK * checking installed package size ... OK * checking package directory ... OK -* checking for future file timestamps ... OK +* checking for future file timestamps ... NOTE +unable to verify current time * checking ‘build’ directory ... OK * checking DESCRIPTION meta-information ... OK * checking top-level files ... OK @@ -70,5 +71,9 @@ Maintainer: ‘Johannes Ranke ’ * checking for detritus in the temp directory ... OK * DONE -Status: OK +Status: 1 NOTE +See + ‘/home/jranke/git/mkin/mkin.Rcheck/00check.log’ +for details. + diff --git a/log/test.log b/log/test.log index fa808f22..cec5e7ed 100644 --- a/log/test.log +++ b/log/test.log @@ -1,39 +1,39 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [1.6s] +✔ | 5 | Analytical solutions for coupled models [1.5s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE -✔ | 7 | Use of precompiled symbols in mkinpredict [3.3s] +✔ | 6 | Use of precompiled symbols in mkinpredict [3.2s] ✔ | 12 | Confidence intervals and p-values [0.4s] -✔ | 1 12 | Dimethenamid data from 2018 [13.4s] +✔ | 1 12 | Dimethenamid data from 2018 [12.5s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:88'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [2.5s] +✔ | 14 | Error model fitting [2.4s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.3s] -✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.5s] -✔ | 4 | Test fitting the decline of metabolites from their maximum [0.3s] +✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.4s] +✔ | 4 | Test fitting the decline of metabolites from their maximum [0.2s] ✔ | 1 | Fitting the logistic model [0.1s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [19.8s] -✔ | 1 11 | Nonlinear mixed-effects models [6.1s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [19.1s] +✔ | 1 17 | Nonlinear mixed-effects models [294.0s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:78'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve ──────────────────────────────────────────────────────────────────────────────── ✔ | 3 | Test dataset classes mkinds and mkindsg -✔ | 10 | Special cases of mkinfit calls [0.4s] +✔ | 10 | Special cases of mkinfit calls [0.3s] ✔ | 3 | mkinfit features [0.5s] ✔ | 8 | mkinmod model generation and printing ✔ | 3 | Model predictions with mkinpredict [0.1s] -✔ | 12 | Multistart method for saem.mmkin models [21.7s] +✔ | 12 | Multistart method for saem.mmkin models [23.2s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [1.5s] ✔ | 9 | Nonlinear mixed-effects models with nlme [3.8s] -✔ | 15 | Plotting [4.7s] +✔ | 15 | Plotting [4.8s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [32.0s] +✔ | 1 36 | saemix parent models [30.7s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): We can also use mkin solution methods for saem Reason: This still takes almost 2.5 minutes although we do not solve ODEs @@ -44,15 +44,15 @@ Reason: This still takes almost 2.5 minutes although we do not solve ODEs ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary ✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [0.8s] -✔ | 9 | Hypothesis tests [3.0s] +✔ | 9 | Hypothesis tests [2.9s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [0.7s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 120.2 s +Duration: 406.1 s ── Skipped tests ────────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 15 minutes on my system (1) • Fitting with saemix takes around 10 minutes when using deSolve (1) • This still takes almost 2.5 minutes although we do not solve ODEs (1) -[ FAIL 0 | WARN 0 | SKIP 3 | PASS 277 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 282 ] diff --git a/tests/testthat/test_compiled_symbols.R b/tests/testthat/test_compiled_symbols.R index 0c8aff99..740781cf 100644 --- a/tests/testthat/test_compiled_symbols.R +++ b/tests/testthat/test_compiled_symbols.R @@ -53,6 +53,6 @@ test_that("We can safely use compiled code", { } else { expect_true(file.remove("test_dlls/sfo_sfo.so")) } - expect_true(file.remove("test_dlls")) + suppressWarnings(file.remove("test_dlls")) }) diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 39a332f5..c60d1421 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -83,3 +83,54 @@ test_that("saemix results are reproducible for biphasic fits", { 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])) }) + +test_that("Reading spreadsheets, finding ill-defined parameters and covariate modelling", { + + skip_on_cran() + + data_path <- system.file( + "testdata", "lambda-cyhalothrin_soil_efsa_2014.xlsx", + package = "mkin") + ds_lambda <- read_spreadsheet(data_path, valid_datasets = c(1:4, 7:13)) + covariates <- attr(ds_lambda, "covariates") + + lambda_sforb <- mmkin("SFORB", ds_lambda, quiet = TRUE, + cores = n_cores, + error_model = "const") + lambda_sforb_saem_pH <- saem(lambda_sforb, covariates = covariates, + covariate_models = list(log_k_lambda_bound_free ~ pH)) + expect_equal( + as.character(illparms(lambda_sforb_saem_pH)), + c("sd(lambda_free_0)", "sd(log_k_lambda_free_bound)")) + + lambda_endpoints <- endpoints(lambda_sforb_saem_pH) + expect_equal(lambda_endpoints$covariates$pH, 6.45) + expect_equal( + round(as.numeric(lambda_endpoints$distimes), 0), + c(47, 422, 127, 7, 162)) +}) + +test_that("SFO-SFO saemix specific analytical solution work", { + + skip_on_cran() + + SFO_SFO <- mkinmod(DMTA = mkinsub("SFO", "M23"), + M23 = mkinsub("SFO"), quiet = TRUE) + mmkin_sfo_sfo <- mmkin(list("SFO-SFO" = SFO_SFO), dmta_ds, quiet = TRUE, + cores = n_cores, + error_model = "const") + saem_sfo_sfo_saemix_analytical <- saem(mmkin_sfo_sfo) + + expect_error(saem(mmkin_sfo_sfo, solution_type = "analytical"), "not supported") + + saem_sfo_sfo_mkin_eigen<- saem(mmkin_sfo_sfo, solution_type = "eigen") + expect_equal( + endpoints(saem_sfo_sfo_saemix_analytical), + endpoints(saem_sfo_sfo_mkin_eigen)) + + saem_sfo_sfo_mkin_desolve <- saem(mmkin_sfo_sfo, solution_type = "deSolve") + expect_equal( + endpoints(saem_sfo_sfo_saemix_analytical), + endpoints(saem_sfo_sfo_mkin_desolve)) + +}) -- cgit v1.2.1