From d2c1ab854491ff047135fa8377400a68499e72de Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 17 Jul 2014 12:53:30 +0200 Subject: Handle non-convergence and maximum number of iterations For details see NEWS.md --- man/mkinfit.Rd | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index bd7f73b7..c99e146c 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -21,7 +21,8 @@ mkinfit(mkinmod, observed, fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], solution_type = "auto", method.ode = "lsoda", - method.modFit = "Marq", + method.modFit = c("Marq", "Port", "SANN", "Nelder-Mead", "BFSG", "CG", "L-BFGS-B"), + maxit.modFit = "auto", control.modFit = list(), transform_rates = TRUE, transform_fractions = TRUE, @@ -102,12 +103,21 @@ mkinfit(mkinmod, observed, recommended as it is less prone to get trapped in local minima and depends less on starting values for parameters. However, it needs more iterations. - When using "Pseudo", "upper" and "lower" need to be specified for the - transformed parameters. + The "Pseudo" algorithm is not included because it needs finite parameter bounds + which are currently not supported. + + The "Newton" algorithm is not included because its number of iterations + can not be controlled by \code{control.modFit} and it does not appear + to provide advantages over the other algorithms. + } + \item{maxit.modFit}{ + Maximum number of iterations in the optimisation. If not "auto", this will + be passed to the method called by \code{\link{modFit}}, overriding + what may be specified in the next argument \code{control.modFit}. } \item{control.modFit}{ Additional arguments passed to the optimisation method used by - \code{\link{modFit}}. + \code{\link{modFit}}. } \item{transform_rates}{ Boolean specifying if kinetic rate constants should be transformed in the -- cgit v1.2.1 From a1567638a3ba9f4d62fa199525097a94ddfd7912 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Mon, 21 Jul 2014 08:20:44 +0200 Subject: Bugfix, model shorthand, state.ini[[1]] from observed data - The bug occurred when using transform_rates=FALSE for FOMC, DFOP or HS - Make it possible to use mkinfit("SFO", ...) - Take initial mean value at time zero for the variable with the highest value in the observed data - Update of vignette/FOCUS_L - Improve the Makefile to build single vignettes --- man/mkinfit.Rd | 22 ++++++++++++++++------ man/transform_odeparms.Rd | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index c99e146c..581d63f4 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -17,7 +17,7 @@ \usage{ mkinfit(mkinmod, observed, parms.ini = "auto", - state.ini = c(100, rep(0, length(mkinmod$diffs) - 1)), + state.ini = "auto", fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], solution_type = "auto", method.ode = "lsoda", @@ -35,7 +35,11 @@ mkinfit(mkinmod, observed, } \arguments{ \item{mkinmod}{ - A list of class \code{\link{mkinmod}}, containing the kinetic model to be fitted to the data. + A list of class \code{\link{mkinmod}}, containing the kinetic model to be + fitted to the data, or one of the shorthand names ("SFO", "FOMC", "DFOP", + "HS", "SFORB"). If a shorthand name is given, a parent only degradation + model is generated for the observation with the highest value in + \code{observed}. } \item{observed}{ The observed data. It has to be in the long format as described in @@ -65,7 +69,8 @@ mkinfit(mkinmod, observed, case the observed variables are represented by more than one model variable, the names will differ from the names of the observed variables (see \code{map} component of \code{\link{mkinmod}}). The default is to set - the initial value of the first model variable to 100 and all others to 0. + the initial value of the first model variable to the mean of the time zero + values for the variable with the maximum observed value, and all others to 0. } \item{fixed_parms}{ The names of parameters that should not be optimised but rather kept at the @@ -124,8 +129,9 @@ mkinfit(mkinmod, observed, model specification used in the fitting for better compliance with the assumption of normal distribution of the estimator. If TRUE, also alpha and beta parameters of the FOMC model are log-transformed, as well - as k1 and k2 rate constants for the DFOP and HS models. - If TRUE, zero is used as a lower bound for the rates in the optimisation. + as k1 and k2 rate constants for the DFOP and HS models and the break point + tb of the HS model. + If FALSE, zero is used as a lower bound for the rates in the optimisation. } \item{transform_fractions}{ Boolean specifying if formation fractions constants should be transformed in the @@ -204,9 +210,13 @@ mkinfit(mkinmod, observed, other GUI derivative of mkin, sponsored by Syngenta. } \author{ - Johannes Ranke + Johannes Ranke } \examples{ +# Use shorthand notation for parent only degradation +fit <- mkinfit("FOMC", FOCUS_2006_C) +summary(fit) + # One parent compound, one metabolite, both single first order. SFO_SFO <- mkinmod( parent = list(type = "SFO", to = "m1", sink = TRUE), diff --git a/man/transform_odeparms.Rd b/man/transform_odeparms.Rd index ea0b5024..ba93af7d 100644 --- a/man/transform_odeparms.Rd +++ b/man/transform_odeparms.Rd @@ -41,7 +41,7 @@ backtransform_odeparms(transparms, mkinmod, assumption of normal distribution of the estimator. If TRUE, also alpha and beta parameters of the FOMC model are log-transformed, as well as k1 and k2 rate constants for the DFOP and HS models and the break point tb - of the HS model + of the HS model. } \item{transform_fractions}{ Boolean specifying if formation fractions constants should be transformed in the -- cgit v1.2.1 From 9b947f0358d3a1b1fc922bfd0187ca444ce5811d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 24 Jul 2014 14:42:59 +0200 Subject: Bump version, better default for state.ini --- man/mkinfit.Rd | 1 + 1 file changed, 1 insertion(+) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 581d63f4..4e331e2a 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -71,6 +71,7 @@ mkinfit(mkinmod, observed, (see \code{map} component of \code{\link{mkinmod}}). The default is to set the initial value of the first model variable to the mean of the time zero values for the variable with the maximum observed value, and all others to 0. + If this variable has no time zero observations, its initial value is set to 100. } \item{fixed_parms}{ The names of parameters that should not be optimised but rather kept at the -- cgit v1.2.1 From 7416e25376726d24be67c8802cb56cb18acaebf8 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 24 Jul 2014 14:52:27 +0200 Subject: Semantic correction in help file --- man/mkinfit.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 4e331e2a..e1c9b497 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -38,7 +38,7 @@ mkinfit(mkinmod, observed, A list of class \code{\link{mkinmod}}, containing the kinetic model to be fitted to the data, or one of the shorthand names ("SFO", "FOMC", "DFOP", "HS", "SFORB"). If a shorthand name is given, a parent only degradation - model is generated for the observation with the highest value in + model is generated for the observed variable with the highest value in \code{observed}. } \item{observed}{ -- cgit v1.2.1 From f9e3f7964623530983f8c0665df06602d6283ff7 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 24 Jul 2014 14:54:39 +0200 Subject: Improve formulation --- man/mkinfit.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index e1c9b497..8c36e77e 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -38,7 +38,7 @@ mkinfit(mkinmod, observed, A list of class \code{\link{mkinmod}}, containing the kinetic model to be fitted to the data, or one of the shorthand names ("SFO", "FOMC", "DFOP", "HS", "SFORB"). If a shorthand name is given, a parent only degradation - model is generated for the observed variable with the highest value in + model is generated for the variable with the highest value in \code{observed}. } \item{observed}{ -- cgit v1.2.1 From f30472ecd2afea6bd2153b8ad2bb2f663f3a2742 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Mon, 25 Aug 2014 10:39:40 +0200 Subject: Bug fix and unit tests for mkinerrmin See NEWS.md for details --- man/mkinerrmin.Rd | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'man') diff --git a/man/mkinerrmin.Rd b/man/mkinerrmin.Rd index c43d87a1..78ab414e 100644 --- a/man/mkinerrmin.Rd +++ b/man/mkinerrmin.Rd @@ -34,6 +34,16 @@ mkinerrmin(fit, alpha = 0.05) \details{ This function is used internally by \code{\link{summary.mkinfit}}. } +\examples{ +SFO_SFO = mkinmod(parent = list(type = "SFO", to = "m1"), + m1 = list(type = "SFO"), + use_of_ff = "max") + +fit_FOCUS_D = mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE) +round(mkinerrmin(fit_FOCUS_D), 4) +fit_FOCUS_E = mkinfit(SFO_SFO, FOCUS_2006_E, quiet = TRUE) +round(mkinerrmin(fit_FOCUS_E), 4) +} \references{ FOCUS (2006) \dQuote{Guidance Document on Estimating Persistence and Degradation Kinetics from Environmental Fate Studies on Pesticides in EU -- cgit v1.2.1 From ceabddf8bf8bd43f1b57edf112a0fe11c76f5251 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 14 Oct 2014 20:30:15 +0200 Subject: Add a comment about transforming fractions --- man/mkinfit.Rd | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 8c36e77e..21af9a05 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -9,6 +9,12 @@ deviation between the kinetic model and the observed data. This model cost is then minimised using the Levenberg-Marquardt algorithm \code{\link{nls.lm}}, using the specified initial or fixed parameters and starting values. + Per default, parameters in the kinetic models are internally transformed in order + to better satisfy the assumption of a normal distribution of their estimators. + If fitting with transformed fractions leads to a suboptimal fit, doing a + first run without transforming fractions may help. A final + run using the optimised parameters from the previous run as starting values + can then be performed with transformed fractions. In each step of the optimsation, the kinetic model is solved using the function \code{\link{mkinpredict}}. The variance of the residuals for each observed variable can optionally be iteratively reweighted until convergence @@ -138,10 +144,10 @@ mkinfit(mkinmod, observed, Boolean specifying if formation fractions constants should be transformed in the model specification used in the fitting for better compliance with the assumption of normal distribution of the estimator. The default (TRUE) is - to do transformations. The g parameter of the DFOP and HS models are also - transformed, as they can also be seen as compositional data. The - transformation used for these transformations is the \code{\link{ilr}} - transformation. + to do transformations. If TRUE, the g parameter of the DFOP and HS + models are also transformed, as they can also be seen as compositional + data. The transformation used for these transformations is the + \code{\link{ilr}} transformation. } \item{plot}{ Should the observed values and the numerical solutions be plotted at each -- cgit v1.2.1 From 65d31e345f9e61e9d05584b24df6a01c6c6ed18d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 15 Oct 2014 01:13:48 +0200 Subject: Switch to using the Port algorithm per default --- man/mkinfit.Rd | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'man') diff --git a/man/mkinfit.Rd b/man/mkinfit.Rd index 21af9a05..c40dff83 100644 --- a/man/mkinfit.Rd +++ b/man/mkinfit.Rd @@ -7,14 +7,10 @@ This function uses the Flexible Modelling Environment package \code{\link{FME}} to create a function calculating the model cost, i.e. the deviation between the kinetic model and the observed data. This model cost is - then minimised using the Levenberg-Marquardt algorithm \code{\link{nls.lm}}, + then minimised using the Port algorithm \code{\link{nlminb}}, using the specified initial or fixed parameters and starting values. Per default, parameters in the kinetic models are internally transformed in order to better satisfy the assumption of a normal distribution of their estimators. - If fitting with transformed fractions leads to a suboptimal fit, doing a - first run without transforming fractions may help. A final - run using the optimised parameters from the previous run as starting values - can then be performed with transformed fractions. In each step of the optimsation, the kinetic model is solved using the function \code{\link{mkinpredict}}. The variance of the residuals for each observed variable can optionally be iteratively reweighted until convergence @@ -27,7 +23,7 @@ mkinfit(mkinmod, observed, fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], solution_type = "auto", method.ode = "lsoda", - method.modFit = c("Marq", "Port", "SANN", "Nelder-Mead", "BFSG", "CG", "L-BFGS-B"), + method.modFit = c("Port", "Marq", "SANN", "Nelder-Mead", "BFSG", "CG", "L-BFGS-B"), maxit.modFit = "auto", control.modFit = list(), transform_rates = TRUE, @@ -107,13 +103,17 @@ mkinfit(mkinmod, observed, "lsoda" is performant, but sometimes fails to converge. } \item{method.modFit}{ - The optimisation method passed to \code{\link{modFit}}. The default "Marq" - is the Levenberg Marquardt algorithm \code{\link{nls.lm}} from the package - \code{minpack.lm} and usually needs the least number of iterations. + The optimisation method passed to \code{\link{modFit}}. - For more complex problems where local minima occur, the "Port" algorithm is - recommended as it is less prone to get trapped in local minima and depends - less on starting values for parameters. However, it needs more iterations. + In order to optimally deal with problems where local minima occur, the + "Port" algorithm is now used per default as it is less prone to get trapped + in local minima and depends less on starting values for parameters than + the Levenberg Marquardt variant selected by "Marq". However, "Port" needs + more iterations. + + The former default "Marq" is the Levenberg Marquardt algorithm + \code{\link{nls.lm}} from the package \code{minpack.lm} and usually needs + the least number of iterations. The "Pseudo" algorithm is not included because it needs finite parameter bounds which are currently not supported. -- cgit v1.2.1 From 79fdb787e2e79a70e27cf8a3191aa6a0ac2ac2e3 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 29 Oct 2014 13:25:08 +0100 Subject: Correct name of the DFOP model according to FOCUS kinetics --- man/DFOP.solution.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'man') diff --git a/man/DFOP.solution.Rd b/man/DFOP.solution.Rd index d30cf7f3..2d8b1735 100644 --- a/man/DFOP.solution.Rd +++ b/man/DFOP.solution.Rd @@ -2,7 +2,7 @@ \Rdversion{1.1} \alias{DFOP.solution} \title{ -Dual First-Order in Parallel kinetics +Double First-Order in Parallel kinetics } \description{ Function describing decline from a defined starting value using the sum -- cgit v1.2.1