From c504e823809aa8a299ed5326a22505f82d891ce5 Mon Sep 17 00:00:00 2001
From: Johannes Ranke <jranke@uni-bremen.de>
Date: Thu, 16 Apr 2015 11:06:39 +0200
Subject: Update copyright header, improve documentation of solution_type

---
 R/mkinfit.R     | 29 +++++++++++++++++------------
 R/mkinmod.R     |  2 +-
 R/mkinpredict.R |  2 +-
 3 files changed, 19 insertions(+), 14 deletions(-)

(limited to 'R')

diff --git a/R/mkinfit.R b/R/mkinfit.R
index 38f76674..5118519a 100644
--- a/R/mkinfit.R
+++ b/R/mkinfit.R
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2014 Johannes Ranke
+# Copyright (C) 2010-2015 Johannes Ranke
 # Portions of this code are copyright (C) 2013 Eurofins Regulatory AG
 # Contact: jranke@uni-bremen.de
 # The summary function is an adapted and extended version of summary.modFit
@@ -26,7 +26,7 @@ mkinfit <- function(mkinmod, observed,
   state.ini = "auto", 
   fixed_parms = NULL,
   fixed_initials = names(mkinmod$diffs)[-1],
-  solution_type = "auto",
+  solution_type = c("auto", "analytical", "eigen", "deSolve"),
   method.ode = "lsoda",
   use_compiled = "auto",
   method.modFit = c("Port", "Marq", "SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B"),
@@ -89,7 +89,7 @@ mkinfit <- function(mkinmod, observed,
          " not used in the model")
   }
 
-  # Warn that the sum of formation fractions may exceed one they are not
+  # Warn that the sum of formation fractions may exceed one if they are not
   # fitted in the transformed way
   if (mkinmod$use_of_ff == "max" & transform_fractions == FALSE) {
     warning("The sum of formation fractions may exceed one if you do not use ",
@@ -112,7 +112,7 @@ mkinfit <- function(mkinmod, observed,
       stop("Fixing formation fractions is not supported when using the ilr ",
            "transformation.")
     }
- }
+  }
 
   # Set initial parameter values, including a small increment (salt)
   # to avoid linear dependencies (singular matrix) in Eigenvalue based solutions
@@ -208,8 +208,9 @@ mkinfit <- function(mkinmod, observed,
   # Decide if the solution of the model can be based on a simple analytical
   # formula, the spectral decomposition of the matrix (fundamental system)
   # or a numeric ode solver from the deSolve package
-  if (!solution_type %in% c("auto", "analytical", "eigen", "deSolve"))
-     stop("solution_type must be auto, analytical, eigen or de Solve")
+  # Prefer deSolve over eigen if a compiled model is present and use_compiled
+  # is not set to FALSE
+  solution_type = match.arg(solution_type)
   if (solution_type == "analytical" && length(mkinmod$spec) > 1)
      stop("Analytical solution not implemented for models with metabolites.")
   if (solution_type == "eigen" && !is.matrix(mkinmod$coefmat))
@@ -218,13 +219,17 @@ mkinfit <- function(mkinmod, observed,
     if (length(mkinmod$spec) == 1) {
       solution_type = "analytical"
     } else {
-      if (is.matrix(mkinmod$coefmat)) {
-        solution_type = "eigen"
-        if (max(observed$value, na.rm = TRUE) < 0.1) {
-          stop("The combination of small observed values (all < 0.1) and solution_type = eigen is error-prone")
-        }
-      } else {
+      if (!is.null(mkinmod$compiled) & use_compiled[1] != FALSE) {
         solution_type = "deSolve"
+      } else {
+        if (is.matrix(mkinmod$coefmat)) {
+          solution_type = "eigen"
+          if (max(observed$value, na.rm = TRUE) < 0.1) {
+            stop("The combination of small observed values (all < 0.1) and solution_type = eigen is error-prone")
+          }
+        } else {
+          solution_type = "deSolve"
+        }
       }
     }
   }
diff --git a/R/mkinmod.R b/R/mkinmod.R
index 37cd02b4..e73c56c6 100644
--- a/R/mkinmod.R
+++ b/R/mkinmod.R
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2014 Johannes Ranke {{{
+# Copyright (C) 2010-2015 Johannes Ranke {{{
 # Contact: jranke@uni-bremen.de
 
 # This file is part of the R package mkin
diff --git a/R/mkinpredict.R b/R/mkinpredict.R
index 864eefbe..3e3ca0bf 100644
--- a/R/mkinpredict.R
+++ b/R/mkinpredict.R
@@ -1,4 +1,4 @@
-# Copyright (C) 2010-2014 Johannes Ranke
+# Copyright (C) 2010-2015 Johannes Ranke
 # Some lines in this code are copyright (C) 2013 Eurofins Regulatory AG
 # Contact: jranke@uni-bremen.de
 
-- 
cgit v1.2.1