From d3df16102c5ed4bf9182b4f1893561e99eaed166 Mon Sep 17 00:00:00 2001 From: jranke Date: Tue, 3 Apr 2012 05:17:54 +0000 Subject: - Separated model prediction out into a separate function - Created separate functions for parameter transformations (not documented yet) - Fitting of analytical models works - SFO_SFO model works, complex models do not at the moment - summary.mkinfit not operational at the moment git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@21 edb9625f-4e0d-4859-8d74-9fd3b1da38cb --- R/transform_odeparms.R | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 R/transform_odeparms.R (limited to 'R/transform_odeparms.R') diff --git a/R/transform_odeparms.R b/R/transform_odeparms.R new file mode 100644 index 00000000..4b8bfd14 --- /dev/null +++ b/R/transform_odeparms.R @@ -0,0 +1,46 @@ +transform_odeparms <- function(odeparms, mod_vars) { + # Transform rate constants and formation fractions + transparms <- odeparms + # Exponential transformation for rate constants + index_k <- grep("^k_", names(odeparms)) + if (length(index_k) > 0) { + transparms[index_k] <- exp(odeparms[index_k]) + } + + # Go through state variables and apply inverse isotropic logratio transformation + for (box in mod_vars) { + indices_f <- grep(paste("^f", box, sep = "_"), names(odeparms)) + f_names <- grep(paste("^f", box, sep = "_"), names(odeparms), value = TRUE) + n_paths <- length(indices_f) + if (n_paths > 0) { + f <- invilr(odeparms[indices_f])[1:n_paths] # We do not need the last component + names(f) <- f_names + transparms[indices_f] <- f + } + } + return(transparms) +} + +backtransform_odeparms <- function(transparms, mod_vars) { + # Transform rate constants and formation fractions + odeparms <- transparms + # Log transformation for rate constants + index_k <- grep("^k_", names(transparms)) + if (length(index_k) > 0) { + odeparms[index_k] <- log(transparms[index_k]) + } + + # Go through state variables and apply isotropic logratio transformation + for (box in mod_vars) { + indices_f <- grep(paste("^f", box, sep = "_"), names(transparms)) + f_names <- grep(paste("^f", box, sep = "_"), names(transparms), value = TRUE) + n_paths <- length(indices_f) + if (n_paths > 0) { + trans_f <- transparms[indices_f] + f <- ilr(c(trans_f, 1 - sum(trans_f))) + names(f) <- f_names + odeparms[indices_f] <- f + } + } + return(odeparms) +} -- cgit v1.2.1