mkinfit.Rd
This function uses the Flexible Modelling Environment package
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 Port algorithm 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.
In each step of the optimsation, the kinetic model is solved using the
function mkinpredict
. The variance of the residuals for each
observed variable can optionally be iteratively reweighted until convergence
using the argument reweight.method = "obs"
.
mkinfit(mkinmod, observed, parms.ini = "auto", state.ini = "auto", fixed_parms = NULL, fixed_initials = names(mkinmod$diffs)[-1], from_max_mean = FALSE, solution_type = c("auto", "analytical", "eigen", "deSolve"), method.ode = "lsoda", use_compiled = "auto", method.modFit = c("Port", "Marq", "SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B"), maxit.modFit = "auto", control.modFit = list(), transform_rates = TRUE, transform_fractions = TRUE, plot = FALSE, quiet = FALSE, err = NULL, weight = c("none", "manual", "std", "mean", "tc"), tc = c(sigma_low = 0.5, rsd_high = 0.07), scaleVar = FALSE, atol = 1e-8, rtol = 1e-10, n.outtimes = 100, reweight.method = NULL, reweight.tol = 1e-8, reweight.max.iter = 10, trace_parms = FALSE, ...)
mkinmod | A list of class |
---|---|
observed | The observed data. It has to be in the long format as described in
|
parms.ini | A named vector of initial values for the parameters, including parameters
to be optimised and potentially also fixed parameters as indicated by
It is possible to only specify a subset of the parameters that the model needs. You can use the parameter lists "bparms.ode" from a previously fitted model, which contains the differential equation parameters from this model. This works nicely if the models are nested. An example is given below. |
state.ini | A named vector of initial values for the state variables of the model. In
case the observed variables are represented by more than one model
variable, the names will differ from the names of the observed variables
(see |
fixed_parms | The names of parameters that should not be optimised but rather kept at the
values specified in |
fixed_initials | The names of model variables for which the initial state at time 0 should be excluded from the optimisation. Defaults to all state variables except for the first one. |
from_max_mean | If this is set to TRUE, and the model has only one observed variable, then data before the time of the maximum observed value (after averaging for each sampling time) are discarded, and this time is subtracted from all remaining time values, so the time of the maximum observed mean value is the new time zero. |
solution_type | If set to "eigen", the solution of the system of differential equations is
based on the spectral decomposition of the coefficient matrix in cases that
this is possible. If set to "deSolve", a numerical ode solver from package
|
method.ode | The solution method passed via |
use_compiled | If set to |
method.modFit | The optimisation method passed to 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
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 |
maxit.modFit | Maximum number of iterations in the optimisation. If not "auto", this will
be passed to the method called by |
control.modFit | Additional arguments passed to the optimisation method used by
|
transform_rates | Boolean specifying if kinetic rate constants should be transformed in the 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 and the break point tb of the HS model. If FALSE, zero is used as a lower bound for the rates in the optimisation. |
transform_fractions | 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. 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
|
plot | Should the observed values and the numerical solutions be plotted at each stage of the optimisation? |
quiet | Suppress printing out the current model cost after each improvement? |
err | either |
weight | only if |
tc | The two components of the error model as used for (initial) weighting |
scaleVar | Will be passed to |
atol | Absolute error tolerance, passed to |
rtol | Absolute error tolerance, passed to |
n.outtimes | The length of the dataseries that is produced by the model prediction
function |
reweight.method | The method used for iteratively reweighting residuals, also known
as iteratively reweighted least squares (IRLS). Default is NULL,
i.e. no iterative weighting.
The first reweighting method is called "obs", meaning that each
observed variable is assumed to have its own variance. This variance
is estimated from the fit (mean squared residuals) and used for weighting
the residuals in each iteration until convergence of this estimate up to
|
reweight.tol | Tolerance for convergence criterion for the variance components in IRLS fits. |
reweight.max.iter | Maximum iterations in IRLS fits. |
trace_parms | Should a trace of the parameter values be listed? |
… | Further arguments that will be passed to |
A list with "mkinfit" and "modFit" in the class attribute.
A summary can be obtained by summary.mkinfit
.
Plotting methods plot.mkinfit
and
mkinparplot
.
Comparisons of models fitted to the same data can be made using AIC
by virtue of the method logLik.mkinfit
.
Fitting of several models to several datasets in a single call to
mmkin
.
The implementation of iteratively reweighted least squares is inspired by the work of the KinGUII team at Bayer Crop Science (Walter Schmitt and Zhenglei Gao). A similar implemention can also be found in CAKE 2.0, which is the other GUI derivative of mkin, sponsored by Syngenta.
When using the "IORE" submodel for metabolites, fitting with "transform_rates = TRUE" (the default) often leads to failures of the numerical ODE solver. In this situation it may help to switch off the internal rate transformation.
Rocke, David M. und Lorenzato, Stefan (1995) A two-component model for measurement error in analytical chemistry. Technometrics 37(2), 176-184.
# Use shorthand notation for parent only degradation fit <- mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE)#> Error in mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE): konnte Funktion "mkinfit" nicht findensummary(fit)#> Error in summary(fit): Objekt 'fit' nicht gefunden# One parent compound, one metabolite, both single first order. # Use mkinsub for convenience in model formulation. Pathway to sink included per default. SFO_SFO <- mkinmod( parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"))#> Error in mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO")): konnte Funktion "mkinmod" nicht finden# Fit the model to the FOCUS example dataset D using defaults print(system.time(fit <- mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "eigen", quiet = TRUE)))#> Error in mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "eigen", quiet = TRUE): konnte Funktion "mkinfit" nicht finden#>coef(fit)#> Error in coef(fit): Objekt 'fit' nicht gefundenendpoints(fit)#> Error in endpoints(fit): konnte Funktion "endpoints" nicht finden# deSolve is slower when no C compiler (gcc) was available during model generation print(system.time(fit.deSolve <- mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "deSolve")))#> Error in mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "deSolve"): konnte Funktion "mkinfit" nicht finden#>coef(fit.deSolve)#> Error in coef(fit.deSolve): Objekt 'fit.deSolve' nicht gefundenendpoints(fit.deSolve)#> Error in endpoints(fit.deSolve): konnte Funktion "endpoints" nicht finden# Use stepwise fitting, using optimised parameters from parent only fit, FOMC#> Error in mkinmod(parent = mkinsub("FOMC", "m1"), m1 = mkinsub("SFO")): konnte Funktion "mkinmod" nicht finden# Fit the model to the FOCUS example dataset D using defaults fit.FOMC_SFO <- mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE)#> Error in mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE): konnte Funktion "mkinfit" nicht finden# Use starting parameters from parent only FOMC fit fit.FOMC = mkinfit("FOMC", FOCUS_2006_D, quiet = TRUE)#> Error in mkinfit("FOMC", FOCUS_2006_D, quiet = TRUE): konnte Funktion "mkinfit" nicht findenfit.FOMC_SFO <- mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE, parms.ini = fit.FOMC$bparms.ode)#> Error in mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE, parms.ini = fit.FOMC$bparms.ode): konnte Funktion "mkinfit" nicht finden# Use stepwise fitting, using optimised parameters from parent only fit, SFORB SFORB_SFO <- mkinmod( parent = list(type = "SFORB", to = "m1", sink = TRUE), m1 = list(type = "SFO"))#> Error in mkinmod(parent = list(type = "SFORB", to = "m1", sink = TRUE), m1 = list(type = "SFO")): konnte Funktion "mkinmod" nicht finden# Fit the model to the FOCUS example dataset D using defaults fit.SFORB_SFO <- mkinfit(SFORB_SFO, FOCUS_2006_D, quiet = TRUE)#> Error in mkinfit(SFORB_SFO, FOCUS_2006_D, quiet = TRUE): konnte Funktion "mkinfit" nicht findenfit.SFORB_SFO.deSolve <- mkinfit(SFORB_SFO, FOCUS_2006_D, solution_type = "deSolve", quiet = TRUE)#> Error in mkinfit(SFORB_SFO, FOCUS_2006_D, solution_type = "deSolve", quiet = TRUE): konnte Funktion "mkinfit" nicht finden# Use starting parameters from parent only SFORB fit (not really needed in this case) fit.SFORB = mkinfit("SFORB", FOCUS_2006_D, quiet = TRUE)#> Error in mkinfit("SFORB", FOCUS_2006_D, quiet = TRUE): konnte Funktion "mkinfit" nicht findenfit.SFORB_SFO <- mkinfit(SFORB_SFO, FOCUS_2006_D, parms.ini = fit.SFORB$bparms.ode, quiet = TRUE)#> Error in mkinfit(SFORB_SFO, FOCUS_2006_D, parms.ini = fit.SFORB$bparms.ode, quiet = TRUE): konnte Funktion "mkinfit" nicht finden# Weighted fits, including IRLS SFO_SFO.ff <- mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"), use_of_ff = "max")#> Error in mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"), use_of_ff = "max"): konnte Funktion "mkinmod" nicht findenf.noweight <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, quiet = TRUE)#> Error in mkinfit(SFO_SFO.ff, FOCUS_2006_D, quiet = TRUE): konnte Funktion "mkinfit" nicht findensummary(f.noweight)#> Error in summary(f.noweight): Objekt 'f.noweight' nicht gefundenf.irls <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, reweight.method = "obs", quiet = TRUE)#> Error in mkinfit(SFO_SFO.ff, FOCUS_2006_D, reweight.method = "obs", quiet = TRUE): konnte Funktion "mkinfit" nicht findensummary(f.irls)#> Error in summary(f.irls): Objekt 'f.irls' nicht gefundenf.w.mean <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, weight = "mean", quiet = TRUE)#> Error in mkinfit(SFO_SFO.ff, FOCUS_2006_D, weight = "mean", quiet = TRUE): konnte Funktion "mkinfit" nicht findensummary(f.w.mean)#> Error in summary(f.w.mean): Objekt 'f.w.mean' nicht gefunden#> Error in mkinfit(SFO_SFO.ff, subset(FOCUS_2006_D, value != 0), err = "value", quiet = TRUE): konnte Funktion "mkinfit" nicht findensummary(f.w.value)#> Error in summary(f.w.value): Objekt 'f.w.value' nicht gefunden# Manual weighting dw <- FOCUS_2006_D errors <- c(parent = 2, m1 = 1) dw$err.man <- errors[FOCUS_2006_D$name] f.w.man <- mkinfit(SFO_SFO.ff, dw, err = "err.man", quiet = TRUE)#> Error in mkinfit(SFO_SFO.ff, dw, err = "err.man", quiet = TRUE): konnte Funktion "mkinfit" nicht findensummary(f.w.man)#> Error in summary(f.w.man): Objekt 'f.w.man' nicht gefundenf.w.man.irls <- mkinfit(SFO_SFO.ff, dw, err = "err.man", quiet = TRUE, reweight.method = "obs")#> Error in mkinfit(SFO_SFO.ff, dw, err = "err.man", quiet = TRUE, reweight.method = "obs"): konnte Funktion "mkinfit" nicht findensummary(f.w.man.irls)#> Error in summary(f.w.man.irls): Objekt 'f.w.man.irls' nicht gefunden