aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-11-04 18:09:50 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-11-04 18:09:50 +0100
commit85cb80385bb26f40d1c1a40bbda457dd29c4cc23 (patch)
tree5a11c81b5ebd63b42fba715c72902a3147c5cdd8
parentce7a20e54d8005264f13d3e9fe0c99f84d20b85e (diff)
Make it easy to override maxsteps for lsoda
The hope was to be more successful in saemix fits, but I did not notice an improvement (e.g. for a failing likelihood calculation with importance sampling, where the error message suggested to increase maxsteps).
-rw-r--r--R/mkinpredict.R49
-rw-r--r--man/mkinpredict.Rd33
2 files changed, 44 insertions, 38 deletions
diff --git a/R/mkinpredict.R b/R/mkinpredict.R
index 9e6ba31f..0dc9cf55 100644
--- a/R/mkinpredict.R
+++ b/R/mkinpredict.R
@@ -1,40 +1,41 @@
#' Produce predictions from a kinetic model using specific parameters
#'
#' This function produces a time series for all the observed variables in a
-#' kinetic model as specified by \code{\link{mkinmod}}, using a specific set of
+#' kinetic model as specified by [mkinmod], using a specific set of
#' kinetic parameters and initial values for the state variables.
#'
#' @aliases mkinpredict mkinpredict.mkinmod mkinpredict.mkinfit
-#' @param x A kinetic model as produced by \code{\link{mkinmod}}, or a kinetic
-#' fit as fitted by \code{\link{mkinfit}}. In the latter case, the fitted
-#' parameters are used for the prediction.
+#' @param x A kinetic model as produced by [mkinmod], or a kinetic fit as
+#' fitted by [mkinfit]. In the latter case, the fitted parameters are used for
+#' the prediction.
#' @param odeparms A numeric vector specifying the parameters used in the
-#' kinetic model, which is generally defined as a set of ordinary
-#' differential equations.
+#' kinetic model, which is generally defined as a set of ordinary differential
+#' equations.
#' @param odeini A numeric vector containing the initial values of the state
-#' variables of the model. Note that the state variables can differ from the
-#' observed variables, for example in the case of the SFORB model.
+#' variables of the model. Note that the state variables can differ from the
+#' observed variables, for example in the case of the SFORB model.
#' @param outtimes A numeric vector specifying the time points for which model
-#' predictions should be generated.
+#' predictions should be generated.
#' @param solution_type The method that should be used for producing the
-#' predictions. This should generally be "analytical" if there is only one
-#' observed variable, and usually "deSolve" in the case of several observed
-#' variables. The third possibility "eigen" is faster but not applicable to
-#' some models e.g. using FOMC for the parent compound.
-#' @param method.ode The solution method passed via \code{\link{mkinpredict}}
-#' to \code{\link{ode}} in case the solution type is "deSolve". The default
-#' "lsoda" is performant, but sometimes fails to converge.
+#' predictions. This should generally be "analytical" if there is only one
+#' observed variable, and usually "deSolve" in the case of several observed
+#' variables. The third possibility "eigen" is faster 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
+#' case the solution type is "deSolve". The default "lsoda" is performant, but
+#' sometimes fails to converge.
#' @param use_compiled If set to \code{FALSE}, no compiled version of the
-#' \code{\link{mkinmod}} model is used, even if is present.
-#' @param atol Absolute error tolerance, passed to \code{\link{ode}}. Default
-#' is 1e-8, lower than in \code{\link{lsoda}}.
-#' @param rtol Absolute error tolerance, passed to \code{\link{ode}}. Default
-#' is 1e-10, much lower than in \code{\link{lsoda}}.
+#' [mkinmod] model is used, even if is present.
+#' @param atol Absolute error tolerance, passed to [ode]. Default is 1e-8,
+#' lower than in [lsoda].
+#' @param rtol Absolute error tolerance, passed to [ode]. Default is 1e-10,
+#' much lower than in [lsoda].
+#' @param maxsteps Maximum number of steps, passed to [ode].
#' @param map_output Boolean to specify if the output should list values for
#' 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 deSolve::ode returns NaN values
+#' @param na_stop Should it be an error if [ode] returns NaN values
#' @param \dots Further arguments passed to the ode solver in case such a
#' solver is used.
#' @import deSolve
@@ -115,7 +116,7 @@ mkinpredict.mkinmod <- function(x,
outtimes = seq(0, 120, by = 0.1),
solution_type = "deSolve",
use_compiled = "auto",
- method.ode = "lsoda", atol = 1e-8, rtol = 1e-10,
+ method.ode = "lsoda", atol = 1e-8, rtol = 1e-10, maxsteps = 20000,
map_output = TRUE,
na_stop = TRUE,
...)
@@ -183,6 +184,7 @@ mkinpredict.mkinmod <- function(x,
method = method.ode,
atol = atol,
rtol = rtol,
+ maxsteps = maxsteps,
...
)
} else {
@@ -206,6 +208,7 @@ mkinpredict.mkinmod <- function(x,
method = method.ode,
atol = atol,
rtol = rtol,
+ maxsteps = maxsteps,
...
)
}
diff --git a/man/mkinpredict.Rd b/man/mkinpredict.Rd
index 3a2939e1..0797f259 100644
--- a/man/mkinpredict.Rd
+++ b/man/mkinpredict.Rd
@@ -18,6 +18,7 @@ mkinpredict(x, odeparms, odeini, outtimes, ...)
method.ode = "lsoda",
atol = 1e-08,
rtol = 1e-10,
+ maxsteps = 20000,
map_output = TRUE,
na_stop = TRUE,
...
@@ -38,13 +39,13 @@ mkinpredict(x, odeparms, odeini, outtimes, ...)
)
}
\arguments{
-\item{x}{A kinetic model as produced by \code{\link{mkinmod}}, or a kinetic
-fit as fitted by \code{\link{mkinfit}}. In the latter case, the fitted
-parameters are used for the prediction.}
+\item{x}{A kinetic model as produced by \link{mkinmod}, or a kinetic fit as
+fitted by \link{mkinfit}. In the latter case, the fitted parameters are used for
+the prediction.}
\item{odeparms}{A numeric vector specifying the parameters used in the
-kinetic model, which is generally defined as a set of ordinary
-differential equations.}
+kinetic model, which is generally defined as a set of ordinary differential
+equations.}
\item{odeini}{A numeric vector containing the initial values of the state
variables of the model. Note that the state variables can differ from the
@@ -63,31 +64,33 @@ variables. The third possibility "eigen" is faster but not applicable to
some models e.g. using FOMC for the parent compound.}
\item{use_compiled}{If set to \code{FALSE}, no compiled version of the
-\code{\link{mkinmod}} model is used, even if is present.}
+\link{mkinmod} model is used, even if is present.}
-\item{method.ode}{The solution method passed via \code{\link{mkinpredict}}
-to \code{\link{ode}} in case the solution type is "deSolve". The default
-"lsoda" is performant, but sometimes fails to converge.}
+\item{method.ode}{The solution method passed via \link{mkinpredict} to \link{ode}] in
+case the solution type is "deSolve". The default "lsoda" is performant, but
+sometimes fails to converge.}
-\item{atol}{Absolute error tolerance, passed to \code{\link{ode}}. Default
-is 1e-8, lower than in \code{\link{lsoda}}.}
+\item{atol}{Absolute error tolerance, passed to \link{ode}. Default is 1e-8,
+lower than in \link{lsoda}.}
-\item{rtol}{Absolute error tolerance, passed to \code{\link{ode}}. Default
-is 1e-10, much lower than in \code{\link{lsoda}}.}
+\item{rtol}{Absolute error tolerance, passed to \link{ode}. Default is 1e-10,
+much lower than in \link{lsoda}.}
+
+\item{maxsteps}{Maximum number of steps, passed to \link{ode}.}
\item{map_output}{Boolean to specify if the output should list values for
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.}
-\item{na_stop}{Should it be an error if deSolve::ode returns NaN values}
+\item{na_stop}{Should it be an error if \link{ode} returns NaN values}
}
\value{
A matrix with the numeric solution in wide format
}
\description{
This function produces a time series for all the observed variables in a
-kinetic model as specified by \code{\link{mkinmod}}, using a specific set of
+kinetic model as specified by \link{mkinmod}, using a specific set of
kinetic parameters and initial values for the state variables.
}
\examples{

Contact - Imprint