diff options
| author | Johannes Ranke <jranke@uni-bremen.de> | 2021-01-06 20:34:52 +0100 | 
|---|---|---|
| committer | Johannes Ranke <jranke@uni-bremen.de> | 2021-01-06 20:38:29 +0100 | 
| commit | f99bdd8697c3bfbd432a320774a4692fd0e1241a (patch) | |
| tree | f2f03f30d3fa3f25780f21611ec407b7a90ad2eb | |
| parent | d28ce9f8ad6f9573e403ebd8eb637ecd5e5b0e02 (diff) | |
Make saemix and corresponding tests optional
Address release critical check and test issues
| -rw-r--r-- | DESCRIPTION | 7 | ||||
| -rw-r--r-- | NEWS.md | 26 | ||||
| -rw-r--r-- | R/D24_2014.R | 2 | ||||
| -rw-r--r-- | check.log | 16 | ||||
| -rw-r--r-- | man/D24_2014.Rd | 2 | ||||
| -rw-r--r-- | man/saem.Rd | 8 | ||||
| -rw-r--r-- | man/summary.saem.mmkin.Rd | 2 | ||||
| -rw-r--r-- | test.log | 52 | ||||
| -rw-r--r-- | test_dev.log | 69 | ||||
| -rw-r--r-- | tests/testthat/print_mmkin_biphasic_mixed.txt | 4 | ||||
| -rw-r--r-- | tests/testthat/print_nlme_biphasic.txt | 8 | ||||
| -rw-r--r-- | tests/testthat/setup_script.R | 39 | ||||
| -rw-r--r-- | tests/testthat/summary_nlme_biphasic_s.txt | 42 | ||||
| -rw-r--r-- | tests/testthat/test_error_models.R | 1 | ||||
| -rw-r--r-- | tests/testthat/test_mixed.R | 13 | ||||
| -rw-r--r-- | tests/testthat/test_plot.R | 14 | 
16 files changed, 187 insertions, 118 deletions
| diff --git a/DESCRIPTION b/DESCRIPTION index 697aa90d..fa6c1c90 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Package: mkin  Type: Package  Title: Kinetic Evaluation of Chemical Degradation Data  Version: 0.9.50.4 -Date: 2020-12-10 +Date: 2021-01-06  Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),                      email = "jranke@uni-bremen.de",                      comment = c(ORCID = "0000-0003-4371-6538")), @@ -18,9 +18,10 @@ Description: Calculation routines based on the FOCUS Kinetics Report (2006,    particular purpose.  Depends: R (>= 2.15.1), parallel  Imports: stats, graphics, methods, deSolve, R6, inline (>= 0.3.17), numDeriv, -  lmtest, pkgbuild, nlme (>= 3.1-151), purrr, saemix (>= 3.1.9000) +  lmtest, pkgbuild, nlme (>= 3.1-151), purrr  Suggests: knitr, rbenchmark, tikzDevice, testthat, rmarkdown, covr, vdiffr, -  benchmarkme, tibble, stats4 +  benchmarkme, tibble, stats4, saemix (>= 3.1.9000) +Additional_repositories: https://jranke.github.io/drat  License: GPL  LazyLoad: yes  LazyData: yes @@ -1,28 +1,36 @@  # mkin 0.9.50.4 (unreleased) -- 'mixed.mmkin' New container for mmkin objects for plotting with the 'plot.mixed.mmkin' method +## General new features  - 'mkinmod' models gain arguments 'name' and 'dll_dir' which, in conjunction with a current version of the 'inline' package, make it possible to still use the DLL used for fast ODE solutions with 'deSolve' after saving and restoring the 'mkinmod' object. -- 'f_norm_temp_focus' generic function to normalise time intervals using the FOCUS method, with methods for numeric vectors and 'mkindsg' objects -  - 'mkindsg' R6 class for groups of 'mkinds' datasets with metadata -- 'D24_2014' dataset +- 'f_norm_temp_focus' generic function to normalise time intervals using the FOCUS method, with methods for numeric vectors and 'mkindsg' objects + +- 'D24_2014' and 'dimethenamid_2018' datasets  - 'focus_soil_moisture' FOCUS default soil moisture data -- 'plot.mixed.mmkin' method used for 'nlme.mmkin' and 'saem.mmkin', both inheriting from 'mixed.mmkin' (currently virtual) - -- 'saem' generic function to fit saemix models, with a generator 'saem.mmkin', summary and plot methods +- 'update' method for 'mmkin' objects  - 'transform_odeparms', 'backtransform_odeparms': Use logit transformation for solitary fractions like the g parameter of the DFOP model, or formation fractions for a pathway to only one target variable -- 'update' method for 'mmkin' objects +## Mixed-effects models + +- 'mixed.mmkin' New container for mmkin objects for plotting with the 'plot.mixed.mmkin' method + +- 'plot.mixed.mmkin' method used for 'nlme.mmkin' and 'saem.mmkin', both inheriting from 'mixed.mmkin' (currently virtual)  - 'plot', 'summary' and 'print' methods for 'nlme.mmkin' objects -- 'saemix_model', 'saemix_data': Helper functions to fit nonlinear mixed-effects models for mmkin row objects using the saemix package +-  Add the current development version of the saemix package as a second, optional backend for mixed-effects models + +- DESCRIPTION: Additional_repositories entry pointing to my drat repository on github for a suitable saemix version + +- 'saemix_model', 'saemix_data': Helper functions to fit nonlinear mixed-effects models for mmkin row objects. + +- 'saem' generic function to fit saemix models using 'saemix_model' and 'saemix_data', with a generator 'saem.mmkin', summary and plot methods  # mkin 0.9.50.3 (2020-10-08) diff --git a/R/D24_2014.R b/R/D24_2014.R index 0a111e1c..1f2bcc04 100644 --- a/R/D24_2014.R +++ b/R/D24_2014.R @@ -23,6 +23,7 @@  #'   \url{http://registerofquestions.efsa.europa.eu/roqFrontend/outputLoader?output=ON-3812}  #' @examples  #' print(D24_2014) +#' \dontrun{  #' print(D24_2014$ds[[1]], data = TRUE)  #' m_D24 = mkinmod(D24 = mkinsub("SFO", to = "DCP"),  #'   DCP = mkinsub("SFO", to = "DCA"), @@ -32,4 +33,5 @@  #'   DCP = mkinsub("SFO", to = "DCA"),  #'   DCA = mkinsub("SFO"))  #' print(m_D24_2) +#' }  "D24_2014" @@ -10,7 +10,8 @@  * checking CRAN incoming feasibility ... Note_to_CRAN_maintainers  Maintainer: ‘Johannes Ranke <jranke@uni-bremen.de>’  * checking package namespace information ... OK -* checking package dependencies ... OK +* checking package dependencies ... NOTE +Package suggested but not available for checking: ‘saemix’  * checking if this is a source package ... OK  * checking if there is a namespace ... OK  * checking for executable files ... OK @@ -21,8 +22,7 @@ Maintainer: ‘Johannes Ranke <jranke@uni-bremen.de>’  * checking whether package ‘mkin’ can be installed ... OK  * checking installed package size ... OK  * checking package directory ... OK -* checking for future file timestamps ... NOTE -unable to verify current time +* checking for future file timestamps ... OK  * checking ‘build’ directory ... OK  * checking DESCRIPTION meta-information ... OK  * checking top-level files ... OK @@ -46,7 +46,8 @@ unable to verify current time  * checking Rd files ... OK  * checking Rd metadata ... OK  * checking Rd line widths ... OK -* checking Rd cross-references ... OK +* checking Rd cross-references ... NOTE +Package unavailable to check Rd xrefs: ‘saemix’  * checking for missing documentation entries ... OK  * checking for code/documentation mismatches ... OK  * checking Rd \usage sections ... OK @@ -57,7 +58,10 @@ unable to verify current time  * checking data for ASCII and uncompressed saves ... OK  * checking installed files from ‘inst/doc’ ... OK  * checking files in ‘vignettes’ ... OK -* checking examples ... OK +* checking examples ... NOTE +Examples with CPU (user + system) or elapsed time > 5s +          user system elapsed +D24_2014 1.808  3.425   0.986  * checking for unstated dependencies in ‘tests’ ... OK  * checking tests ... SKIPPED  * checking for unstated dependencies in vignettes ... OK @@ -68,7 +72,7 @@ unable to verify current time  * checking for detritus in the temp directory ... OK  * DONE -Status: 1 NOTE +Status: 3 NOTEs  See    ‘/home/jranke/git/mkin/mkin.Rcheck/00check.log’  for details. diff --git a/man/D24_2014.Rd b/man/D24_2014.Rd index 8d0e632c..1afa9596 100644 --- a/man/D24_2014.Rd +++ b/man/D24_2014.Rd @@ -36,6 +36,7 @@ specific pieces of information in the comments.  }  \examples{  print(D24_2014) +\dontrun{  print(D24_2014$ds[[1]], data = TRUE)  m_D24 = mkinmod(D24 = mkinsub("SFO", to = "DCP"),    DCP = mkinsub("SFO", to = "DCA"), @@ -46,4 +47,5 @@ m_D24_2 = mkinmod(D24 = mkinsub("DFOP", to = "DCP"),    DCA = mkinsub("SFO"))  print(m_D24_2)  } +}  \keyword{datasets} diff --git a/man/saem.Rd b/man/saem.Rd index 775a8e7b..969e9a22 100644 --- a/man/saem.Rd +++ b/man/saem.Rd @@ -57,7 +57,7 @@ automatic choice is not desired}  \item{control}{Passed to \link[saemix:saemix]{saemix::saemix}}  \item{verbose}{Should we print information about created objects of -type \link[saemix:SaemixModel-class]{saemix::SaemixModel} and \link[saemix:SaemixData-class]{saemix::SaemixData}?} +type \link[saemix:SaemixModel]{saemix::SaemixModel} and \link[saemix:SaemixData]{saemix::SaemixData}?}  \item{suppressPlot}{Should we suppress any plotting that is done  by the saemix function?} @@ -71,12 +71,12 @@ and the end of the optimisation process?}  }  \value{  An S3 object of class 'saem.mmkin', containing the fitted -\link[saemix:SaemixObject-class]{saemix::SaemixObject} as a list component named 'so'. The +\link[saemix:SaemixObject]{saemix::SaemixObject} as a list component named 'so'. The  object also inherits from 'mixed.mmkin'. -An \link[saemix:SaemixModel-class]{saemix::SaemixModel} object. +An \link[saemix:SaemixModel]{saemix::SaemixModel} object. -An \link[saemix:SaemixData-class]{saemix::SaemixData} object. +An \link[saemix:SaemixData]{saemix::SaemixData} object.  }  \description{  This function uses \code{\link[saemix:saemix]{saemix::saemix()}} as a backend for fitting nonlinear mixed diff --git a/man/summary.saem.mmkin.Rd b/man/summary.saem.mmkin.Rd index 67cb3cbb..4f83489c 100644 --- a/man/summary.saem.mmkin.Rd +++ b/man/summary.saem.mmkin.Rd @@ -27,7 +27,7 @@ included.}  \item{digits}{Number of digits to use for printing}  }  \value{ -The summary function returns a list based on the \link[saemix:SaemixObject-class]{saemix::SaemixObject} +The summary function returns a list based on the \link[saemix:SaemixObject]{saemix::SaemixObject}  obtained in the fit, with at least the following additional components  \item{saemixversion, mkinversion, Rversion}{The saemix, mkin and R versions used}  \item{date.fit, date.summary}{The dates where the fit and the summary were @@ -4,41 +4,47 @@ Testing mkin  ✔ |  OK F W S | Context  ✔ |   5       | AIC calculation  ✔ |   2       | Export dataset for reading into CAKE -✔ |  14       | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.0 s] +✔ |  14       | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.1 s]  ✔ |   4       | Calculation of FOCUS chi2 error levels [0.5 s] -✔ |   7       | Fitting the SFORB model [3.6 s] -✔ |   5       | Analytical solutions for coupled models [3.3 s] +✔ |   7       | Fitting the SFORB model [4.0 s] +✔ |   5       | Analytical solutions for coupled models [3.6 s]  ✔ |   5       | Calculation of Akaike weights -✔ |  14       | Confidence intervals and p-values [1.2 s] -✔ |  14       | Error model fitting [5.6 s] +✔ |  14       | Confidence intervals and p-values [1.4 s] +✔ |  14       | Error model fitting [6.8 s]  ✔ |   5       | Time step normalisation -✔ |   4       | Test fitting the decline of metabolites from their maximum [0.3 s] -✔ |   1       | Fitting the logistic model [0.2 s] -✔ |  33     1 | Nonlinear mixed effects models [28.7 s] +✔ |   4       | Test fitting the decline of metabolites from their maximum [0.5 s] +✔ |   1       | Fitting the logistic model [0.3 s] +✔ |   5     3 | Nonlinear mixed-effects models [0.1 s]  ──────────────────────────────────────────────────────────────────────────────── -Skip (test_mixed.R:143:3): saem results are reproducible for biphasic fits -Reason: Fitting with saemix takes around 10 minutes when using deSolve +Skip (test_mixed.R:4:3): Parent fits using saemix are correctly implemented +Reason: !saemix_available is TRUE + +Skip (test_mixed.R:94:3): Print methods work +Reason: !saemix_available is TRUE + +Skip (test_mixed.R:118:3): saem results are reproducible for biphasic fits +Reason: !saemix_available is TRUE  ────────────────────────────────────────────────────────────────────────────────  ✔ |   2       | Test dataset classes mkinds and mkindsg -✔ |   1       | mkinfit features [0.3 s] -✔ |  10       | Special cases of mkinfit calls [0.3 s] +✔ |   1       | mkinfit features [0.4 s] +✔ |  10       | Special cases of mkinfit calls [0.4 s]  ✔ |   8       | mkinmod model generation and printing [0.2 s]  ✔ |   3       | Model predictions with mkinpredict [0.4 s] -✔ |  16       | Evaluations according to 2015 NAFTA guidance [1.7 s] -✔ |   9       | Nonlinear mixed-effects models [8.2 s] -✔ |  16       | Plotting [1.9 s] +✔ |  16       | Evaluations according to 2015 NAFTA guidance [2.0 s] +✔ |   9       | Nonlinear mixed-effects models [9.3 s] +✔ |  14       | Plotting [2.0 s]  ✔ |   4       | Residuals extracted from mkinfit models -✔ |   2       | Complex test case from Schaefer et al. (2007) Piacenza paper [1.6 s] -✔ |   4       | Summary [0.1 s] +✔ |   2       | Complex test case from Schaefer et al. (2007) Piacenza paper [1.8 s] +✔ |   4       | Summary [0.2 s]  ✔ |   1       | Summaries of old mkinfit objects -✔ |   4       | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.3 s] -✔ |   9       | Hypothesis tests [7.3 s] -✔ |   4       | Calculation of maximum time weighted average concentrations (TWAs) [2.4 s] +✔ |   4       | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.5 s] +✔ |   9       | Hypothesis tests [7.9 s] +✔ |   4       | Calculation of maximum time weighted average concentrations (TWAs) [2.7 s]  ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 71.3 s +Duration: 48.3 s  ── Skipped tests  ────────────────────────────────────────────────────────────── -● Fitting with saemix takes around 10 minutes when using deSolve (1) +● !saemix_available is TRUE (3) -[ FAIL 0 | WARN 0 | SKIP 1 | PASS 206 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 176 ] diff --git a/test_dev.log b/test_dev.log index c57bb958..df159d1e 100644 --- a/test_dev.log +++ b/test_dev.log @@ -1,37 +1,62 @@  Loading mkin +Loading required package: parallel  Testing mkin  ✔ |  OK F W S | Context -✔ |   4       | AIC calculation +✔ |   5       | AIC calculation  ✔ |   2       | Export dataset for reading into CAKE -✔ |  14       | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.9 s] -✔ |   4       | Calculation of FOCUS chi2 error levels [0.4 s] -✔ |   7       | Fitting the SFORB model [3.1 s] -✔ |   5       | Analytical solutions for coupled models [2.8 s] +✔ |  14       | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.0 s] +✔ |   4       | Calculation of FOCUS chi2 error levels [0.5 s] +✔ |   7       | Fitting the SFORB model [3.4 s] +✔ |   5       | Analytical solutions for coupled models [3.1 s]  ✔ |   5       | Calculation of Akaike weights -✔ |  10       | Confidence intervals and p-values [0.9 s] -✔ |  14       | Error model fitting [3.8 s] +✔ |  14       | Confidence intervals and p-values [1.2 s] +✔ |  14       | Error model fitting [5.8 s] +✔ |   5       | Time step normalisation  ✔ |   4       | Test fitting the decline of metabolites from their maximum [0.3 s]  ✔ |   1       | Fitting the logistic model [0.2 s] -✔ |   1       | Test dataset class mkinds used in gmkin -✔ |   1       | mkinfit features [0.2 s] -✔ |  12       | Special cases of mkinfit calls [0.6 s] +✔ |   5     3 | Nonlinear mixed-effects models [0.1 s] +──────────────────────────────────────────────────────────────────────────────── +Skip (test_mixed.R:4:3): Parent fits using saemix are correctly implemented +Reason: !saemix_available  is TRUE + +Skip (test_mixed.R:94:3): Print methods work +Reason: !saemix_available  is TRUE + +Skip (test_mixed.R:118:3): saem results are reproducible for biphasic fits +Reason: !saemix_available  is TRUE +──────────────────────────────────────────────────────────────────────────────── +✔ |   2       | Test dataset classes mkinds and mkindsg +✔ |   1       | mkinfit features [0.3 s] +✔ |  10       | Special cases of mkinfit calls [0.3 s]  ✔ |   8       | mkinmod model generation and printing [0.2 s]  ✔ |   3       | Model predictions with mkinpredict [0.3 s] -✔ |  16       | Evaluations according to 2015 NAFTA guidance [1.3 s] -✔ |   9       | Nonlinear mixed-effects models [7.3 s] -✔ |  14       | Plotting [1.3 s] +✔ |  14     2 | Evaluations according to 2015 NAFTA guidance [2.2 s] +──────────────────────────────────────────────────────────────────────────────── +Skip (test_nafta.R:25:5): Test data from Appendix B are correctly evaluated +Reason: getRversion() >= "4.1.0"  is TRUE + +Skip (test_nafta.R:53:5): Test data from Appendix D are correctly evaluated +Reason: getRversion() >= "4.1.0"  is TRUE +──────────────────────────────────────────────────────────────────────────────── +✔ |   9       | Nonlinear mixed-effects models [7.9 s] +✔ |   0     1 | Plotting [0.7 s] +──────────────────────────────────────────────────────────────────────────────── +Skip (test_plot.R:18:3): Plotting mkinfit, mmkin and mixed model objects is reproducible +Reason: getRversion() >= "4.1.0"  is TRUE +────────────────────────────────────────────────────────────────────────────────  ✔ |   4       | Residuals extracted from mkinfit models  ✔ |   2       | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4 s] -✔ |   4       | Summary +✔ |   4       | Summary [0.1 s]  ✔ |   1       | Summaries of old mkinfit objects -✔ |   4       | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.0 s] -✔ |   9       | Hypothesis tests [7.4 s] -✔ |   4       | Calculation of maximum time weighted average concentrations (TWAs) [2.2 s] +✔ |   4       | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2 s] +✔ |   9       | Hypothesis tests [7.7 s] +✔ |   4       | Calculation of maximum time weighted average concentrations (TWAs) [2.0 s]  ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 36.9 s +Duration: 41.2 s + +── Skipped tests  ────────────────────────────────────────────────────────────── +● !saemix_available  is TRUE (3) +● getRversion() >= "4.1.0"  is TRUE (3) -OK:       162 -Failed:   0 -Warnings: 0 -Skipped:  0 +[ FAIL 0 | WARN 0 | SKIP 6 | PASS 160 ] diff --git a/tests/testthat/print_mmkin_biphasic_mixed.txt b/tests/testthat/print_mmkin_biphasic_mixed.txt index 3d92b120..11e11bfc 100644 --- a/tests/testthat/print_mmkin_biphasic_mixed.txt +++ b/tests/testthat/print_mmkin_biphasic_mixed.txt @@ -21,6 +21,6 @@ OK: No warnings  Mean fitted parameters:         parent_0        log_k_m1 f_parent_qlogis          log_k1          log_k2  -        100.700          -6.299          -0.078          -3.094          -3.954  +        100.702          -5.347          -0.078          -2.681          -4.366          g_qlogis  -          0.027  +         -0.335  diff --git a/tests/testthat/print_nlme_biphasic.txt b/tests/testthat/print_nlme_biphasic.txt index 98895d3a..f86bda76 100644 --- a/tests/testthat/print_nlme_biphasic.txt +++ b/tests/testthat/print_nlme_biphasic.txt @@ -11,19 +11,19 @@ d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g)  Data:  509 observations of 2 variable(s) grouped in 15 datasets -Log-likelihood: -1343 +Log-likelihood: -1329  Fixed effects:   list(parent_0 ~ 1, log_k_m1 ~ 1, f_parent_qlogis ~ 1, log_k1 ~ 1,      log_k2 ~ 1, g_qlogis ~ 1)          parent_0        log_k_m1 f_parent_qlogis          log_k1          log_k2  -         100.37           -6.23           -0.08           -3.22           -4.10  +         100.43           -5.34           -0.08           -2.90           -4.34          g_qlogis  -          -0.10  +          -0.19   Random effects:   Formula: list(parent_0 ~ 1, log_k_m1 ~ 1, f_parent_qlogis ~ 1, log_k1 ~ 1,      log_k2 ~ 1, g_qlogis ~ 1)   Level: ds   Structure: Diagonal          parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2 g_qlogis Residual -StdDev:        1    2e-04             0.3    0.7    0.8      0.3        3 +StdDev:        1      0.1             0.3    0.6    0.5      0.3        3 diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index fd9635d1..2071e05c 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -156,7 +156,7 @@ DFOP_SFO <- mkinmod(    m1 = mkinsub("SFO"),    quiet = TRUE)  dfop_sfo_pop <- list(parent_0 = 100, -  k_m1 = 0.002, f_parent_to_m1 = 0.5, +  k_m1 = 0.005, f_parent_to_m1 = 0.5,    k1 = 0.05, k2 = 0.01, g = 0.5)  syn_biphasic_parms <- as.matrix(data.frame(    k1 = rlnorm(n_biphasic, log(dfop_sfo_pop$k1), log_sd), @@ -178,19 +178,27 @@ ds_biphasic <- lapply(ds_biphasic_mean, function(ds) {  })  # Mixed model fits -mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc") -sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix") +saemix_available <- FALSE +if (requireNamespace("saemix", quietly = TRUE)) { +  if(packageVersion("saemix") > "3.1.9000") saemix_available <- TRUE +} +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_biphasic <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_biphasic, quiet = TRUE, cores = n_cores) +mmkin_biphasic_mixed <- mixed(mmkin_biphasic) -mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE) -dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin") -dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix")  dfop_nlme_1 <- nlme(mmkin_dfop_1) - -mmkin_biphasic <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_biphasic, quiet = TRUE) -mmkin_biphasic_mixed <- mixed(mmkin_biphasic)  nlme_biphasic <- nlme(mmkin_biphasic) -saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE) -saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE) + +if (saemix_available) { +  sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix") + +  dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin") +  dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix") + +  saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE) +  saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE) +}  ds_uba <- lapply(experimental_data_for_UBA_2019[6:10],    function(x) subset(x$data[c("name", "time", "value")])) @@ -200,7 +208,10 @@ sfo_sfo_uba <- mkinmod(parent = mkinsub("SFO", "A1"),  dfop_sfo_uba <- mkinmod(parent = mkinsub("DFOP", "A1"),    A1 = mkinsub("SFO"), quiet = TRUE)  f_uba_mmkin <- mmkin(list("SFO-SFO" = sfo_sfo_uba, "DFOP-SFO" = dfop_sfo_uba), -  ds_uba, quiet = TRUE) +  ds_uba, quiet = TRUE, cores = n_cores)  f_uba_dfop_sfo_mixed <- mixed(f_uba_mmkin[2, ]) -f_uba_sfo_sfo_saem <- saem(f_uba_mmkin["SFO-SFO", ], quiet = TRUE, transformations = "saemix") -f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix") + +if (saemix_available) { +  f_uba_sfo_sfo_saem <- saem(f_uba_mmkin["SFO-SFO", ], quiet = TRUE, transformations = "saemix") +  f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix") +} diff --git a/tests/testthat/summary_nlme_biphasic_s.txt b/tests/testthat/summary_nlme_biphasic_s.txt index f9171748..65aead62 100644 --- a/tests/testthat/summary_nlme_biphasic_s.txt +++ b/tests/testthat/summary_nlme_biphasic_s.txt @@ -17,15 +17,15 @@ Data:  Model predictions using solution type analytical  -Fitted in test time 0 s using 2 iterations +Fitted in test time 0 s using 3 iterations  Variance model: Constant variance   Mean of starting values for individual parameters:         parent_0        log_k_m1 f_parent_qlogis          log_k1          log_k2  -         100.70           -6.30           -0.08           -3.09           -3.95  +         100.70           -5.35           -0.08           -2.68           -4.37          g_qlogis  -           0.03  +          -0.33   Fixed degradation parameter values:       value  type @@ -34,40 +34,40 @@ m1_0     0 state  Results:     AIC  BIC logLik -  2711 2766  -1343 +  2683 2738  -1329  Optimised, transformed parameters with symmetric confidence intervals:                  lower   est.  upper -parent_0         99.5 100.37 101.23 -log_k_m1         -6.5  -6.23  -5.94 -f_parent_qlogis  -0.2  -0.08   0.08 -log_k1           -3.6  -3.22  -2.84 -log_k2           -4.5  -4.10  -3.68 -g_qlogis         -0.4  -0.10   0.17 +parent_0         99.6 100.43 101.26 +log_k_m1         -5.5  -5.34  -5.18 +f_parent_qlogis  -0.3  -0.08   0.09 +log_k1           -3.2  -2.90  -2.60 +log_k2           -4.6  -4.34  -4.07 +g_qlogis         -0.5  -0.19   0.08  Correlation:                   prnt_0 lg_k_1 f_prn_ log_k1 log_k2 -log_k_m1        -0.185                             -f_parent_qlogis -0.161  0.405                      -log_k1           0.056 -0.014 -0.016               -log_k2           0.025  0.011 -0.004  0.026        -g_qlogis        -0.032 -0.046 -0.012 -0.109 -0.103 +log_k_m1        -0.177                             +f_parent_qlogis -0.164  0.385                      +log_k1           0.108 -0.017 -0.025               +log_k2           0.036  0.054  0.008  0.096        +g_qlogis        -0.068 -0.110 -0.030 -0.269 -0.267  Random effects:   Formula: list(parent_0 ~ 1, log_k_m1 ~ 1, f_parent_qlogis ~ 1, log_k1 ~ 1,      log_k2 ~ 1, g_qlogis ~ 1)   Level: ds   Structure: Diagonal          parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2 g_qlogis Residual -StdDev:        1    2e-04             0.3    0.7    0.8      0.3        3 +StdDev:        1      0.1             0.3    0.6    0.5      0.3        3  Backtransformed parameters with asymmetric confidence intervals:                 lower  est. upper  parent_0       1e+02 1e+02 1e+02 -k_m1           1e-03 2e-03 3e-03 +k_m1           4e-03 5e-03 6e-03  f_parent_to_m1 4e-01 5e-01 5e-01 -k1             3e-02 4e-02 6e-02 -k2             1e-02 2e-02 3e-02 +k1             4e-02 6e-02 7e-02 +k2             1e-02 1e-02 2e-02  g              4e-01 5e-01 5e-01  Resulting formation fractions: @@ -77,5 +77,5 @@ parent_sink 0.5  Estimated disappearance times:         DT50 DT90 DT50back DT50_k1 DT50_k2 -parent   27  105       31      17      42 -m1      352 1171       NA      NA      NA +parent   26  131       39      13      53 +m1      144  479       NA      NA      NA diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R index 2a1ffcc1..c11f6712 100644 --- a/tests/testthat/test_error_models.R +++ b/tests/testthat/test_error_models.R @@ -56,6 +56,7 @@ test_that("The default error model algorithm finds the best known AIC values for    f_tc_exp_d_3 <- mmkin(c("SFO", "DFOP", "HS"),      lapply(experimental_data_for_UBA_2019, function(x) x$data),      error_model = "tc", +    cores = n_cores,      quiet = TRUE)    AIC_exp_d_3 <- lapply(f_tc_exp_d_3, AIC) diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 1e96c338..e9af10e6 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -1,6 +1,8 @@  context("Nonlinear mixed-effects models") -test_that("Parent only models can be fitted using nonlinear mixed effects models", { +test_that("Parent fits using saemix are correctly implemented", { +  skip_if(!saemix_available) +    expect_error(saem(fits), "Only row objects")    # Some fits were done in the setup script    mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100)) @@ -26,7 +28,7 @@ test_that("Parent only models can be fitted using nonlinear mixed effects models    expect_equal(round(s_sfo_s1$confint_back["k_parent", "est."], 3),      round(s_sfo_n$confint_back["k_parent", "est."], 3)) -  mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc") +  mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc", cores = n_cores)    fomc_saem_1 <- saem(mmkin_fomc_1, quiet = TRUE)    ci_fomc_s1 <- summary(fomc_saem_1)$confint_back @@ -66,7 +68,7 @@ test_that("Parent only models can be fitted using nonlinear mixed effects models    rel_diff_2 <- (s_dfop_s2$confint_back[, "est."] - dfop_pop) / dfop_pop    expect_true(all(rel_diff_2 < 0.12)) -  mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const") +  mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const", cores = n_cores)    hs_saem_1 <- saem(mmkin_hs_1, quiet = TRUE)    ci_hs_s1 <- summary(hs_saem_1)$confint_back @@ -88,10 +90,12 @@ test_that("Print methods work", {    expect_known_output(print(fits, digits = 2), "print_mmkin_parent.txt")    expect_known_output(print(mmkin_biphasic_mixed, digits = 2), "print_mmkin_biphasic_mixed.txt")    expect_known_output(print(nlme_biphasic, digits = 1), "print_nlme_biphasic.txt") + +  skip_if(!saemix_available)    expect_known_output(print(sfo_saem_1, digits = 1), "print_sfo_saem_1.txt")  }) -test_that("nlme results are reproducible", { +test_that("nlme results are reproducible to some degree", {    test_summary <- summary(nlme_biphasic)    test_summary$nlmeversion <- "Dummy 0.0 for testing" @@ -111,6 +115,7 @@ test_that("nlme results are reproducible", {  test_that("saem results are reproducible for biphasic fits", { +  skip_if(!saemix_available)    test_summary <- summary(saem_biphasic_s)    test_summary$saemixversion <- "Dummy 0.0 for testing"    test_summary$mkinversion <- "Dummy 0.0 for testing" diff --git a/tests/testthat/test_plot.R b/tests/testthat/test_plot.R index 75d401a3..1c95d069 100644 --- a/tests/testthat/test_plot.R +++ b/tests/testthat/test_plot.R @@ -35,8 +35,10 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", {    plot_biphasic_mmkin <- function() plot(f_uba_dfop_sfo_mixed)    vdiffr::expect_doppelganger("mixed model fit for mmkin object", plot_biphasic_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) +  if (saemix_available) { +    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) +  }    skip_on_travis() @@ -46,10 +48,12 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", {    #plot_biphasic_mmkin <- function() plot(mixed(mmkin_biphasic))    # 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) +  if (saemix_available) { +    #plot_biphasic_saem_s <- function() plot(saem_biphasic_s) +    plot_biphasic_saem_m <- function() plot(saem_biphasic_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_biphasic_saem_m) +  }    # different results when working with eigenvalues    plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE) | 
