aboutsummaryrefslogtreecommitdiff
path: root/vignettes
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2016-11-17 18:14:32 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2016-11-17 18:23:31 +0100
commitf3f415520c89f9d8526bf6fadc862ebd44be220d (patch)
treee80d26e3b4f56ebe872888bed8f01a21d49b7ff4 /vignettes
parentf52fffd9eab13b7902bf767dd9cd7f0e7abf8069 (diff)
Remove trailing whitespace, clean headers
Also ignore test.R in the top level directory, as it is not meant to be public
Diffstat (limited to 'vignettes')
-rw-r--r--vignettes/FOCUS_D.Rmd6
-rw-r--r--vignettes/FOCUS_Z.Rnw66
-rw-r--r--vignettes/compiled_models.Rmd22
-rw-r--r--vignettes/mkin.Rmd44
4 files changed, 69 insertions, 69 deletions
diff --git a/vignettes/FOCUS_D.Rmd b/vignettes/FOCUS_D.Rmd
index 998cefa4..40bcb157 100644
--- a/vignettes/FOCUS_D.Rmd
+++ b/vignettes/FOCUS_D.Rmd
@@ -18,7 +18,7 @@ library(knitr)
opts_chunk$set(tidy = FALSE, cache = TRUE)
```
-This is just a very simple vignette showing how to fit a degradation model for a parent
+This is just a very simple vignette showing how to fit a degradation model for a parent
compound with one transformation product using `mkin`. After loading the
library we look a the data. We have observed concentrations in the column named
`value` at the times specified in column `time` for the two observed variables
@@ -33,7 +33,7 @@ print(FOCUS_2006_D)
Next we specify the degradation model: The parent compound degrades with simple first-order
kinetics (SFO) to one metabolite named m1, which also degrades with SFO kinetics.
-The call to mkinmod returns a degradation model. The differential equations represented in
+The call to mkinmod returns a degradation model. The differential equations represented in
R code can be found in the character vector `$diffs` of the `mkinmod` object. If
a C compiler (gcc) is installed and functional, the differential equation model will
be compiled from auto-generated C code.
@@ -51,7 +51,7 @@ fit <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE)
```
A plot of the fit including a residual plot for both observed variables is obtained
-using the `plot_sep` method for `mkinfit` objects, which shows separate graphs for
+using the `plot_sep` method for `mkinfit` objects, which shows separate graphs for
all compounds and their residuals.
```{r plot, fig.height = 6, fig.width = 8}
diff --git a/vignettes/FOCUS_Z.Rnw b/vignettes/FOCUS_Z.Rnw
index 5a66db24..5abda0e1 100644
--- a/vignettes/FOCUS_Z.Rnw
+++ b/vignettes/FOCUS_Z.Rnw
@@ -3,7 +3,7 @@
\documentclass[12pt,a4paper]{article}
\usepackage{a4wide}
\input{header}
-\hypersetup{
+\hypersetup{
pdftitle = {Example evaluation of FOCUS dataset Z},
pdfsubject = {Manuscript},
pdfauthor = {Johannes Ranke},
@@ -50,15 +50,15 @@ report \citep{FOCUSkinetics2011}, p.350.
require(mkin)
LOD = 0.5
FOCUS_2006_Z = data.frame(
- t = c(0, 0.04, 0.125, 0.29, 0.54, 1, 2, 3, 4, 7, 10, 14, 21,
+ t = c(0, 0.04, 0.125, 0.29, 0.54, 1, 2, 3, 4, 7, 10, 14, 21,
42, 61, 96, 124),
- Z0 = c(100, 81.7, 70.4, 51.1, 41.2, 6.6, 4.6, 3.9, 4.6, 4.3, 6.8,
+ Z0 = c(100, 81.7, 70.4, 51.1, 41.2, 6.6, 4.6, 3.9, 4.6, 4.3, 6.8,
2.9, 3.5, 5.3, 4.4, 1.2, 0.7),
- Z1 = c(0, 18.3, 29.6, 46.3, 55.1, 65.7, 39.1, 36, 15.3, 5.6, 1.1,
+ Z1 = c(0, 18.3, 29.6, 46.3, 55.1, 65.7, 39.1, 36, 15.3, 5.6, 1.1,
1.6, 0.6, 0.5 * LOD, NA, NA, NA),
- Z2 = c(0, NA, 0.5 * LOD, 2.6, 3.8, 15.3, 37.2, 31.7, 35.6, 14.5,
+ Z2 = c(0, NA, 0.5 * LOD, 2.6, 3.8, 15.3, 37.2, 31.7, 35.6, 14.5,
0.8, 2.1, 1.9, 0.5 * LOD, NA, NA, NA),
- Z3 = c(0, NA, NA, NA, NA, 0.5 * LOD, 9.2, 13.1, 22.3, 28.4, 32.5,
+ Z3 = c(0, NA, NA, NA, NA, 0.5 * LOD, 9.2, 13.1, 22.3, 28.4, 32.5,
25.2, 17.2, 4.8, 4.5, 2.8, 4.4))
FOCUS_2006_Z_mkin <- mkin_wide_to_long(FOCUS_2006_Z)
@@ -66,9 +66,9 @@ FOCUS_2006_Z_mkin <- mkin_wide_to_long(FOCUS_2006_Z)
\section{Parent compound and one metabolite}
-The next step is to set up the models used for the kinetic analysis. As the
+The next step is to set up the models used for the kinetic analysis. As the
simultaneous fit of parent and the first metabolite is usually straightforward,
-Step 1 (SFO for parent only) is skipped here. We start with the model 2a,
+Step 1 (SFO for parent only) is skipped here. We start with the model 2a,
with formation and decline of metabolite Z1 and the pathway from parent
directly to sink included (default in mkin).
@@ -80,15 +80,15 @@ plot_sep(m.Z.2a)
summary(m.Z.2a, data = FALSE)$bpar
@
-As obvious from the parameter summary (the \texttt{bpar} component of the
+As obvious from the parameter summary (the \texttt{bpar} component of the
summary), the kinetic rate constant from parent compound Z to sink
-is negligible. Accordingly, the exact magnitude of the fitted parameter
+is negligible. Accordingly, the exact magnitude of the fitted parameter
\texttt{log k\_Z0\_sink} is ill-defined and the covariance matrix is not
-returned (not shown, would be visible in the complete summary).
+returned (not shown, would be visible in the complete summary).
This suggests, in agreement with the analysis in the FOCUS kinetics report, to
simplify the model by removing the pathway to sink.
-A similar result can be obtained when formation fractions are used in the model
+A similar result can be obtained when formation fractions are used in the model
formulation:
<<FOCUS_2006_Z_fits_2, echo=TRUE, fig.height=6>>=
@@ -104,16 +104,16 @@ summary(m.Z.2a.ff, data = FALSE)$bpar
Here, the ilr transformed formation fraction fitted in the model takes a very
large value, and the backtransformed formation fraction from parent Z to Z1 is
practically unity. Again, the covariance matrix is not returned as the model is
-overparameterised.
+overparameterised.
The simplified model is obtained by setting the list component \texttt{sink} to
\texttt{FALSE}.\footnote{If the model formulation without formation fractions
is used, the same effect can be obtained by fixing the parameter \texttt{k\_Z\_sink}
-to a value of zero.}
+to a value of zero.}
In the following, we use the parameterisation with formation fractions in order
-to be able to compare with the results in the FOCUS guidance, and as it
-makes it easier to use parameters obtained in a previous fit when adding a further
+to be able to compare with the results in the FOCUS guidance, and as it
+makes it easier to use parameters obtained in a previous fit when adding a further
metabolite.
<<FOCUS_2006_Z_fits_3, echo=TRUE, fig.height=6>>=
@@ -130,10 +130,10 @@ to sink, the formation fraction is internally fixed to unity.
\section{Including metabolites Z2 and Z3}
As suggested in the FOCUS report, the pathway to sink was removed for metabolite Z1 as
-well in the next step. While this step appears questionable on the basis of the above results, it
-is followed here for the purpose of comparison. Also, in the FOCUS report, it is
+well in the next step. While this step appears questionable on the basis of the above results, it
+is followed here for the purpose of comparison. Also, in the FOCUS report, it is
assumed that there is additional empirical evidence that Z1 quickly and exclusively
-hydrolyses to Z2.
+hydrolyses to Z2.
<<FOCUS_2006_Z_fits_5, echo=TRUE, fig.height=7>>=
Z.5 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
@@ -151,9 +151,9 @@ accelerate the optimization.
Z.FOCUS <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
Z1 = mkinsub("SFO", "Z2", sink = FALSE),
Z2 = mkinsub("SFO", "Z3"),
- Z3 = mkinsub("SFO"),
+ Z3 = mkinsub("SFO"),
use_of_ff = "max")
-m.Z.FOCUS <- mkinfit(Z.FOCUS, FOCUS_2006_Z_mkin,
+m.Z.FOCUS <- mkinfit(Z.FOCUS, FOCUS_2006_Z_mkin,
parms.ini = m.Z.5$bparms.ode,
quiet = TRUE)
plot_sep(m.Z.FOCUS)
@@ -167,13 +167,13 @@ transformed parameters, however.
\section{Using the SFORB model for parent and metabolites}
-As the FOCUS report states, there is a certain tailing of the time course of metabolite
-Z3. Also, the time course of the parent compound is not fitted very well using the
+As the FOCUS report states, there is a certain tailing of the time course of metabolite
+Z3. Also, the time course of the parent compound is not fitted very well using the
SFO model, as residues at a certain low level remain.
-Therefore, an additional model is offered here, using the single first-order
+Therefore, an additional model is offered here, using the single first-order
reversible binding (SFORB) model for metabolite Z3. As expected, the $\chi^2$
-error level is lower for metabolite Z3 using this model and the graphical
+error level is lower for metabolite Z3 using this model and the graphical
fit for Z3 is improved. However, the covariance matrix is not returned.
<<FOCUS_2006_Z_fits_7, echo=TRUE, fig.height=8>>=
@@ -198,7 +198,7 @@ m.Z.mkin.3 <- mkinfit(Z.mkin.3, FOCUS_2006_Z_mkin, quiet = TRUE)
plot_sep(m.Z.mkin.3)
@
-This results in a much better representation of the behaviour of the parent
+This results in a much better representation of the behaviour of the parent
compound Z0.
Finally, Z3 is added as well. These models appear overparameterised (no
@@ -209,7 +209,7 @@ Z.mkin.4 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
Z1 = mkinsub("SFO", "Z2", sink = FALSE),
Z2 = mkinsub("SFO", "Z3"),
Z3 = mkinsub("SFO"))
-m.Z.mkin.4 <- mkinfit(Z.mkin.4, FOCUS_2006_Z_mkin,
+m.Z.mkin.4 <- mkinfit(Z.mkin.4, FOCUS_2006_Z_mkin,
parms.ini = m.Z.mkin.3$bparms.ode,
quiet = TRUE)
plot_sep(m.Z.mkin.4)
@@ -224,7 +224,7 @@ Z.mkin.5 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
Z1 = mkinsub("SFO", "Z2", sink = FALSE),
Z2 = mkinsub("SFO", "Z3"),
Z3 = mkinsub("SFORB"))
-m.Z.mkin.5 <- mkinfit(Z.mkin.5, FOCUS_2006_Z_mkin,
+m.Z.mkin.5 <- mkinfit(Z.mkin.5, FOCUS_2006_Z_mkin,
parms.ini = m.Z.mkin.4$bparms.ode[1:4],
quiet = TRUE)
plot_sep(m.Z.mkin.5)
@@ -233,10 +233,10 @@ plot_sep(m.Z.mkin.5)
The summary view of the backtransformed parameters shows that we get no
confidence intervals due to overparameterisation. As the optimized
\texttt{k\_Z3\_bound\_free} is excessively small, it seems reasonable to fix it to
-zero.
+zero.
<<FOCUS_2006_Z_fits_11a, echo=TRUE>>=
-m.Z.mkin.5a <- mkinfit(Z.mkin.5, FOCUS_2006_Z_mkin,
+m.Z.mkin.5a <- mkinfit(Z.mkin.5, FOCUS_2006_Z_mkin,
parms.ini = c(m.Z.mkin.5$bparms.ode[1:7],
k_Z3_bound_free = 0),
fixed_parms = "k_Z3_bound_free",
@@ -244,7 +244,7 @@ m.Z.mkin.5a <- mkinfit(Z.mkin.5, FOCUS_2006_Z_mkin,
plot_sep(m.Z.mkin.5a)
@
-As expected, the residual plots for Z0 and Z3 are more random than in the case of the
+As expected, the residual plots for Z0 and Z3 are more random than in the case of the
all SFO model for which they were shown above. In conclusion, the model
\texttt{Z.mkin.5a} is proposed as the best-fit model for the dataset from
Appendix 7 of the FOCUS report.
@@ -261,8 +261,8 @@ The endpoints obtained with this model are
endpoints(m.Z.mkin.5a)
@
-It is clear the degradation rate of Z3 towards the end of the experiment
-is very low as DT50\_Z3\_b2 (the second Eigenvalue of the system of two differential
+It is clear the degradation rate of Z3 towards the end of the experiment
+is very low as DT50\_Z3\_b2 (the second Eigenvalue of the system of two differential
equations representing the SFORB system for Z3, corresponding to the slower rate
constant of the DFOP model) is reported to be infinity. However, this appears
to be a feature of the data.
diff --git a/vignettes/compiled_models.Rmd b/vignettes/compiled_models.Rmd
index 9fd39d81..18e1a462 100644
--- a/vignettes/compiled_models.Rmd
+++ b/vignettes/compiled_models.Rmd
@@ -25,7 +25,7 @@ This evaluation is taken from the example section of mkinfit. When using an mkin
equal to or greater than 0.9-36 and a C compiler (gcc) is available, you will see
a message that the model is being compiled from autogenerated C code when
defining a model using mkinmod. The `mkinmod()` function checks for presence of
-the gcc compiler using
+the gcc compiler using
```{r check_gcc}
Sys.which("gcc")
@@ -48,12 +48,12 @@ the microbenchmark package.
library("microbenchmark")
library("ggplot2")
mb.1 <- microbenchmark(
- "deSolve, not compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
- solution_type = "deSolve",
+ "deSolve, not compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
+ solution_type = "deSolve",
use_compiled = FALSE, quiet = TRUE),
- "Eigenvalue based" = mkinfit(SFO_SFO, FOCUS_2006_D,
+ "Eigenvalue based" = mkinfit(SFO_SFO, FOCUS_2006_D,
solution_type = "eigen", quiet = TRUE),
- "deSolve, compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
+ "deSolve, compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
solution_type = "deSolve", quiet = TRUE),
times = 3, control = list(warmup = 0))
@@ -62,8 +62,8 @@ print(mb.1)
autoplot(mb.1)
```
-We see that using the compiled model is by a factor of
-`r round(smb.1[1, "median"]/smb.1[3, "median"], 1)`
+We see that using the compiled model is by a factor of
+`r round(smb.1[1, "median"]/smb.1[3, "median"], 1)`
faster than using the R version with the default ode solver, and it is even
faster than the Eigenvalue based solution implemented in R which does not need
iterative solution of the ODEs:
@@ -75,7 +75,7 @@ smb.1["median"]/smb.1["deSolve, compiled", "median"]
## Model that can not be solved with Eigenvalues
-This evaluation is also taken from the example section of mkinfit.
+This evaluation is also taken from the example section of mkinfit.
```{r benchmark_FOMC_SFO, fig.height = 3}
FOMC_SFO <- mkinmod(
@@ -83,7 +83,7 @@ FOMC_SFO <- mkinmod(
m1 = mkinsub( "SFO"))
mb.2 <- microbenchmark(
- "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D,
+ "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D,
use_compiled = FALSE, quiet = TRUE),
"deSolve, compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE),
times = 3, control = list(warmup = 0))
@@ -93,8 +93,8 @@ smb.2["median"]/smb.2["deSolve, compiled", "median"]
autoplot(mb.2)
```
-Here we get a performance benefit of a factor of
-`r round(smb.2[1, "median"]/smb.2[2, "median"], 1)`
+Here we get a performance benefit of a factor of
+`r round(smb.2[1, "median"]/smb.2[2, "median"], 1)`
using the version of the differential equation model compiled from C code!
This vignette was built with mkin `r packageVersion("mkin")` on
diff --git a/vignettes/mkin.Rmd b/vignettes/mkin.Rmd
index a3982df9..062bfdac 100644
--- a/vignettes/mkin.Rmd
+++ b/vignettes/mkin.Rmd
@@ -26,8 +26,8 @@ opts_chunk$set(engine='R', tidy=FALSE)
# Abstract
In the regulatory evaluation of chemical substances like plant protection
products (pesticides), biocides and other chemicals, degradation data play an
-important role. For the evaluation of pesticide degradation experiments,
-detailed guidance has been developed, based on nonlinear optimisation.
+important role. For the evaluation of pesticide degradation experiments,
+detailed guidance has been developed, based on nonlinear optimisation.
The `R` add-on package `mkin` [@pkg:mkin] implements fitting some of the models
recommended in this guidance from within R and calculates some statistical
measures for data series within one or more compartments, for parent and
@@ -38,23 +38,23 @@ library(mkin)
# Define the kinetic model
m_SFO_SFO_SFO <- mkinmod(parent = mkinsub("SFO", "M1"),
M1 = mkinsub("SFO", "M2"),
- M2 = mkinsub("SFO"),
+ M2 = mkinsub("SFO"),
use_of_ff = "max", quiet = TRUE)
# Produce model predictions using some arbitrary parameters
sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120)
d_SFO_SFO_SFO <- mkinpredict(m_SFO_SFO_SFO,
- c(k_parent = 0.03,
- f_parent_to_M1 = 0.5, k_M1 = log(2)/100,
+ c(k_parent = 0.03,
+ f_parent_to_M1 = 0.5, k_M1 = log(2)/100,
f_M1_to_M2 = 0.9, k_M2 = log(2)/50),
c(parent = 100, M1 = 0, M2 = 0),
sampling_times)
-# Generate a dataset by adding normally distributed errors with
+# Generate a dataset by adding normally distributed errors with
# standard deviation 3, for two replicates at each sampling time
d_SFO_SFO_SFO_err <- add_err(d_SFO_SFO_SFO, reps = 2,
- sdfunc = function(x) 3,
+ sdfunc = function(x) 3,
n = 1, seed = 123456789 )
# Fit the model to the dataset
@@ -67,7 +67,7 @@ plot_sep(f_SFO_SFO_SFO, lpos = c("topright", "bottomright", "bottomright"))
# Background
Many approaches are possible regarding the evaluation of chemical degradation
-data.
+data.
The now deprecated `kinfit` package [@pkg:kinfit] in `R` [@rcore2016]
implements the approach recommended in the kinetics report provided by the
@@ -91,10 +91,10 @@ models based on differential equations to data.
The code was first uploaded to the BerliOS platform. When this was taken down,
the version control history was imported into the R-Forge site, where the code
-is still mirrored today (see *e.g.*
+is still mirrored today (see *e.g.*
[the initial commit on 11 May 2010](http://cgit.jrwb.de/mkin/commit/?id=30cbb4092f6d2d3beff5800603374a0d009ad770)).
-At that time, the R package `FME` (Flexible Modelling Environment)
+At that time, the R package `FME` (Flexible Modelling Environment)
[@soetaert2010] was already available, and provided a good basis for
developing a package specifically tailored to the task. The remaining challenge
was to make it as easy as possible for the users (including the author of this
@@ -133,16 +133,16 @@ but until 2014, only simple first-order models could be specified for
transformation products. Starting with KinGUII version 2.1, biphasic modelling
of metabolites was also available in KinGUII.
-A further graphical user interface (GUI) that has recently been brought to a decent
-degree of maturity is the browser based GUI named `gmkin`. Please see its
-[documentation page](http://kinfit.r-forge.r-project.org/gmkin_static) and
+A further graphical user interface (GUI) that has recently been brought to a decent
+degree of maturity is the browser based GUI named `gmkin`. Please see its
+[documentation page](http://kinfit.r-forge.r-project.org/gmkin_static) and
[manual](http://kinfit.r-forge.r-project.org/gmkin_static/vignettes/gmkin_manual.html)
for further information.
## Recent developments
Currently (June 2016), the main features available in `mkin` which are
-not present in KinGUII or CAKE, are the speed increase by using compiled code when
+not present in KinGUII or CAKE, are the speed increase by using compiled code when
a compiler is present, parallel model fitting on multicore machines using the
`mmkin` function, and the estimation of parameter confidence intervals based on
transformed parameters. These are explained in more detail below.
@@ -156,9 +156,9 @@ constants [compare @bates1988, p. 135], *i.e.* for their logarithms.
Confidence intervals for the rate constants are then obtained using the
appropriate backtransformation using the exponential function.
-In the first version of `mkin` allowing for specifying models using
+In the first version of `mkin` allowing for specifying models using
formation fractions, a home-made reparameterisation was used in order to ensure
-that the sum of formation fractions would not exceed unity.
+that the sum of formation fractions would not exceed unity.
This method is still used in the current version of KinGUII (v2.1 from April
2014), with a modification that allows for fixing the pathway to sink to zero.
@@ -175,7 +175,7 @@ confidence intervals.
## Confidence intervals based on transformed parameters
In the first attempt at providing improved parameter confidence intervals
-introduced to `mkin` in 2013, confidence intervals obtained from
+introduced to `mkin` in 2013, confidence intervals obtained from
FME on the transformed parameters were simply all backtransformed one by one
to yield asymetric confidence intervals for the backtransformed parameters.
@@ -186,14 +186,14 @@ fractions that quantify the paths to each of the compounds formed from a
specific parent compound, and no such 1:1 relation exists.
Therefore, parameter confidence intervals for formation fractions obtained with
-this method only appear valid for the case of a single transformation product, where
+this method only appear valid for the case of a single transformation product, where
only one formation fraction is to be estimated, directly corresponding to one
component of the ilr transformed parameter.
-The confidence intervals obtained by backtransformation for the cases where a
-1:1 relation between transformed and original parameter exist are considered by
+The confidence intervals obtained by backtransformation for the cases where a
+1:1 relation between transformed and original parameter exist are considered by
the author of this vignette to be more accurate than those obtained using a
-re-estimation of the Hessian matrix after backtransformation, as implemented
+re-estimation of the Hessian matrix after backtransformation, as implemented
in the FME package.
## Parameter t-test based on untransformed parameters
@@ -208,7 +208,7 @@ of the estimator for the parameters, is not fulfilled in the case of nonlinear r
[@ranke2015]. However, this test is commonly used by industry, consultants and
national authorities in order to decide on the reliability of parameter estimates, based
on the FOCUS guidance mentioned above. Therefore, the results of this one-sided
-t-test are included in the summary output from `mkin`.
+t-test are included in the summary output from `mkin`.
As it is not reasonable to test for significant difference of the transformed
parameters (*e.g.* $log(k)$) from zero, the t-test is calculated based on the

Contact - Imprint