From 48d9cad339394c3aa0d730d9a27b1c0680ce13e8 Mon Sep 17 00:00:00 2001 From: Ranke Johannes Date: Mon, 7 Sep 2026 13:45:39 +0200 Subject: Add DTx function, check and test The tolerance of one test had to be increased in test_deSolve.R, and four vdiffr snapshots with negligible differences were updated. Tests run with a maximum of 16 cores when running in the Agroscope Apptainer environment. --- DESCRIPTION | 6 +- NAMESPACE | 99 +++++---- NEWS.md | 8 +- R/endpoints.R | 79 ++++++- _pkgdown.yml | 1 + log/build.log | 4 +- log/check.log | 29 ++- log/test.log | 35 +-- man/DFOP.solution.Rd | 14 +- man/DTx.Rd | 26 +++ man/FOMC.solution.Rd | 14 +- man/HS.solution.Rd | 14 +- man/IORE.solution.Rd | 14 +- man/SFO.solution.Rd | 14 +- man/SFORB.solution.Rd | 14 +- man/anova.saem.mmkin.Rd | 2 +- man/logLik.saem.mmkin.Rd | 4 +- man/logistic.solution.Rd | 14 +- man/mkinds.Rd | 95 +++++---- man/mkindsg.Rd | 91 ++++---- man/reexports.Rd | 7 +- man/saem.Rd | 8 +- man/summary.saem.mmkin.Rd | 2 +- man/transform_odeparms.Rd | 2 +- .../_snaps/multistart/llhist-for-dfop-sfo-fit.svg | 34 +-- ...t-for-saem-object-with-mkin-transformations.svg | 148 ++++++------- .../_snaps/multistart/parplot-for-dfop-sfo-fit.svg | 236 ++++++++++----------- .../plot/mixed-model-fit-for-nlme-object.svg | 20 +- tests/testthat/print_dfop_saem_1.txt | 10 +- tests/testthat/setup_script.R | 7 +- tests/testthat/test_deSolve.R | 3 +- tests/testthat/test_endpoints.R | 49 +++++ 32 files changed, 645 insertions(+), 458 deletions(-) create mode 100644 man/DTx.Rd create mode 100644 tests/testthat/test_endpoints.R diff --git a/DESCRIPTION b/DESCRIPTION index 77b53a6d..ded3b27b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: mkin Type: Package Title: Kinetic Evaluation of Chemical Degradation Data -Version: 1.2.10 -Date: 2025-09-12 +Version: 1.2.11 +Date: 2026-09-07 Authors@R: c( person("Johannes", "Ranke", role = c("aut", "cre", "cph"), email = "johannes.ranke@jrwb.de", @@ -35,4 +35,4 @@ VignetteBuilder: knitr BugReports: https://github.com/jranke/mkin/issues/ URL: https://pkgdown.jrwb.de/mkin/ Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.3 +Config/roxygen2/version: 8.1.0 diff --git a/NAMESPACE b/NAMESPACE index 5b9a1c85..445a3649 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -83,6 +83,7 @@ S3method(update,saem.mmkin) S3method(which.best,default) export(CAKE_export) export(DFOP.solution) +export(DTx) export(FOMC.solution) export(HS.solution) export(IORE.solution) @@ -155,49 +156,59 @@ import(nlme) importFrom(R6,R6Class) importFrom(grDevices,dev.cur) importFrom(lmtest,lrtest) -importFrom(methods,is) -importFrom(methods,signature) -importFrom(nlme,intervals) -importFrom(nlme,nlme) -importFrom(parallel,detectCores) -importFrom(parallel,mclapply) -importFrom(parallel,parLapply) +importFrom(methods, + is, + signature +) +importFrom(nlme, + intervals, + nlme +) +importFrom(parallel, + detectCores, + mclapply, + parLapply +) importFrom(rlang,"!!!") importFrom(saemix,saemix) -importFrom(stats,AIC) -importFrom(stats,BIC) -importFrom(stats,aggregate) -importFrom(stats,anova) -importFrom(stats,as.formula) -importFrom(stats,coef) -importFrom(stats,coefficients) -importFrom(stats,cov2cor) -importFrom(stats,dist) -importFrom(stats,dnorm) -importFrom(stats,lm) -importFrom(stats,logLik) -importFrom(stats,median) -importFrom(stats,na.fail) -importFrom(stats,nlminb) -importFrom(stats,nobs) -importFrom(stats,optimize) -importFrom(stats,pchisq) -importFrom(stats,plogis) -importFrom(stats,predict) -importFrom(stats,pt) -importFrom(stats,qchisq) -importFrom(stats,qf) -importFrom(stats,qlogis) -importFrom(stats,qnorm) -importFrom(stats,qt) -importFrom(stats,quantile) -importFrom(stats,residuals) -importFrom(stats,rnorm) -importFrom(stats,shapiro.test) -importFrom(stats,terms) -importFrom(stats,update) -importFrom(stats,vcov) -importFrom(utils,capture.output) -importFrom(utils,getFromNamespace) -importFrom(utils,packageVersion) -importFrom(utils,write.table) +importFrom(stats, + AIC, + BIC, + aggregate, + anova, + as.formula, + coef, + coefficients, + cov2cor, + dist, + dnorm, + lm, + logLik, + median, + na.fail, + nlminb, + nobs, + optimize, + pchisq, + plogis, + predict, + pt, + qchisq, + qf, + qlogis, + qnorm, + qt, + quantile, + residuals, + rnorm, + shapiro.test, + terms, + update, + vcov +) +importFrom(utils, + capture.output, + getFromNamespace, + packageVersion, + write.table +) diff --git a/NEWS.md b/NEWS.md index 82f6aa4d..bbdc1b29 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,10 @@ -# mkin 1.2.10 (unreleased) +# mkin 1.2.11 (unreleased) + +## New features + +- 'R/endpoints.R': Introduce the function `DTx` that makes it easy to calculate various types of DTx values such as DT50, DT90 and pseudo-half-lives calculated from DT90 or from the slow phase of biphasic models. + +# mkin 1.2.10 (2025-05-13) ## New features diff --git a/R/endpoints.R b/R/endpoints.R index 70a9eef3..fd5ecec1 100644 --- a/R/endpoints.R +++ b/R/endpoints.R @@ -158,7 +158,7 @@ endpoints <- function(fit, covariates = NULL, covariate_quantile = 0.5) { silent = TRUE) if (inherits(DT50, "try-error")) DT50 = NA if (inherits(DT90, "try-error")) DT90 = NA - DT50_back = DT90 / (log(10)/log(2)) # Backcalculated DT50 as recommended in FOCUS 2011 + DT50_back = DT90 / (log(10)/log(2)) ep$distimes[obs_var, c("DT50back")] = DT50_back ep$distimes[obs_var, c("DT50_k1")] = DT50_k1 @@ -177,7 +177,7 @@ endpoints <- function(fit, covariates = NULL, covariate_quantile = 0.5) { } DT50 <- DTx(50) DT90 <- DTx(90) - DT50_back = DT90 / (log(10)/log(2)) # Backcalculated DT50 as recommended in FOCUS 2011 + DT50_back = DT90 / (log(10)/log(2)) DT50_k1 = log(2)/k1 DT50_k2 = log(2)/k2 ep$distimes[obs_var, c("DT50back")] = DT50_back @@ -254,3 +254,78 @@ endpoints <- function(fit, covariates = NULL, covariate_quantile = 0.5) { if (length(ep$SFORB) == 0) ep$SFORB <- NULL return(ep) } + +#' Calculate DTx from parameters of parent degradation models +#' +#' @param type Character string specifying the degradation model +#' @param parms Named numeric vector giving the kinetic parameters +#' @param exact Should we used log(10)/log(2) instead of the widely used value +#' of 3.32 for backcalculation of DT50 values from DT90 values? +#' @export +#' @examples +#' # Check what type of DT50 is given in the bixafen EFSA conclusion from 2012 on p. 42 +#' DTx("HS", parms = c(k1 = 0.0081, k2 = 0.00023, tb = 53)) +#' # We get 1200 days for the time the concentration reaches 50%, the value of 1235 +#' # was likely based on more digits for the parameters. The half-life corresponding +#' # to the slow phase is around 3000 days +DTx <- function(type = c("SFO", "FOMC", "DFOP", "HS", "SFORB"), parms, exact = FALSE) { + type <- match.arg(type) + backcalculation_factor <- if (exact) log(10)/log(2) else 3.32 + + if (type == "SFO") { + DT50 <- log(2)/parms[["k"]] + DT90 <- log(10)/parms[["k"]] + return(c(DT50 = DT50, DT90 = DT90)) + } + if (type == "FOMC") { + alpha = parms[["alpha"]] + beta = parms[["beta"]] + DT50 = beta * (2^(1/alpha) - 1) + DT90 = beta * (10^(1/alpha) - 1) + DT50_back = DT90 / backcalculation_factor + return(c(DT50 = DT50, DT90 = DT90, DT50back = DT50_back)) + } + if (type == "DFOP") { + k1 = parms[["k1"]] + k2 = parms[["k2"]] + g = parms[["g"]] + + f <- function(log_t, x) { + t <- exp(log_t) + fraction <- g * exp( - k1 * t) + (1 - g) * exp( - k2 * t) + (fraction - (1 - x/100))^2 + } + + DT50_k1 = log(2)/k1 + DT50_k2 = log(2)/k2 + DT90_k1 = log(10)/k1 + DT90_k2 = log(10)/k2 + + DT50 <- try(exp(optimize(f, c(log(DT50_k1), log(DT50_k2)), x=50)$minimum), + silent = TRUE) + DT90 <- try(exp(optimize(f, c(log(DT90_k1), log(DT90_k2)), x=90)$minimum), + silent = TRUE) + if (inherits(DT50, "try-error")) DT50 = NA + if (inherits(DT90, "try-error")) DT90 = NA + DT50_back = DT90 / backcalculation_factor + return(c(DT50 = DT50, DT90 = DT90, DT50back = DT50_back, DT50_k1 = DT50_k1, DT50_k2 = DT50_k2)) + } + if (type == "HS") { + k1 = parms[["k1"]] + k2 = parms[["k2"]] + tb = parms[["tb"]] + DTx <- function(x) { + DTx.a <- (log(100/(100 - x)))/k1 + DTx.b <- tb + (log(100/(100 - x)) - k1 * tb)/k2 + if (DTx.a < tb) DTx <- DTx.a + else DTx <- DTx.b + return(DTx) + } + DT50 <- DTx(50) + DT90 <- DTx(90) + DT50_back = DT90 / backcalculation_factor + DT50_k1 = log(2)/k1 + DT50_k2 = log(2)/k2 + return(c(DT50 = DT50, DT90 = DT90, DT50back = DT50_back, DT50_k1 = DT50_k1, DT50_k2 = DT50_k2)) + } +} diff --git a/_pkgdown.yml b/_pkgdown.yml index a88e9cde..ebbe078b 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -94,6 +94,7 @@ reference: - plot.nafta - title: Utility functions contents: + - DTx - summary_listing - f_time_norm_focus - set_nd_nq diff --git a/log/build.log b/log/build.log index b2206986..0d9a46de 100644 --- a/log/build.log +++ b/log/build.log @@ -1,10 +1,10 @@ * checking for file ‘./DESCRIPTION’ ... OK * preparing ‘mkin’: * checking DESCRIPTION meta-information ... OK -* installing the package to build vignettes +* installing the package (it is needed to build vignettes) * creating vignettes ... OK * checking for LF line-endings in source and make files and shell scripts * checking for empty or unneeded directories Removed empty directory ‘mkin/vignettes/web_only’ -* building ‘mkin_1.2.10.tar.gz’ +* building ‘mkin_1.2.11.tar.gz’ diff --git a/log/check.log b/log/check.log index 7f212453..575e96c3 100644 --- a/log/check.log +++ b/log/check.log @@ -1,15 +1,16 @@ -* using log directory ‘/home/jranke/git/mkin/mkin.Rcheck’ -* using R version 4.5.1 (2025-06-13) +* using log directory ‘/home/f80868656/projects/mkin/mkin.Rcheck’ +* using R version 4.6.1 (2026-06-24) * using platform: x86_64-pc-linux-gnu * R was compiled by - gcc (Debian 12.2.0-14+deb12u1) 12.2.0 - GNU Fortran (Debian 12.2.0-14+deb12u1) 12.2.0 -* running under: Debian GNU/Linux 13 (trixie) + gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 + GNU Fortran (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0 +* running under: Ubuntu 24.04.4 LTS * using session charset: UTF-8 +* current time: 2026-09-07 10:01:19 UTC * using options ‘--no-tests --as-cran’ * checking for file ‘mkin/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘mkin’ version ‘1.2.10’ +* this is package ‘mkin’ version ‘1.2.11’ * package encoding: UTF-8 * checking CRAN incoming feasibility ... OK * checking package namespace information ... OK @@ -43,7 +44,7 @@ * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK -* checking R code for possible problems ... OK +* checking R code for possible problems ... [24s/15s] OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd line widths ... OK @@ -60,17 +61,23 @@ * checking sizes of PDF files under ‘inst/doc’ ... OK * checking installed files from ‘inst/doc’ ... OK * checking files in ‘vignettes’ ... OK -* checking examples ... [12s/12s] OK +* checking examples ... [37s/21s] OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... SKIPPED * checking for unstated dependencies in vignettes ... OK * checking package vignettes ... OK -* checking re-building of vignette outputs ... [15s/11s] OK +* checking re-building of vignette outputs ... [30s/19s] OK * checking PDF version of manual ... OK -* checking HTML version of manual ... OK +* checking HTML version of manual ... NOTE +Skipping checking HTML validation: no command 'tidy' found. +Please obtain a recent version of HTML Tidy by downloading a binary +release or compiling the source code from . * checking for non-standard things in the check directory ... OK * checking for detritus in the temp directory ... OK * DONE -Status: OK +Status: 1 NOTE +See + ‘/home/f80868656/projects/mkin/mkin.Rcheck/00check.log’ +for details. diff --git a/log/test.log b/log/test.log index e1726492..33ee7dfd 100644 --- a/log/test.log +++ b/log/test.log @@ -1,44 +1,45 @@ ℹ Testing mkin ✔ | F W S OK | Context ✔ | 5 | AIC calculation -✔ | 5 | Analytical solutions for coupled models [1.6s] +✔ | 5 | Analytical solutions for coupled models [2.8s] ✔ | 5 | Calculation of Akaike weights ✔ | 3 | Export dataset for reading into CAKE -✔ | 6 | Use of precompiled symbols in mkinpredict [3.7s] +✔ | 6 | Use of precompiled symbols in mkinpredict [4.7s] ✔ | 12 | Confidence intervals and p-values ✔ | 1 | Solutions with deSolve -✔ | 1 12 | Dimethenamid data from 2018 [14.0s] -✔ | 14 | Error model fitting [2.7s] +✔ | 1 12 | Dimethenamid data from 2018 [24.3s] +✔ | 4 | DTx calculations +✔ | 14 | Error model fitting [4.0s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels ✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) ✔ | 4 | Test fitting the decline of metabolites from their maximum ✔ | 1 | Fitting the logistic model -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [20.5s] -✔ | 2 20 | Nonlinear mixed-effects models [142.6s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [37.9s] +✔ | 2 20 | Nonlinear mixed-effects models [283.3s] ✔ | 3 | Test dataset classes mkinds and mkindsg ✔ | 10 | Special cases of mkinfit calls ✔ | 3 | mkinfit features ✔ | 8 | mkinmod model generation and printing ✔ | 4 | Model predictions with mkinpredict -✔ | 12 | Multistart method for saem.mmkin models [23.8s] -✔ | 16 | Evaluations according to 2015 NAFTA guidance [1.5s] -✔ | 9 | Nonlinear mixed-effects models with nlme [4.0s] -✔ | 15 | Plotting [4.9s] +✔ | 12 | Multistart method for saem.mmkin models [41.8s] +✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.6s] +✔ | 9 | Nonlinear mixed-effects models with nlme [7.6s] +✔ | 15 | Plotting [9.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 38 | saemix parent models [36.1s] +✔ | 1 38 | saemix parent models [66.6s] ✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [1.7s] +✔ | 10 | Fitting the SFORB model [3.0s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) -✔ | 9 | Hypothesis tests [2.8s] -✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [1.5s] +✔ | 9 | Hypothesis tests [5.3s] +✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [1.5s] ✔ | 2 | water-sediment ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 265.7 s +Duration: 503.1 s ── Skipped tests (4) ─────────────────────────────────────────────────────────── • Fitting this ODE model with saemix takes about 5 minutes on my new system @@ -49,4 +50,4 @@ Duration: 265.7 s • This still takes almost 2.5 minutes although we do not solve ODEs (1): 'test_saemix_parent.R:143:3' -[ FAIL 0 | WARN 0 | SKIP 4 | PASS 291 ] +[ FAIL 0 | WARN 0 | SKIP 4 | PASS 295 ] diff --git a/man/DFOP.solution.Rd b/man/DFOP.solution.Rd index d8c4553e..61089081 100644 --- a/man/DFOP.solution.Rd +++ b/man/DFOP.solution.Rd @@ -43,12 +43,12 @@ Version 1.1, 18 December 2014 \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics} } \seealso{ -Other parent solutions: -\code{\link{FOMC.solution}()}, -\code{\link{HS.solution}()}, -\code{\link{IORE.solution}()}, -\code{\link{SFO.solution}()}, -\code{\link{SFORB.solution}()}, -\code{\link{logistic.solution}()} +Other parent solutions: +\code{\link[=FOMC.solution]{FOMC.solution()}}, +\code{\link[=HS.solution]{HS.solution()}}, +\code{\link[=IORE.solution]{IORE.solution()}}, +\code{\link[=SFO.solution]{SFO.solution()}}, +\code{\link[=SFORB.solution]{SFORB.solution()}}, +\code{\link[=logistic.solution]{logistic.solution()}} } \concept{parent solutions} diff --git a/man/DTx.Rd b/man/DTx.Rd new file mode 100644 index 00000000..67dba5d6 --- /dev/null +++ b/man/DTx.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/endpoints.R +\name{DTx} +\alias{DTx} +\title{Calculate DTx from parameters of parent degradation models} +\usage{ +DTx(type = c("SFO", "FOMC", "DFOP", "HS", "SFORB"), parms, exact = FALSE) +} +\arguments{ +\item{type}{Character string specifying the degradation model} + +\item{parms}{Named numeric vector giving the kinetic parameters} + +\item{exact}{Should we used log(10)/log(2) instead of the widely used value +of 3.32 for backcalculation of DT50 values from DT90 values?} +} +\description{ +Calculate DTx from parameters of parent degradation models +} +\examples{ +# Check what type of DT50 is given in the bixafen EFSA conclusion from 2012 on p. 42 +DTx("HS", parms = c(k1 = 0.0081, k2 = 0.00023, tb = 53)) +# We get 1200 days for the time the concentration reaches 50\%, the value of 1235 +# was likely based on more digits for the parameters. The half-life corresponding +# to the slow phase is around 3000 days +} diff --git a/man/FOMC.solution.Rd b/man/FOMC.solution.Rd index d645113c..456b406f 100644 --- a/man/FOMC.solution.Rd +++ b/man/FOMC.solution.Rd @@ -56,12 +56,12 @@ A new model based on spatial variability. \emph{Environmental Science and Technology} \bold{24}, 1032-1038 } \seealso{ -Other parent solutions: -\code{\link{DFOP.solution}()}, -\code{\link{HS.solution}()}, -\code{\link{IORE.solution}()}, -\code{\link{SFO.solution}()}, -\code{\link{SFORB.solution}()}, -\code{\link{logistic.solution}()} +Other parent solutions: +\code{\link[=DFOP.solution]{DFOP.solution()}}, +\code{\link[=HS.solution]{HS.solution()}}, +\code{\link[=IORE.solution]{IORE.solution()}}, +\code{\link[=SFO.solution]{SFO.solution()}}, +\code{\link[=SFORB.solution]{SFORB.solution()}}, +\code{\link[=logistic.solution]{logistic.solution()}} } \concept{parent solutions} diff --git a/man/HS.solution.Rd b/man/HS.solution.Rd index 2940e949..9390a2e9 100644 --- a/man/HS.solution.Rd +++ b/man/HS.solution.Rd @@ -44,12 +44,12 @@ Version 1.1, 18 December 2014 \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics} } \seealso{ -Other parent solutions: -\code{\link{DFOP.solution}()}, -\code{\link{FOMC.solution}()}, -\code{\link{IORE.solution}()}, -\code{\link{SFO.solution}()}, -\code{\link{SFORB.solution}()}, -\code{\link{logistic.solution}()} +Other parent solutions: +\code{\link[=DFOP.solution]{DFOP.solution()}}, +\code{\link[=FOMC.solution]{FOMC.solution()}}, +\code{\link[=IORE.solution]{IORE.solution()}}, +\code{\link[=SFO.solution]{SFO.solution()}}, +\code{\link[=SFORB.solution]{SFORB.solution()}}, +\code{\link[=logistic.solution]{logistic.solution()}} } \concept{parent solutions} diff --git a/man/IORE.solution.Rd b/man/IORE.solution.Rd index 5d0126a7..9909e87c 100644 --- a/man/IORE.solution.Rd +++ b/man/IORE.solution.Rd @@ -49,12 +49,12 @@ NAFTA Technical Working Group on Pesticides (not dated) Guidance for Evaluating and Calculating Degradation Kinetics in Environmental Media } \seealso{ -Other parent solutions: -\code{\link{DFOP.solution}()}, -\code{\link{FOMC.solution}()}, -\code{\link{HS.solution}()}, -\code{\link{SFO.solution}()}, -\code{\link{SFORB.solution}()}, -\code{\link{logistic.solution}()} +Other parent solutions: +\code{\link[=DFOP.solution]{DFOP.solution()}}, +\code{\link[=FOMC.solution]{FOMC.solution()}}, +\code{\link[=HS.solution]{HS.solution()}}, +\code{\link[=SFO.solution]{SFO.solution()}}, +\code{\link[=SFORB.solution]{SFORB.solution()}}, +\code{\link[=logistic.solution]{logistic.solution()}} } \concept{parent solutions} diff --git a/man/SFO.solution.Rd b/man/SFO.solution.Rd index c0aac237..f76837e8 100644 --- a/man/SFO.solution.Rd +++ b/man/SFO.solution.Rd @@ -37,12 +37,12 @@ Version 1.1, 18 December 2014 \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics} } \seealso{ -Other parent solutions: -\code{\link{DFOP.solution}()}, -\code{\link{FOMC.solution}()}, -\code{\link{HS.solution}()}, -\code{\link{IORE.solution}()}, -\code{\link{SFORB.solution}()}, -\code{\link{logistic.solution}()} +Other parent solutions: +\code{\link[=DFOP.solution]{DFOP.solution()}}, +\code{\link[=FOMC.solution]{FOMC.solution()}}, +\code{\link[=HS.solution]{HS.solution()}}, +\code{\link[=IORE.solution]{IORE.solution()}}, +\code{\link[=SFORB.solution]{SFORB.solution()}}, +\code{\link[=logistic.solution]{logistic.solution()}} } \concept{parent solutions} diff --git a/man/SFORB.solution.Rd b/man/SFORB.solution.Rd index dc78d1f1..817e9788 100644 --- a/man/SFORB.solution.Rd +++ b/man/SFORB.solution.Rd @@ -47,12 +47,12 @@ Version 1.1, 18 December 2014 \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics} } \seealso{ -Other parent solutions: -\code{\link{DFOP.solution}()}, -\code{\link{FOMC.solution}()}, -\code{\link{HS.solution}()}, -\code{\link{IORE.solution}()}, -\code{\link{SFO.solution}()}, -\code{\link{logistic.solution}()} +Other parent solutions: +\code{\link[=DFOP.solution]{DFOP.solution()}}, +\code{\link[=FOMC.solution]{FOMC.solution()}}, +\code{\link[=HS.solution]{HS.solution()}}, +\code{\link[=IORE.solution]{IORE.solution()}}, +\code{\link[=SFO.solution]{SFO.solution()}}, +\code{\link[=logistic.solution]{logistic.solution()}} } \concept{parent solutions} diff --git a/man/anova.saem.mmkin.Rd b/man/anova.saem.mmkin.Rd index 34711c41..59c6754e 100644 --- a/man/anova.saem.mmkin.Rd +++ b/man/anova.saem.mmkin.Rd @@ -19,7 +19,7 @@ \item{method}{Method for likelihood calculation: "is" (importance sampling), "lin" (linear approximation), or "gq" (Gaussian quadrature). Passed -to \link[saemix:logLik]{saemix::logLik.SaemixObject}} +to \link[saemix:logLik.SaemixObject]{saemix::logLik.SaemixObject}} \item{test}{Should a likelihood ratio test be performed? If TRUE, the alternative models are tested against the first model. Should diff --git a/man/logLik.saem.mmkin.Rd b/man/logLik.saem.mmkin.Rd index bd0bb72e..e3a29ad2 100644 --- a/man/logLik.saem.mmkin.Rd +++ b/man/logLik.saem.mmkin.Rd @@ -9,9 +9,9 @@ \arguments{ \item{object}{The fitted \link{saem.mmkin} object} -\item{\dots}{Passed to \link[saemix:logLik]{saemix::logLik.SaemixObject}} +\item{\dots}{Passed to \link[saemix:logLik.SaemixObject]{saemix::logLik.SaemixObject}} -\item{method}{Passed to \link[saemix:logLik]{saemix::logLik.SaemixObject}} +\item{method}{Passed to \link[saemix:logLik.SaemixObject]{saemix::logLik.SaemixObject}} } \description{ logLik method for saem.mmkin objects diff --git a/man/logistic.solution.Rd b/man/logistic.solution.Rd index 22944098..137043d9 100644 --- a/man/logistic.solution.Rd +++ b/man/logistic.solution.Rd @@ -78,12 +78,12 @@ Version 1.1, 18 December 2014 \url{http://esdac.jrc.ec.europa.eu/projects/degradation-kinetics} } \seealso{ -Other parent solutions: -\code{\link{DFOP.solution}()}, -\code{\link{FOMC.solution}()}, -\code{\link{HS.solution}()}, -\code{\link{IORE.solution}()}, -\code{\link{SFO.solution}()}, -\code{\link{SFORB.solution}()} +Other parent solutions: +\code{\link[=DFOP.solution]{DFOP.solution()}}, +\code{\link[=FOMC.solution]{FOMC.solution()}}, +\code{\link[=HS.solution]{HS.solution()}}, +\code{\link[=IORE.solution]{IORE.solution()}}, +\code{\link[=SFO.solution]{SFO.solution()}}, +\code{\link[=SFORB.solution]{SFORB.solution()}} } \concept{parent solutions} diff --git a/man/mkinds.Rd b/man/mkinds.Rd index a2c58300..ce87fb7f 100644 --- a/man/mkinds.Rd +++ b/man/mkinds.Rd @@ -27,70 +27,71 @@ print(mds) } \section{Public fields}{ -\if{html}{\out{
}} -\describe{ -\item{\code{title}}{A full title for the dataset} + \if{html}{\out{
}} + \describe{ + \item{\code{title}}{A full title for the dataset} -\item{\code{sampling_times}}{The sampling times} + \item{\code{sampling_times}}{The sampling times} -\item{\code{time_unit}}{The time unit} + \item{\code{time_unit}}{The time unit} -\item{\code{observed}}{Names of the observed variables} + \item{\code{observed}}{Names of the observed variables} -\item{\code{unit}}{The unit of the observations} + \item{\code{unit}}{The unit of the observations} -\item{\code{replicates}}{The maximum number of replicates per sampling time} + \item{\code{replicates}}{The maximum number of replicates per sampling time} -\item{\code{data}}{A data frame with at least the columns name, time + \item{\code{data}}{A data frame with at least the columns name, time and value in order to be compatible with mkinfit} -} -\if{html}{\out{
}} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-mkinds-new}{\code{mkinds$new()}} -\item \href{#method-mkinds-clone}{\code{mkinds$clone()}} -} + \itemize{ + \item \href{#method-mkinds-initialize}{\code{mkinds$new()}} + \item \href{#method-mkinds-clone}{\code{mkinds$clone()}} + } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-mkinds-new}{}}} -\subsection{Method \code{new()}}{ -Create a new mkinds object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{mkinds$new(title = "", data, time_unit = NA, unit = NA)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-mkinds-initialize}{}}} +\subsection{\code{mkinds$new()}}{ + Create a new mkinds object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{mkinds$new(title = "", data, time_unit = NA, unit = NA)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{title}}{The dataset title} + \item{\code{data}}{The data} + \item{\code{time_unit}}{The time unit} + \item{\code{unit}}{The unit of the observations} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{title}}{The dataset title} - -\item{\code{data}}{The data} - -\item{\code{time_unit}}{The time unit} - -\item{\code{unit}}{The unit of the observations} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-mkinds-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{mkinds$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{mkinds$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{mkinds$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/mkindsg.Rd b/man/mkindsg.Rd index 3b6a9f61..cb0c9bfd 100644 --- a/man/mkindsg.Rd +++ b/man/mkindsg.Rd @@ -37,69 +37,70 @@ print(mdsg, verbose = TRUE, data = TRUE) } \section{Public fields}{ -\if{html}{\out{
}} -\describe{ -\item{\code{title}}{A title for the dataset group} + \if{html}{\out{
}} + \describe{ + \item{\code{title}}{A title for the dataset group} -\item{\code{ds}}{A list of mkinds objects} + \item{\code{ds}}{A list of mkinds objects} -\item{\code{observed_n}}{Occurrence counts of compounds in datasets} + \item{\code{observed_n}}{Occurrence counts of compounds in datasets} -\item{\code{f_time_norm}}{Time normalisation factors} + \item{\code{f_time_norm}}{Time normalisation factors} -\item{\code{meta}}{A data frame with a row for each dataset, + \item{\code{meta}}{A data frame with a row for each dataset, containing additional information in the form of categorical data (factors) or numerical data (e.g. temperature, moisture, or covariates like soil pH).} -} -\if{html}{\out{
}} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-mkindsg-new}{\code{mkindsg$new()}} -\item \href{#method-mkindsg-clone}{\code{mkindsg$clone()}} -} + \itemize{ + \item \href{#method-mkindsg-initialize}{\code{mkindsg$new()}} + \item \href{#method-mkindsg-clone}{\code{mkindsg$clone()}} + } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-mkindsg-new}{}}} -\subsection{Method \code{new()}}{ -Create a new mkindsg object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{mkindsg$new(title = "", ds, f_time_norm = rep(1, length(ds)), meta)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-mkindsg-initialize}{}}} +\subsection{\code{mkindsg$new()}}{ + Create a new mkindsg object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{mkindsg$new(title = "", ds, f_time_norm = rep(1, length(ds)), meta)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{title}}{The title} + \item{\code{ds}}{A list of mkinds objects} + \item{\code{f_time_norm}}{Time normalisation factors} + \item{\code{meta}}{The meta data} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{title}}{The title} - -\item{\code{ds}}{A list of mkinds objects} - -\item{\code{f_time_norm}}{Time normalisation factors} - -\item{\code{meta}}{The meta data} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-mkindsg-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{mkindsg$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{mkindsg$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{mkindsg$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/reexports.Rd b/man/reexports.Rd index 43d27ac1..4608450f 100644 --- a/man/reexports.Rd +++ b/man/reexports.Rd @@ -1,5 +1,6 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/intervals.R, R/lrtest.mkinfit.R, R/nlme.mmkin.R +% Please edit documentation in R/intervals.R, R/lrtest.mkinfit.R, +% R/nlme.mmkin.R \docType{import} \name{reexports} \alias{reexports} @@ -13,8 +14,8 @@ These objects are imported from other packages. Follow the links below to see their documentation. \describe{ - \item{lmtest}{\code{\link[lmtest]{lrtest}}} + \item{lmtest}{\code{\link[lmtest:lrtest]{lrtest()}}} - \item{nlme}{\code{\link[nlme]{intervals}}, \code{\link[nlme]{nlme}}} + \item{nlme}{\code{\link[nlme:intervals]{intervals()}}, \code{\link[nlme:nlme]{nlme()}}} }} diff --git a/man/saem.Rd b/man/saem.Rd index 5a125ab6..73e42535 100644 --- a/man/saem.Rd +++ b/man/saem.Rd @@ -118,7 +118,7 @@ iterations} \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{quiet}{Should we suppress the messages saemix prints at the beginning and the end of the optimisation process?} @@ -129,12 +129,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 41932547..1c27e941 100644 --- a/man/summary.saem.mmkin.Rd +++ b/man/summary.saem.mmkin.Rd @@ -42,7 +42,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 diff --git a/man/transform_odeparms.Rd b/man/transform_odeparms.Rd index 3a97ff8d..09723fb8 100644 --- a/man/transform_odeparms.Rd +++ b/man/transform_odeparms.Rd @@ -42,7 +42,7 @@ of the estimator. The default (TRUE) is to do transformations. The g parameter of the DFOP model is also seen as a fraction. If a single fraction is transformed (g parameter of DFOP or only a single target variable e.g. a single metabolite plus a pathway to sink), a -logistic transformation is used \code{\link[stats:Logistic]{stats::qlogis()}}. In other cases, i.e. if +logistic transformation is used \code{\link[stats:qlogis]{stats::qlogis()}}. In other cases, i.e. if two or more formation fractions need to be transformed whose sum cannot exceed one, the \link{ilr} transformation is used.} diff --git a/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg index 3b9d51fb..4c91a43e 100644 --- a/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg @@ -27,20 +27,22 @@ --1149.30 --1149.25 --1149.20 --1149.15 --1149.10 --1149.05 --1149.00 +-1149.5 +-1149.4 +-1149.3 +-1149.2 +-1149.1 +-1149.0 +-1148.9 - + + 0 -1 -2 +1 +2 +3 @@ -48,13 +50,13 @@ - - - + + + - - - + + + original fit diff --git a/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg b/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg index 5e534dd1..381fed52 100644 --- a/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg +++ b/tests/testthat/_snaps/multistart/mixed-model-fit-for-saem-object-with-mkin-transformations.svg @@ -342,7 +342,7 @@ - + @@ -933,51 +933,51 @@ - - - + + + - - + + - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -1585,7 +1585,7 @@ - + @@ -2099,7 +2099,7 @@ - + @@ -2107,54 +2107,54 @@ - - - + + + - - - + + + - - + + - - - + + + - - - + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + 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 c733f84f..9be7ee5f 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg @@ -25,104 +25,104 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + @@ -167,28 +167,28 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg b/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg index c94012ce..76fed0dc 100644 --- a/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg +++ b/tests/testthat/_snaps/plot/mixed-model-fit-for-nlme-object.svg @@ -813,7 +813,7 @@ - + @@ -833,7 +833,7 @@ - + @@ -900,7 +900,7 @@ - + @@ -921,7 +921,7 @@ - + @@ -964,8 +964,8 @@ - - + + @@ -1243,8 +1243,8 @@ - - + + @@ -1291,8 +1291,8 @@ - - + + diff --git a/tests/testthat/print_dfop_saem_1.txt b/tests/testthat/print_dfop_saem_1.txt index 3a1f1667..3d036357 100644 --- a/tests/testthat/print_dfop_saem_1.txt +++ b/tests/testthat/print_dfop_saem_1.txt @@ -9,15 +9,15 @@ Data: Likelihood computed by importance sampling AIC BIC logLik - 1409 1415 -696 + 1409 1414 -696 Fitted parameters: estimate lower upper -parent_0 99.96 98.82 101.11 -log_k1 -2.71 -2.94 -2.49 +parent_0 99.97 98.83 101.12 +log_k1 -2.71 -2.94 -2.48 log_k2 -4.14 -4.26 -4.01 g_qlogis -0.36 -0.54 -0.17 -a.1 0.93 0.69 1.17 +a.1 0.92 0.68 1.17 b.1 0.05 0.04 0.05 -SD.log_k1 0.37 0.23 0.51 +SD.log_k1 0.37 0.23 0.52 SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index b2147fbe..111daa30 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -4,7 +4,12 @@ require(testthat) # Per default (on my box where I set NOT_CRAN in .Rprofile) use all cores minus one # Otherwise (CRAN check systems) use the allowed maximum of two cores if (identical(Sys.getenv("NOT_CRAN"), "true")) { - n_cores <- parallel::detectCores() - 1 + # We cannot use all course if on the Agroscope cluster, if not we use all but one + if (grepl("agsad.admin.ch", Sys.getenv("http_proxy"))) { + n_cores = 16 + } else { + n_cores <- parallel::detectCores() - 1 + } } else { n_cores <- 2 } diff --git a/tests/testthat/test_deSolve.R b/tests/testthat/test_deSolve.R index 3d15de35..c7acdc43 100644 --- a/tests/testthat/test_deSolve.R +++ b/tests/testthat/test_deSolve.R @@ -13,7 +13,8 @@ test_that("Solutions with deSolve work if we have no observations at time zero", solution_type = "deSolve", quiet = TRUE) expect_equal( parms(f_sfo_sfo_nozero), - parms(f_sfo_sfo_nozero_deSolve) + parms(f_sfo_sfo_nozero_deSolve), + tolerance = 1e-5 ) }) diff --git a/tests/testthat/test_endpoints.R b/tests/testthat/test_endpoints.R new file mode 100644 index 00000000..284e1379 --- /dev/null +++ b/tests/testthat/test_endpoints.R @@ -0,0 +1,49 @@ +context("DTx calculations") + +test_that("The DTx function gives the same results as the endpoints function", { + # We silently assume that the calculations in the endpoint function are correct + + SFO_fit <- fits[["SFO", "FOCUS_C"]] + SFO_distimes <- endpoints(SFO_fit)$distimes + SFO_DTx <- DTx("SFO", c(k = parms(SFO_fit)[["k_parent"]])) + + expect_equal( + as.numeric(SFO_distimes), + as.numeric(SFO_DTx) + ) + + FOMC_fit <- fits[["FOMC", "FOCUS_C"]] + FOMC_distimes <- endpoints(FOMC_fit)$distimes + FOMC_DTx <- DTx("FOMC", c( + alpha = parms(FOMC_fit)[["alpha"]], + beta = parms(FOMC_fit)[["beta"]]), exact = TRUE) + + expect_equal( + as.numeric(FOMC_distimes), + as.numeric(FOMC_DTx) + ) + + DFOP_fit <- fits[["DFOP", "FOCUS_C"]] + DFOP_distimes <- endpoints(DFOP_fit)$distimes + DFOP_DTx <- DTx("DFOP", c( + k1 = parms(DFOP_fit)[["k1"]], + k2 = parms(DFOP_fit)[["k2"]], + g = parms(DFOP_fit)[["g"]]), exact = TRUE) + + expect_equal( + as.numeric(DFOP_distimes), + as.numeric(DFOP_DTx) + ) + + HS_fit <- fits[["HS", "FOCUS_C"]] + HS_distimes <- endpoints(HS_fit)$distimes + HS_DTx <- DTx("HS", c( + k1 = parms(HS_fit)[["k1"]], + k2 = parms(HS_fit)[["k2"]], + tb = parms(HS_fit)[["tb"]]), exact = TRUE) + + expect_equal( + as.numeric(HS_distimes), + as.numeric(HS_DTx) + ) +}) -- cgit v1.2.3