diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2022-02-08 17:17:29 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2022-02-08 17:17:29 +0100 |
commit | 0fa8a770812775d697717ad723f7f61fb04b7fef (patch) | |
tree | 17473ddf787541745d47dab063bc643ec59a9557 /R/tffm0.R | |
parent | d081384ddcb75a9f92fad33e4e3f6d6796f98e67 (diff) | |
parent | c0638c84568d475b3b059e2c6e593e6f03b846bc (diff) |
Merge branch 'nlmixr'
Diffstat (limited to 'R/tffm0.R')
-rw-r--r-- | R/tffm0.R | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/R/tffm0.R b/R/tffm0.R new file mode 100644 index 00000000..bb5f4cf5 --- /dev/null +++ b/R/tffm0.R @@ -0,0 +1,48 @@ +#' 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 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 +#' 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 +#' @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) + f_remaining <- 1 + for (i in 1:n) { + res[i] <- ff_trans[i] * f_remaining + f_remaining <- f_remaining - res[i] + } + return(res) +} |