aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>2012-04-25 10:33:53 +0000
committerjranke <jranke@edb9625f-4e0d-4859-8d74-9fd3b1da38cb>2012-04-25 10:33:53 +0000
commitc4e8498ee688fff1e1b2df1a7a65f888cb0d9d84 (patch)
treebcc4a6136520f1e4b9f04760657875eca781ab70
parent081b5f25cc4ef779175307d9ce20672e0573b7c9 (diff)
- Transferred some testing code from test.R to unit tests for mkinpredict
- Fixed the output format of mkinpredict to be uniform across solution types git-svn-id: svn+ssh://svn.r-forge.r-project.org/svnroot/kinfit/pkg/mkin@33 edb9625f-4e0d-4859-8d74-9fd3b1da38cb
-rw-r--r--R/mkinpredict.R8
-rw-r--r--TODO3
-rw-r--r--inst/unitTests/runit.mkinfit.R1
-rw-r--r--inst/unitTests/runit.mkinpredict.R86
4 files changed, 92 insertions, 6 deletions
diff --git a/R/mkinpredict.R b/R/mkinpredict.R
index be43b0e4..493c5781 100644
--- a/R/mkinpredict.R
+++ b/R/mkinpredict.R
@@ -57,8 +57,8 @@ mkinpredict <- function(mkinmod, odeparms, odeini, outtimes, solution_type = "de
evalparse(paste("k", sub("free", "bound", parent.name), "free", sep="_")),
evalparse(paste("k", parent.name, "sink", sep="_")))
)
- out <- cbind(outtimes, o)
- dimnames(out) <- list(outtimes, c("time", sub("_free", "", parent.name)))
+ out <- data.frame(outtimes, o)
+ names(out) <- c("time", sub("_free", "", parent.name))
}
if (solution_type == "eigen") {
coefmat.num <- matrix(sapply(as.vector(mkinmod$coefmat), evalparse),
@@ -70,8 +70,8 @@ mkinpredict <- function(mkinmod, odeparms, odeini, outtimes, solution_type = "de
}
o <- matrix(mapply(f.out, outtimes),
nrow = length(mod_vars), ncol = length(outtimes))
- dimnames(o) <- list(mod_vars, outtimes)
- out <- cbind(time = outtimes, t(o))
+ out <- data.frame(outtimes, t(o))
+ names(out) <- c("time", mod_vars)
}
if (solution_type == "deSolve") {
mkindiff <- function(t, state, parms) {
diff --git a/TODO b/TODO
index a7503bda..fb8b80d6 100644
--- a/TODO
+++ b/TODO
@@ -1,9 +1,8 @@
Must have:
-- Fix remaining problem with the schaefer complex test data (test.R)
- Adapt mkinplot function
Nice to have:
-- Make unit tests for mkinpredict, comparing different solution types
+- Fix remaining problem with the schaefer complex test data (test.R: fit.2.eigen)
- Calculate confidence intervals for parameters assuming normal distribution
- Calculate confidence intervals for DT50 and DT90 values when only one parameter is involved
- Add unit tests for mkinfit
diff --git a/inst/unitTests/runit.mkinfit.R b/inst/unitTests/runit.mkinfit.R
index a06e4ff1..2030f852 100644
--- a/inst/unitTests/runit.mkinfit.R
+++ b/inst/unitTests/runit.mkinfit.R
@@ -257,4 +257,5 @@ test.mkinfit.schaefer07_complex_example <- function()
r$mkin.deviation <- abs(round(100 * ((r$mkin - r$means)/r$means), digits=1))
checkIdentical(r$mkin.deviation < 10, rep(TRUE, length(r$mkin.deviation)))
} # }}}
+
# vim: set foldmethod=marker ts=2 sw=2 expandtab:
diff --git a/inst/unitTests/runit.mkinpredict.R b/inst/unitTests/runit.mkinpredict.R
new file mode 100644
index 00000000..997857ce
--- /dev/null
+++ b/inst/unitTests/runit.mkinpredict.R
@@ -0,0 +1,86 @@
+# $Id: jranke $
+
+# Copyright (C) 2012 Johannes Ranke
+# Contact: jranke@uni-bremen.de
+
+# This file is part of the R package mkin
+
+# mkin is free software: you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>
+
+# Check solution types for SFO {{{
+test.SFO_solution_types <- function()
+{
+ ot = seq(0, 100, by = 1)
+ SFO <- mkinmod(parent = list(type = "SFO"))
+ SFO.analytical <- round(subset(mkinpredict(SFO, c(k_parent_sink = 0.1),
+ c(parent = 100), ot, solution_type = "analytical"), time == 100), digits=5)
+ SFO.deSolve <- round(subset(mkinpredict(SFO, c(k_parent_sink = 0.1),
+ c(parent = 100), ot, solution_type = "deSolve"), time == 100), digits=5)
+ SFO.eigen <- round(subset(mkinpredict(SFO, c(k_parent_sink = 0.1),
+ c(parent = 100), ot, solution_type = "eigen"), time == 100), digits=5)
+
+ checkEquals(SFO.analytical, SFO.deSolve)
+ checkEquals(SFO.analytical, SFO.eigen)
+} # }}}
+
+# Check model specification and solution types for SFO_SFO {{{
+# Relative Tolerance is 0.01%
+# Do not use time 0, as eigenvalue based solution does not give 0 at time 0 for metabolites
+# and relative tolerance is thus not met
+test.SFO_solution_types <- function()
+{
+ tol = 0.01
+ SFO_SFO.1 <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"), use_of_ff = "min")
+ SFO_SFO.2 <- mkinmod(parent = list(type = "SFO", to = "m1"),
+ m1 = list(type = "SFO"), use_of_ff = "max")
+
+ ot = seq(0, 100, by = 1)
+ r.1.e <- subset(mkinpredict(SFO_SFO.1,
+ c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "eigen"),
+ time %in% c(1, 10, 50, 100))
+ r.1.d <- subset(mkinpredict(SFO_SFO.1,
+ c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "deSolve"),
+ time %in% c(1, 10, 50, 100))
+
+ r.2.e <- subset(mkinpredict(SFO_SFO.2, c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "eigen"),
+ time %in% c(1, 10, 50, 100))
+ r.2.d <- subset(mkinpredict(SFO_SFO.2, c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "deSolve"),
+ time %in% c(1, 10, 50, 100))
+
+ # Compare eigen and deSolve for minimum use of formation fractions
+ dev.1.e_d.percent = 100 * (r.1.e[-1] - r.1.d[-1])/r.1.e[-1]
+ dev.1.e_d.percent = as.numeric(unlist((dev.1.e_d.percent)))
+ dev.1.e_d.percent = ifelse(is.na(dev.1.e_d.percent), 0, dev.1.e_d.percent)
+ checkIdentical(dev.1.e_d.percent < tol, rep(TRUE, length(dev.1.e_d.percent)))
+
+ # Compare eigen and deSolve for maximum use of formation fractions
+ dev.2.e_d.percent = 100 * (r.1.e[-1] - r.1.d[-1])/r.1.e[-1]
+ dev.2.e_d.percent = as.numeric(unlist((dev.2.e_d.percent)))
+ dev.2.e_d.percent = ifelse(is.na(dev.2.e_d.percent), 0, dev.2.e_d.percent)
+ checkIdentical(dev.2.e_d.percent < tol, rep(TRUE, length(dev.2.e_d.percent)))
+
+ # Compare minimum and maximum use of formation fractions
+ dev.1_2.e.percent = 100 * (r.1.e[-1] - r.2.e[-1])/r.1.e[-1]
+ dev.1_2.e.percent = as.numeric(unlist((dev.1_2.e.percent)))
+ dev.1_2.e.percent = ifelse(is.na(dev.1_2.e.percent), 0, dev.1_2.e.percent)
+ checkIdentical(dev.1_2.e.percent < tol, rep(TRUE, length(dev.1_2.e.percent)))
+
+} # }}}
+
+# vim: set foldmethod=marker ts=2 sw=2 expandtab:

Contact - Imprint