From 85cb80385bb26f40d1c1a40bbda457dd29c4cc23 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 4 Nov 2022 18:09:50 +0100 Subject: 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). --- R/mkinpredict.R | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) (limited to 'R/mkinpredict.R') 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, ... ) } -- cgit v1.2.1