- Notifications
You must be signed in to change notification settings - Fork4
R package for fitting kinetic models with one or more state variables to chemical degradation data
jranke/mkin
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
TheR packagemkin provides calculation routines for the analysis ofchemical degradation data, includingmulticompartmentkinetics asneeded for modelling the formation and decline of transformation products, orif several degradation compartments are involved. It provides stable functionalityfor kinetic evaluations according to the FOCUS guidance (see below for details).In addition, it provides functionality to do hierarchical kinetics based onnonlinear mixed-effects models.
You can install the latest released version fromCRAN from within R:
install.packages("mkin")
In the regulatory evaluation of chemical substances like plant protectionproducts (pesticides), biocides and other chemicals, degradation data play animportant role. For the evaluation of pesticide degradation experiments,detailed guidance and various helpful tools have been developed as detailed in'Credits and historical remarks' below. This package aims to provide a onestop solution for degradation kinetics, addressing modellers that are willingto, or even prefer to work with R.
For a start, have a look at the code examples provided forplot.mkinfit
andplot.mmkin
, andat the package vignettesFOCUS L
andFOCUS D
.
The HTML documentation of the latest version released to CRAN is available atjrwb.de andgithub.
Documentation of the developmentversion is found in the'dev' subdirectory.In the articles section of this documentation, you can also find demonstrationsof the application of nonlinear hierarchical models, also known as nonlinearmixed-effects models, to more complex data, including transformation productsand covariates.
- Highly flexible model specification using
mkinmod
,including equilibrium reactions and using the single first-order reversiblebinding (SFORB) model, which will automatically create two state variablesfor the observed variable. - Model solution (forward modelling) in the function
mkinpredict
is performed either using the analytical solution for the case ofparent only degradation or some simple models involving a single transformationproduct, , an eigenvalue based solution if only simple first-order (SFO) orSFORB kinetics are used in the model, or using a numeric solver from thedeSolve
package (default islsoda
). - The usual one-sided t-test for significant difference from zero isshown based on estimators for the untransformed parameters.
- Summary and plotting functions. The
summary
of anmkinfit
object is infact a full report that should give enough information to be able toapproximately reproduce the fit with other tools. - The chi-squared error level as defined in the FOCUS kinetics guidance(see below) is calculated for each observed variable.
- The 'variance by variable' error model which is often fitted usingIteratively Reweighted Least Squares (IRLS) can be specified as
error_model = "obs"
.
- Three different error models can be selected using the argument
error_model
to themkinfit
function. A two-component error model similar to the one proposed byRocke and Lorenzatocan be selected using the argumenterror_model = "tc"
. - Model comparisons using the Akaike Information Criterion (AIC) are supportedwhich can also be used for non-constant variance. In such cases the FOCUSchi-squared error level is not meaningful.
- By default, kinetic rate constants and kinetic formation fractions aretransformed internally using
transform_odeparms
so their estimators can more reasonably be expected to followa normal distribution. - When parameter estimates are backtransformed to match the model definition,confidence intervals calculated from standard errors are also backtransformedto the correct scale, and will not include meaningless values like negativerate constants or formation fractions adding up to more than 1, which cannotoccur in a single experiment with a single defined radiolabel position.
- When a metabolite decline phase is not described well by SFO kinetics,SFORB kinetics can be used for the metabolite. Mathematically, the SFORB modelis equivalent to the DFOP model. However, the SFORB model has the advantagethat there is a mechanistic interpretation of the model parameters.
- Nonlinear mixed-effects models (hierarchical models) can be created from fitsof the same degradation model to different datasets for the same compound byusing thenlme.mmkin andsaem.mmkinmethods. Note that the convergence of the nlme fits depends on the quality ofthe data. Convergence is better for simple models and data for many groups(e.g. soils). The saem method uses the
saemix
package as a backend. Analyticalsolutions suitable for use with this package have been implemented for parentonly models and the most important models including one metabolite (SFO-SFOand DFOP-SFO). Fitting other models withsaem.mmkin
, while it makes useof the compiled ODE models that mkin provides, has longer run times (from a coupleof minutes to more than an hour).
- Parallel fitting of several models to several datasets is supported, see forexample
plot.mmkin
. - If a C compiler is installed, the kinetic models are compiled from automaticallygenerated C code, seevignette
compiled_models
.The autogeneration of C code wasinspired by theccSolve
package. Thanksto Karline Soetaert for her work on that. - Even if no compiler is installed, many degradation models still givevery good performance,as current versions of mkin also haveanalytical solutions for some modelswith one metabolite, and ifSFO or SFORB are used for the parent compound, Eigenvalue based solutions ofthe degradation model are available.
There is a graphical user interface that may be useful. Pleaserefer to itsdocumentation pagefor installation instructions and a manual. It only supportsevaluations using (generalised) nonlinear regression, butnot simultaneous fits using nonlinear mixed-effects models.
There is a list of changes for the latestCRAN releaseand one for each github branch, e.g.the main branch.
mkin
would not be possible without the underlying software stack consisting of,among others, R and the packagedeSolve.In previous version,mkin
was also using the functionality of theFME package. Please refer to thepackage page on CRAN for the full listof imported and suggested R packages. Also,Debian Linux,the vim editor and theNvim-R plugin havebeen invaluable in its development.
mkin
could not have been written without me being introduced to regulatory fatemodelling of pesticides by Adrian Gurney during my time at Harlan LaboratoriesLtd (formerly RCC Ltd).mkin
greatly profits from and largely followsthe work done by theFOCUS Degradation Kinetics Workgroup,as detailed in their guidance document from 2006, slightly updated in 2011 andin 2014.
Also, it was inspired by the first version of KinGUI developed byBayerCropScience, which is based on the MatLab runtime environment.
The companion packagekinfit (now deprecated) wasstarted in 2008 andfirst published onCRAN on 01 May 2010.
The firstmkin
code waspublished on 11 May 2010 and thefirst CRAN versionon 18 May 2010.
In 2011, Bayer Crop Science started to distribute an R based successor to KinGUI namedKinGUII whose R code is based onmkin
, but which added, among otherrefinements, a closed source graphical user interface (GUI), iterativelyreweighted least squares (IRLS) optimisation of the variance for each of theobserved variables, and Markov Chain Monte Carlo (MCMC) simulationfunctionality, similar to what is available e.g. in theFME
package.
Somewhat in parallel, Syngenta has sponsored the development of anmkin
andKinGUII based GUI application called CAKE, which also adds IRLS and MCMC, ismore limited in the model formulation, but puts more weight on usability.CAKE is available for download from theCAKEwebsite, where you can alsofind a zip archive of the R scripts derived frommkin
, published under the GPLlicense.
Finally, there isKineticEval, which containssome further development of the scripts used for KinGUII.
Thanks to René Lehmann, formerly working at the Umweltbundesamt, for the nicecooperation on parameter transformations, especially the isometric log-ratiotransformation that is now used for formation fractions in case there are morethan two transformation targets.
Many inspirations for improvements of mkin resulted from doing kinetic evaluationsof degradation data for my clients while working at Harlan Laboratories andat Eurofins Regulatory AG, and now as an independent consultant.
Funding was received from the Umweltbundesamt in the course of the projects
- Project Number 27452 (Testing and validation of modelling software as an alternativeto ModelMaker 4.0, 2014-2015)
- Project Number 56703 (Optimization of gmkin for routine use in the Umweltbundesamt, 2015)
- Project Number 92570 (Update of Project Number 27452, 2017-2018)
- Project Number 112407 (Testing the feasibility of using an error modelaccording to Rocke and Lorenzato for more realistic parameter estimates inthe kinetic evaluation of degradation data, 2018-2019)
- Project Number 120667 (Development of objective criteria for the evaluationof the visual fit in the kinetic evaluation of degradation data, 2019-2020)
- Project Number 146839 (Checking the feasibility of using mixed-effects models forthe derivation of kinetic modelling parameters from degradation studies, 2020-2021)
- Project Number 173340 (Application of nonlinear hierarchical models to thekinetic evaluation of chemical degradation data)
Thanks to everyone involved for collaboration and support!
Thanks are due also to Emmanuelle Comets, maintainer of the saemix package, forher interest and support for using the SAEM algorithm and its implementation insaemix for the evaluation of chemical degradation data.
Regarding the application of nonlinear mixed-effects models to degradation data,von Götz et al (1999) have already proposed to use this technique in the contextof environmental risk assessments of pesticides. However, this work wasapparently not followed up, which is why we had to independently arrive at theidea and missed to cite this previous work on the topic in our first publications.
Ranke J (2023) Application of nonlinear hierarchical models to the kinetic evaluation of chemical degradation data - Guidance for the use of an R markdown template file.Umweltbundesamt TEXTE 151/2023 |
Ranke J, Wöltjen J, Schmidt J, and Comets E (2021) Taking kinetic evaluations of degradation data to the next level with nonlinear mixed-effects models.Environments8 (8) 71doi:10.3390/environments8080071 |
Ranke J, Meinecke S (2019) Error Models for the Kinetic Evaluation of Chemical Degradation DataEnvironments6 (12) 124doi:10.3390/environments6120124 |
Ranke J, Wöltjen J, Meinecke S (2018) Comparison of software tools for kinetic evaluation of chemical degradation dataEnvironmental Sciences Europe30 17doi:10.1186/s12302-018-0145-1 |
Von Götz N, Nörtersheuser P, Richter O (1999) Population based analysis of pesticide kineticsChemosphere38 7doi:10.1016/S0045-6535(98)00388-9 |
Contributions are welcome!
About
R package for fitting kinetic models with one or more state variables to chemical degradation data