From 28197d5fcbaf85b39f4c032b8180d68b6f6a01b3 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 16 Jun 2021 18:03:22 +0200 Subject: Translate formation fractions to nlmixr language Works for the dimethenamid data, at least for FOCEI. Very little testing yet. The summary function does not yet handle the new transformations of formation fractions (that are in fact very old, as they were used in the very first version of mkin). The test file has no tests yet, just some code that may be used for testing. --- R/tffm0.R | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 R/tffm0.R (limited to 'R/tffm0.R') diff --git a/R/tffm0.R b/R/tffm0.R new file mode 100644 index 00000000..25787962 --- /dev/null +++ b/R/tffm0.R @@ -0,0 +1,46 @@ +#' 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 +#' 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. +#' +#' @param ff Vector of untransformed formation fractions. The sum +#' must be smaller or equal to one +#' @param ff_trans +#' @return A vector of the transformed formation fractions +#' @export +#' @examples +#' ff_example <- c( +#' 0.10983681, 0.09035905, 0.08399383 +#' ) +#' ff_example_trans <- tffm0(ff_example) +#' invtffm0(ff_example_trans) +tffm0 <- function(ff) { + n <- length(ff) + res <- numeric(n) + f_remaining <- 1 + for (i in 1:n) { + res[i] <- ff[i]/f_remaining + f_remaining <- f_remaining - ff[i] + } + return(res) +} +#' @rdname tffm0 +#' @return +invtffm0 <- function(ff_trans) { + n <- length(ff_trans) + res <- numeric(n) + f_remaining <- 1 + for (i in 1:n) { + res[i] <- ff_trans[i] * f_remaining + f_remaining <- f_remaining - res[i] + } + return(res) +} -- cgit v1.2.1 From 05baf3bf92cba127fd2319b779db78be86170e5e Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 17 Jun 2021 13:58:34 +0200 Subject: Let backtransform_odeparms handle nlmixr formation fractions Also adapt summary.nlmixr.mmkin to correctly handle the way formation fractions are translated to nlmixr --- R/tffm0.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'R/tffm0.R') diff --git a/R/tffm0.R b/R/tffm0.R index 25787962..bb5f4cf5 100644 --- a/R/tffm0.R +++ b/R/tffm0.R @@ -13,7 +13,8 @@ #' #' @param ff Vector of untransformed formation fractions. The sum #' must be smaller or equal to one -#' @param ff_trans +#' @param ff_trans Vector of transformed formation fractions that can be +#' restricted to the interval from 0 to 1 #' @return A vector of the transformed formation fractions #' @export #' @examples @@ -33,7 +34,8 @@ tffm0 <- function(ff) { return(res) } #' @rdname tffm0 -#' @return +#' @export +#' @return A vector of backtransformed formation fractions for natural use in degradation models invtffm0 <- function(ff_trans) { n <- length(ff_trans) res <- numeric(n) -- cgit v1.2.1