diff options
author | Johannes Ranke <johannes.ranke@jrwb.de> | 2025-02-16 17:27:18 +0100 |
---|---|---|
committer | Johannes Ranke <johannes.ranke@jrwb.de> | 2025-02-16 17:29:28 +0100 |
commit | 4f62f39b8979cb3a5c52d65d425e530dc0770665 (patch) | |
tree | 895d4bde0773a600943e5c308e17651c12358a67 /R | |
parent | 44c30938872bd7cc80a4c84dd4db593e26000fce (diff) |
The special case occurs if not observed data for time zero
are available. Fixes #16. Write NEWS and update docs.
A lot of html was regenerated, because I had checked out
the main branch in between, which made pkgdown believe that
I have changed the help files.
Diffstat (limited to 'R')
-rw-r--r-- | R/mkinpredict.R | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/R/mkinpredict.R b/R/mkinpredict.R index 4c6d7862..2c865cb7 100644 --- a/R/mkinpredict.R +++ b/R/mkinpredict.R @@ -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") |