aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-03-02 08:30:46 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-03-02 08:30:46 +0100
commit6468bc31254baeac7dad90a38715714291be30ae (patch)
tree7fa39286d2b56e4bd86152abec493f6dbd8c5576
parent1ba0938b5a39f9d376b54fe3469b40aafea9e8e3 (diff)
Add a test for tffm0()
-rw-r--r--R/tffm0.R19
-rw-r--r--man/tffm0.Rd20
-rw-r--r--test.log15
-rw-r--r--tests/testthat/test_tffm0.R10
4 files changed, 41 insertions, 23 deletions
diff --git a/R/tffm0.R b/R/tffm0.R
index bb5f4cf5..56283a5d 100644
--- a/R/tffm0.R
+++ b/R/tffm0.R
@@ -1,15 +1,18 @@
#' Transform formation fractions as in the first published mkin version
#'
-#' The transformed fractions can be restricted between 0 and 1 in model
-#' optimisations. Therefore this transformation was used originally in mkin. It
-#' was later replaced by the [ilr] transformation because the ilr transformed
+#' This transformation was used originally in mkin, in order to implement a
+#' constraint for the sum of formation fractions to be smaller than 1. It was
+#' later replaced by the [ilr] transformation because the ilr transformed
#' fractions can assumed to follow normal distribution. As the ilr
#' transformation is not available in [RxODE] and can therefore not be used in
-#' the nlmixr modelling language, this transformation is currently used for
-#' translating mkin models with formation fractions to more than one target
-#' compartment for fitting with nlmixr in [nlmixr_model]. However,
-#' this implementation cannot be used there, as it is not accessible
-#' from RxODE.
+#' the nlmixr modelling language, the original transformation is currently used
+#' for translating mkin models with formation fractions to more than one target
+#' compartment for fitting with nlmixr in [nlmixr_model]. However, this
+#' implementation cannot be used there, as it is not accessible from RxODE.
+#'
+#' If the transformed formation fractions are restricted to the interval
+#' between 0 and 1, the sum of backtransformed values is restricted
+#' to this interval.
#'
#' @param ff Vector of untransformed formation fractions. The sum
#' must be smaller or equal to one
diff --git a/man/tffm0.Rd b/man/tffm0.Rd
index 46978d5e..89bee7d9 100644
--- a/man/tffm0.Rd
+++ b/man/tffm0.Rd
@@ -22,16 +22,20 @@ A vector of the transformed formation fractions
A vector of backtransformed formation fractions for natural use in degradation models
}
\description{
-The transformed fractions can be restricted between 0 and 1 in model
-optimisations. Therefore this transformation was used originally in mkin. It
-was later replaced by the \link{ilr} transformation because the ilr transformed
+This transformation was used originally in mkin, in order to implement a
+constraint for the sum of formation fractions to be smaller than 1. It was
+later replaced by the \link{ilr} transformation because the ilr transformed
fractions can assumed to follow normal distribution. As the ilr
transformation is not available in \link{RxODE} and can therefore not be used in
-the nlmixr modelling language, this transformation is currently used for
-translating mkin models with formation fractions to more than one target
-compartment for fitting with nlmixr in \link{nlmixr_model}. However,
-this implementation cannot be used there, as it is not accessible
-from RxODE.
+the nlmixr modelling language, the original transformation is currently used
+for translating mkin models with formation fractions to more than one target
+compartment for fitting with nlmixr in \link{nlmixr_model}. However, this
+implementation cannot be used there, as it is not accessible from RxODE.
+}
+\details{
+If the transformed formation fractions are restricted to the interval
+between 0 and 1, the sum of backtransformed values is restricted
+to this interval.
}
\examples{
ff_example <- c(
diff --git a/test.log b/test.log
index a2217f49..cb7edba3 100644
--- a/test.log
+++ b/test.log
@@ -8,19 +8,19 @@ Loading required package: parallel
✔ | 2 | Export dataset for reading into CAKE
✔ | 12 | Confidence intervals and p-values [1.0s]
⠋ | 1 | Dimethenamid data from 2018
-✔ | 1 25 | Dimethenamid data from 2018 [49.4s]
+✔ | 1 25 | Dimethenamid data from 2018 [52.3s]
────────────────────────────────────────────────────────────────────────────────
Skip (test_dmta.R:147:3): 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 [6.9s]
+✔ | 14 | Error model fitting [7.1s]
✔ | 5 | Time step normalisation
✔ | 4 | Calculation of FOCUS chi2 error levels [0.8s]
✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [1.2s]
✔ | 4 | Test fitting the decline of metabolites from their maximum [0.6s]
✔ | 1 | Fitting the logistic model [0.4s]
⠴ | 6 | Nonlinear mixed-effects models
-✔ | 1 15 | Nonlinear mixed-effects models [2.4s]
+✔ | 1 15 | Nonlinear mixed-effects models [2.5s]
────────────────────────────────────────────────────────────────────────────────
Skip (test_mixed.R:67:3): saemix results are reproducible for biphasic fits
Reason: Fitting with saemix takes around 10 minutes when using deSolve
@@ -30,24 +30,25 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve
✔ | 3 | mkinfit features [1.1s]
✔ | 8 | mkinmod model generation and printing [0.2s]
✔ | 3 | Model predictions with mkinpredict [0.3s]
-✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.1s]
+✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.2s]
✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s]
✔ | 16 | Plotting [1.5s]
✔ | 4 | Residuals extracted from mkinfit models
-✔ | 23 | saemix_parent [29.2s]
+✔ | 23 | saemix_parent [29.1s]
✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.6s]
✔ | 7 | Fitting the SFORB model [4.4s]
✔ | 1 | Summaries of old mkinfit objects
✔ | 4 | Summary [0.1s]
✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.6s]
✔ | 9 | Hypothesis tests [9.4s]
+✔ | 2 | tffm0
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s]
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 132.0 s
+Duration: 135.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)
-[ FAIL 0 | WARN 0 | SKIP 2 | PASS 237 ]
+[ FAIL 0 | WARN 0 | SKIP 2 | PASS 239 ]
diff --git a/tests/testthat/test_tffm0.R b/tests/testthat/test_tffm0.R
new file mode 100644
index 00000000..82e1ee94
--- /dev/null
+++ b/tests/testthat/test_tffm0.R
@@ -0,0 +1,10 @@
+test_that("The formation fraction transformation tffm0 is reversible", {
+ ff_example <- c(
+ 0.10983681, 0.09035905, 0.08399383
+ )
+ ff_example_trans <- tffm0(ff_example)
+ expect_equal(invtffm0(ff_example_trans), ff_example)
+
+ ff_ex_2_trans <- c(0.5, 0.9, 0.99)
+ expect_true(sum(invtffm0(ff_ex_2_trans)) < 1)
+})

Contact - Imprint