aboutsummaryrefslogtreecommitdiff
path: root/R/mkinpredict.R
diff options
context:
space:
mode:
Diffstat (limited to 'R/mkinpredict.R')
-rw-r--r--R/mkinpredict.R24
1 files changed, 20 insertions, 4 deletions
diff --git a/R/mkinpredict.R b/R/mkinpredict.R
index 60456fb2..2c865cb7 100644
--- a/R/mkinpredict.R
+++ b/R/mkinpredict.R
@@ -22,7 +22,7 @@
#' variables. The third possibility "eigen" is fast in comparison to uncompiled
#' ODE models, but not applicable to some models, e.g. using FOMC for the
#' parent compound.
-#' @param method.ode The solution method passed via [mkinpredict] to [ode]] in
+#' @param method.ode The solution method passed via [mkinpredict] to `deSolve::ode()` in
#' case the solution type is "deSolve" and we are not using compiled code.
#' When using compiled code, only lsoda is supported.
#' @param use_compiled If set to \code{FALSE}, no compiled version of the
@@ -36,7 +36,7 @@
#' the observed variables (default) or for all state variables (if set to
#' FALSE). Setting this to FALSE has no effect for analytical solutions,
#' as these always return mapped output.
-#' @param na_stop Should it be an error if [ode] returns NaN values
+#' @param na_stop Should it be an error if `deSolve::ode()` returns NaN values
#' @param \dots Further arguments passed to the ode solver in case such a
#' solver is used.
#' @return A matrix with the numeric solution in wide format
@@ -172,6 +172,15 @@ mkinpredict.mkinmod <- function(x,
}
if (solution_type == "deSolve") {
+
+ # We need to make sure that 0 is included in outtimes,
+ # even if we do not have observed data for time zero,
+ # because otherwise the initial values are not applied
+ # to time zero but to the time of the first observation
+ # in the data
+ if (min(outtimes) > 0) outtimes_deSolve <- c(0, outtimes)
+ else outtimes_deSolve <- outtimes
+
if (!is.null(x$cf) & use_compiled[1] != FALSE) {
if (!is.null(x$symbols) & use_symbols) {
@@ -182,7 +191,7 @@ mkinpredict.mkinmod <- function(x,
out <- deSolve::lsoda(
y = odeini,
- times = outtimes,
+ times = outtimes_deSolve,
func = lsoda_func,
initfunc = "initpar",
dllname = x$dll_info[["name"]],
@@ -209,7 +218,7 @@ mkinpredict.mkinmod <- function(x,
}
out <- deSolve::ode(
y = odeini,
- times = outtimes,
+ times = outtimes_deSolve,
func = mkindiff,
parms = odeparms,
method = method.ode,
@@ -219,6 +228,13 @@ mkinpredict.mkinmod <- function(x,
...
)
}
+
+ # Now we need to remove time zero, in case we did not
+ # have observations for it
+ if (min(outtimes) > 0) {
+ out <- out[-1, ]
+ }
+
n_out_na <- sum(is.na(out))
if (n_out_na > 0 & na_stop) {
cat("odeini:\n")

Contact - Imprint