aboutsummaryrefslogtreecommitdiff
path: root/R/transform_odeparms.R
diff options
context:
space:
mode:
authorjranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>2012-04-03 05:17:54 +0000
committerjranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>2012-04-03 05:17:54 +0000
commitd3df16102c5ed4bf9182b4f1893561e99eaed166 (patch)
tree2ac5629d27dd6fc97e64a3ed627da6a0baa77694 /R/transform_odeparms.R
parentfff1fc581da5b4ff935ebd4d7ded02f750472fdc (diff)
- 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
Diffstat (limited to 'R/transform_odeparms.R')
-rw-r--r--R/transform_odeparms.R46
1 files changed, 46 insertions, 0 deletions
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)
+}

Contact - Imprint