From b4ac7f030fdb467ee995a7e12314d80633a72668 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 6 Sep 2018 11:53:38 +0200 Subject: Static documentation rebuilt by pkgdown --- docs/articles/FOCUS_D.html | 18 ++-- docs/articles/FOCUS_L.html | 162 +++++++++++++++---------------- docs/articles/FOCUS_Z.html | 168 ++++++++++++++++----------------- docs/articles/compiled_models.html | 90 +++++++++--------- docs/articles/mkin.html | 58 ++++++------ docs/articles/twa.html | 2 +- docs/index.html | 2 +- docs/news/index.html | 6 +- docs/pkgdown.yml | 2 +- docs/reference/Extract.mmkin.html | 12 +-- docs/reference/mccall81_245T.html | 6 +- docs/reference/mkinfit.html | 19 ++-- docs/reference/mkinpredict.html | 4 +- docs/reference/summary.mkinfit.html | 6 +- docs/reference/transform_odeparms.html | 6 +- 15 files changed, 281 insertions(+), 280 deletions(-) diff --git a/docs/articles/FOCUS_D.html b/docs/articles/FOCUS_D.html index 630b1d02..0afabe7f 100644 --- a/docs/articles/FOCUS_D.html +++ b/docs/articles/FOCUS_D.html @@ -84,7 +84,7 @@

Example evaluation of FOCUS Example Dataset D

Johannes Ranke

-

2018-07-18

+

2018-09-06

@@ -94,8 +94,8 @@

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 named parent and m1.

-
library("mkin", quietly = TRUE)
-print(FOCUS_2006_D)
+
library("mkin", quietly = TRUE)
+print(FOCUS_2006_D)
##      name time  value
 ## 1  parent    0  99.46
 ## 2  parent    0 102.04
@@ -143,23 +143,23 @@
 ## 44     m1  120  33.31

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 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.

-
SFO_SFO <- mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"))
+
SFO_SFO <- mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"))
## Successfully compiled differential equation model from auto-generated C code.
-
print(SFO_SFO$diffs)
+
print(SFO_SFO$diffs)
##                                                       parent 
 ## "d_parent = - k_parent_sink * parent - k_parent_m1 * parent" 
 ##                                                           m1 
 ##             "d_m1 = + k_parent_m1 * parent - k_m1_sink * m1"

We do the fitting without progress report (quiet = TRUE).

-
fit <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE)
+
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 all compounds and their residuals.

-
plot_sep(fit, lpos = c("topright", "bottomright"))
+
plot_sep(fit, lpos = c("topright", "bottomright"))

Confidence intervals for the parameter estimates are obtained using the mkinparplot function.

-
mkinparplot(fit)
+
mkinparplot(fit)

A comprehensive report of the results is obtained using the summary method for mkinfit objects.

-
summary(fit)
+
summary(fit)
## mkin version used for fitting:    0.9.47.1 
 ## R version used for fitting:       3.5.1 
 ## Date of fit:     Wed Jul 18 14:52:30 2018 
diff --git a/docs/articles/FOCUS_L.html b/docs/articles/FOCUS_L.html
index 72c293b9..4b324b7e 100644
--- a/docs/articles/FOCUS_L.html
+++ b/docs/articles/FOCUS_L.html
@@ -84,7 +84,7 @@
       

Example evaluation of FOCUS Laboratory Data L1 to L3

Johannes Ranke

-

2018-07-18

+

2018-09-06

@@ -97,28 +97,28 @@

Laboratory Data L1

The following code defines example dataset L1 from the FOCUS kinetics report, p. 284:

-
library("mkin", quietly = TRUE)
-FOCUS_2006_L1 = data.frame(
-  t = rep(c(0, 1, 2, 3, 5, 7, 14, 21, 30), each = 2),
-  parent = c(88.3, 91.4, 85.6, 84.5, 78.9, 77.6,
-             72.0, 71.9, 50.3, 59.4, 47.0, 45.1,
-             27.7, 27.3, 10.0, 10.4, 2.9, 4.0))
-FOCUS_2006_L1_mkin <- mkin_wide_to_long(FOCUS_2006_L1)
+

Here we use the assumptions of simple first order (SFO), the case of declining rate constant over time (FOMC) and the case of two different phases of the kinetics (DFOP). For a more detailed discussion of the models, please see the FOCUS kinetics report.

Since mkin version 0.9-32 (July 2014), we can use shorthand notation like "SFO" for parent only degradation models. The following two lines fit the model and produce the summary report of the model fit. This covers the numerical analysis given in the FOCUS report.

-
m.L1.SFO <- mkinfit("SFO", FOCUS_2006_L1_mkin, quiet = TRUE)
-summary(m.L1.SFO)
-
## mkin version used for fitting:    0.9.47.1 
+
m.L1.SFO <- mkinfit("SFO", FOCUS_2006_L1_mkin, quiet = TRUE)
+summary(m.L1.SFO)
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:17 2018 
-## Date of summary: Wed Jul 18 15:16:17 2018 
+## Date of fit:     Thu Sep  6 11:51:22 2018 
+## Date of summary: Thu Sep  6 11:51:22 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent_sink * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 37 model solutions performed in 0.081 s
+## Fitted with method Port using 37 model solutions performed in 0.085 s
 ## 
 ## Weighting: none
 ## 
@@ -189,27 +189,27 @@ FOCUS_2006_L1_mkin <- 

A plot of the fit is obtained with the plot function for mkinfit objects.

-
plot(m.L1.SFO, show_errmin = TRUE, main = "FOCUS L1 - SFO")
+

The residual plot can be easily obtained by

-
mkinresplot(m.L1.SFO, ylab = "Observed", xlab = "Time")
+
mkinresplot(m.L1.SFO, ylab = "Observed", xlab = "Time")

For comparison, the FOMC model is fitted as well, and the \(\chi^2\) error level is checked.

-
m.L1.FOMC <- mkinfit("FOMC", FOCUS_2006_L1_mkin, quiet=TRUE)
-plot(m.L1.FOMC, show_errmin = TRUE, main = "FOCUS L1 - FOMC")
+

-
summary(m.L1.FOMC, data = FALSE)
-
## mkin version used for fitting:    0.9.47.1 
+
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:19 2018 
-## Date of summary: Wed Jul 18 15:16:19 2018 
+## Date of fit:     Thu Sep  6 11:51:24 2018 
+## Date of summary: Thu Sep  6 11:51:24 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 611 model solutions performed in 1.304 s
+## Fitted with method Port using 611 model solutions performed in 1.348 s
 ## 
 ## Weighting: none
 ## 
@@ -267,19 +267,19 @@ FOCUS_2006_L1_mkin <- 
 Laboratory Data L2
 

The following code defines example dataset L2 from the FOCUS kinetics report, p. 287:

-
FOCUS_2006_L2 = data.frame(
-  t = rep(c(0, 1, 3, 7, 14, 28), each = 2),
-  parent = c(96.1, 91.8, 41.4, 38.7,
-             19.3, 22.3, 4.6, 4.6,
-             2.6, 1.2, 0.3, 0.6))
-FOCUS_2006_L2_mkin <- mkin_wide_to_long(FOCUS_2006_L2)
+

SFO fit for L2

Again, the SFO model is fitted and the result is plotted. The residual plot can be obtained simply by adding the argument show_residuals to the plot command.

-
m.L2.SFO <- mkinfit("SFO", FOCUS_2006_L2_mkin, quiet=TRUE)
-plot(m.L2.SFO, show_residuals = TRUE, show_errmin = TRUE,
-     main = "FOCUS L2 - SFO")
+

The \(\chi^2\) error level of 14% suggests that the model does not fit very well. This is also obvious from the plots of the fit, in which we have included the residual plot.

In the FOCUS kinetics report, it is stated that there is no apparent systematic error observed from the residual plot up to the measured DT90 (approximately at day 5), and there is an underestimation beyond that point.

@@ -289,22 +289,22 @@ FOCUS_2006_L2_mkin <- FOMC fit for L2

For comparison, the FOMC model is fitted as well, and the \(\chi^2\) error level is checked.

-
m.L2.FOMC <- mkinfit("FOMC", FOCUS_2006_L2_mkin, quiet = TRUE)
-plot(m.L2.FOMC, show_residuals = TRUE,
-     main = "FOCUS L2 - FOMC")
+

-
summary(m.L2.FOMC, data = FALSE)
-
## mkin version used for fitting:    0.9.47.1 
+
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:19 2018 
-## Date of summary: Wed Jul 18 15:16:19 2018 
+## Date of fit:     Thu Sep  6 11:51:25 2018 
+## Date of summary: Thu Sep  6 11:51:25 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 81 model solutions performed in 0.175 s
+## Fitted with method Port using 81 model solutions performed in 0.182 s
 ## 
 ## Weighting: none
 ## 
@@ -360,15 +360,15 @@ FOCUS_2006_L2_mkin <- 
 DFOP fit for L2
 

Fitting the four parameter DFOP model further reduces the \(\chi^2\) error level.

-
m.L2.DFOP <- mkinfit("DFOP", FOCUS_2006_L2_mkin, quiet = TRUE)
-plot(m.L2.DFOP, show_residuals = TRUE, show_errmin = TRUE,
-     main = "FOCUS L2 - DFOP")
+

-
summary(m.L2.DFOP, data = FALSE)
-
## mkin version used for fitting:    0.9.47.1 
+
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:20 2018 
-## Date of summary: Wed Jul 18 15:16:20 2018 
+## Date of fit:     Thu Sep  6 11:51:26 2018 
+## Date of summary: Thu Sep  6 11:51:26 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) *
@@ -377,7 +377,7 @@ FOCUS_2006_L2_mkin <- 2006_L2_mkin <- 
 Laboratory Data L3
 

The following code defines example dataset L3 from the FOCUS kinetics report, p. 290.

-
FOCUS_2006_L3 = data.frame(
-  t = c(0, 3, 7, 14, 30, 60, 91, 120),
-  parent = c(97.8, 60, 51, 43, 35, 22, 15, 12))
-FOCUS_2006_L3_mkin <- mkin_wide_to_long(FOCUS_2006_L3)
+

Fit multiple models

As of mkin version 0.9-39 (June 2015), we can fit several models to one or more datasets in one call to the function mmkin. The datasets have to be passed in a list, in this case a named list holding only the L3 dataset prepared above.

-
# Only use one core here, not to offend the CRAN checks
-mm.L3 <- mmkin(c("SFO", "FOMC", "DFOP"), cores = 1,
-               list("FOCUS L3" = FOCUS_2006_L3_mkin), quiet = TRUE)
-plot(mm.L3)
+

The \(\chi^2\) error level of 21% as well as the plot suggest that the SFO model does not fit very well. The FOMC model performs better, with an error level at which the \(\chi^2\) test passes of 7%. Fitting the four parameter DFOP model further reduces the \(\chi^2\) error level considerably.

@@ -456,11 +456,11 @@ mm.L3 <- Accessing mmkin objects

The objects returned by mmkin are arranged like a matrix, with models as a row index and datasets as a column index.

We can extract the summary and plot for e.g. the DFOP fit, using square brackets for indexing which will result in the use of the summary and plot functions working on mkinfit objects.

-
summary(mm.L3[["DFOP", 1]])
-
## mkin version used for fitting:    0.9.47.1 
+
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:21 2018 
-## Date of summary: Wed Jul 18 15:16:21 2018 
+## Date of fit:     Thu Sep  6 11:51:27 2018 
+## Date of summary: Thu Sep  6 11:51:27 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) *
@@ -469,7 +469,7 @@ mm.L3 <-  
plot(mm.L3[["DFOP", 1]], show_errmin = TRUE)
+

Here, a look to the model plot, the confidence intervals of the parameters and the correlation matrix suggest that the parameter estimates are reliable, and the DFOP model can be used as the best-fit model based on the \(\chi^2\) error level criterion for laboratory data L3.

This is also an example where the standard t-test for the parameter g_ilr is misleading, as it tests for a significant difference from zero. In this case, zero appears to be the correct value for this parameter, and the confidence interval for the backtransformed parameter g is quite narrow.

@@ -545,30 +545,30 @@ mm.L3 <- Laboratory Data L4

The following code defines example dataset L4 from the FOCUS kinetics report, p. 293:

-
FOCUS_2006_L4 = data.frame(
-  t = c(0, 3, 7, 14, 30, 60, 91, 120),
-  parent = c(96.6, 96.3, 94.3, 88.8, 74.9, 59.9, 53.5, 49.0))
-FOCUS_2006_L4_mkin <- mkin_wide_to_long(FOCUS_2006_L4)
+

Fits of the SFO and FOMC models, plots and summaries are produced below:

-
# Only use one core here, not to offend the CRAN checks
-mm.L4 <- mmkin(c("SFO", "FOMC"), cores = 1,
-               list("FOCUS L4" = FOCUS_2006_L4_mkin),
-               quiet = TRUE)
-plot(mm.L4)
+

The \(\chi^2\) error level of 3.3% as well as the plot suggest that the SFO model fits very well. The error level at which the \(\chi^2\) test passes is slightly lower for the FOMC model. However, the difference appears negligible.

-
summary(mm.L4[["SFO", 1]], data = FALSE)
-
## mkin version used for fitting:    0.9.47.1 
+
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:22 2018 
-## Date of summary: Wed Jul 18 15:16:22 2018 
+## Date of fit:     Thu Sep  6 11:51:27 2018 
+## Date of summary: Thu Sep  6 11:51:27 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent_sink * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 46 model solutions performed in 0.092 s
+## Fitted with method Port using 46 model solutions performed in 0.107 s
 ## 
 ## Weighting: none
 ## 
@@ -617,18 +617,18 @@ mm.L4 <- 
summary(mm.L4[["FOMC", 1]], data = FALSE)
-
## mkin version used for fitting:    0.9.47.1 
+
+
## mkin version used for fitting:    0.9.47.2 
 ## R version used for fitting:       3.5.1 
-## Date of fit:     Wed Jul 18 15:16:22 2018 
-## Date of summary: Wed Jul 18 15:16:22 2018 
+## Date of fit:     Thu Sep  6 11:51:27 2018 
+## Date of summary: Thu Sep  6 11:51:27 2018 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 66 model solutions performed in 0.137 s
+## Fitted with method Port using 66 model solutions performed in 0.161 s
 ## 
 ## Weighting: none
 ## 
diff --git a/docs/articles/FOCUS_Z.html b/docs/articles/FOCUS_Z.html
index d8b9c961..6e7707f8 100644
--- a/docs/articles/FOCUS_Z.html
+++ b/docs/articles/FOCUS_Z.html
@@ -84,7 +84,7 @@
       

Example evaluation of FOCUS dataset Z

Johannes Ranke

-

2018-07-18

+

2018-09-06

@@ -98,33 +98,33 @@

The data

The following code defines the example dataset from Appendix 7 to the FOCUS kinetics report (FOCUS Work Group on Degradation Kinetics 2014, 354).

-
library(mkin, quietly = TRUE)
-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,
-        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,
-         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,
-         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,
-         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,
-         25.2, 17.2, 4.8, 4.5, 2.8, 4.4))
-
-FOCUS_2006_Z_mkin <- mkin_wide_to_long(FOCUS_2006_Z)
+

Parent and one metabolite

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, with formation and decline of metabolite Z1 and the pathway from parent directly to sink included (default in mkin).

-
Z.2a <- mkinmod(Z0 = mkinsub("SFO", "Z1"),
-                Z1 = mkinsub("SFO"))
+
Z.2a <- mkinmod(Z0 = mkinsub("SFO", "Z1"),
+                Z1 = mkinsub("SFO"))
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.2a <- mkinfit(Z.2a, FOCUS_2006_Z_mkin, quiet = TRUE)
-plot_sep(m.Z.2a)
+
m.Z.2a <- mkinfit(Z.2a, FOCUS_2006_Z_mkin, quiet = TRUE)
+plot_sep(m.Z.2a)

-
summary(m.Z.2a, data = FALSE)$bpar
+
##             Estimate se_notrans    t value     Pr(>t) Lower Upper
 ## Z0_0      9.7015e+01   3.553140 2.7304e+01 1.6793e-21    NA    NA
 ## k_Z0_sink 1.2790e-11   0.226895 5.6368e-11 5.0000e-01    NA    NA
@@ -132,14 +132,14 @@ FOCUS_2006_Z_mkin <- 

As obvious from the parameter summary (the component of the summary), the kinetic rate constant from parent compound Z to sink is very small and the t-test for this parameter suggests that it is not significantly different from zero. 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 formulation:

-
Z.2a.ff <- mkinmod(Z0 = mkinsub("SFO", "Z1"),
-                   Z1 = mkinsub("SFO"),
-                   use_of_ff = "max")
+
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.2a.ff <- mkinfit(Z.2a.ff, FOCUS_2006_Z_mkin, quiet = TRUE)
-plot_sep(m.Z.2a.ff)
+
m.Z.2a.ff <- mkinfit(Z.2a.ff, FOCUS_2006_Z_mkin, quiet = TRUE)
+plot_sep(m.Z.2a.ff)

-
summary(m.Z.2a.ff, data = FALSE)$bpar
+
##            Estimate se_notrans t value     Pr(>t) Lower Upper
 ## Z0_0       97.01488   3.553145 27.3039 1.6793e-21    NA    NA
 ## k_Z0        2.23601   0.216849 10.3114 3.6623e-11    NA    NA
@@ -148,13 +148,13 @@ FOCUS_2006_Z_mkin <- 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. Here, the covariance matrix used for the calculation of confidence intervals is not returned as the model is overparameterised.

A simplified model is obtained by removing the pathway to the sink.

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 metabolite.

-
Z.3 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
-               Z1 = mkinsub("SFO"), use_of_ff = "max")
+
Z.3 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
+               Z1 = mkinsub("SFO"), use_of_ff = "max")
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.3 <- mkinfit(Z.3, FOCUS_2006_Z_mkin, quiet = TRUE)
-plot_sep(m.Z.3)
+
m.Z.3 <- mkinfit(Z.3, FOCUS_2006_Z_mkin, quiet = TRUE)
+plot_sep(m.Z.3)

-
summary(m.Z.3, data = FALSE)$bpar
+
##      Estimate se_notrans t value     Pr(>t)    Lower   Upper
 ## Z0_0 97.01488   2.681772  36.176 2.3636e-25 91.52152 102.508
 ## k_Z0  2.23601   0.146861  15.225 2.2464e-15  1.95453   2.558
@@ -165,28 +165,28 @@ FOCUS_2006_Z_mkin <- 
 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 assumed that there is additional empirical evidence that Z1 quickly and exclusively hydrolyses to Z2.

-
Z.5 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
-               Z1 = mkinsub("SFO", "Z2", sink = FALSE),
-               Z2 = mkinsub("SFO"), use_of_ff = "max")
+
Z.5 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
+               Z1 = mkinsub("SFO", "Z2", sink = FALSE),
+               Z2 = mkinsub("SFO"), use_of_ff = "max")
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.5 <- mkinfit(Z.5, FOCUS_2006_Z_mkin, quiet = TRUE)
-plot_sep(m.Z.5)
+
m.Z.5 <- mkinfit(Z.5, FOCUS_2006_Z_mkin, quiet = TRUE)
+plot_sep(m.Z.5)

Finally, metabolite Z3 is added to the model. We use the optimised differential equation parameter values from the previous fit in order to 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"),
-                   use_of_ff = "max")
+
Z.FOCUS <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
+                   Z1 = mkinsub("SFO", "Z2", sink = FALSE),
+                   Z2 = mkinsub("SFO", "Z3"),
+                   Z3 = mkinsub("SFO"),
+                   use_of_ff = "max")
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.FOCUS <- mkinfit(Z.FOCUS, FOCUS_2006_Z_mkin,
-                     parms.ini = m.Z.5$bparms.ode,
-                     quiet = TRUE)
+
## Warning in mkinfit(Z.FOCUS, FOCUS_2006_Z_mkin, parms.ini = m.Z.5$bparms.ode, : Optimisation by method Port did not converge:
 ## false convergence (8)
-
plot_sep(m.Z.FOCUS)
+
plot_sep(m.Z.FOCUS)

-
summary(m.Z.FOCUS, data = FALSE)$bpar
+
##             Estimate se_notrans t value     Pr(>t)     Lower      Upper
 ## Z0_0       96.837112   2.058861 47.0343 5.5877e-44 92.703779 100.970445
 ## k_Z0        2.215368   0.118098 18.7587 7.6563e-25  1.990525   2.465609
@@ -194,7 +194,7 @@ FOCUS_2006_Z_mkin <- 
-
endpoints(m.Z.FOCUS)
+
endpoints(m.Z.FOCUS)
## $ff
 ##   Z2_Z3 Z2_sink 
 ## 0.47152 0.52848 
@@ -215,61 +215,61 @@ FOCUS_2006_Z_mkin <- Using the SFORB model
 

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 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 fit for Z3 is improved. However, the covariance matrix is not returned.

-
Z.mkin.1 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
-                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
-                    Z2 = mkinsub("SFO", "Z3"),
-                    Z3 = mkinsub("SFORB"))
+
Z.mkin.1 <- mkinmod(Z0 = mkinsub("SFO", "Z1", sink = FALSE),
+                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
+                    Z2 = mkinsub("SFO", "Z3"),
+                    Z3 = mkinsub("SFORB"))
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.mkin.1 <- mkinfit(Z.mkin.1, FOCUS_2006_Z_mkin, quiet = TRUE)
-plot_sep(m.Z.mkin.1)
+
m.Z.mkin.1 <- mkinfit(Z.mkin.1, FOCUS_2006_Z_mkin, quiet = TRUE)
+plot_sep(m.Z.mkin.1)

-
summary(m.Z.mkin.1, data = FALSE)$cov.unscaled
+
## NULL

Therefore, a further stepwise model building is performed starting from the stage of parent and two metabolites, starting from the assumption that the model fit for the parent compound can be improved by using the SFORB model.

-
Z.mkin.3 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
-                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
-                    Z2 = mkinsub("SFO"))
+
Z.mkin.3 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
+                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
+                    Z2 = mkinsub("SFO"))
## Successfully compiled differential equation model from auto-generated C code.
-
m.Z.mkin.3 <- mkinfit(Z.mkin.3, FOCUS_2006_Z_mkin, quiet = TRUE)
-plot_sep(m.Z.mkin.3)
+
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 compound Z0.

Finally, Z3 is added as well. These models appear overparameterised (no covariance matrix returned) if the sink for Z1 is left in the models.

-
Z.mkin.4 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
-                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
-                    Z2 = mkinsub("SFO", "Z3"),
-                    Z3 = mkinsub("SFO"))
+
Z.mkin.4 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
+                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
+                    Z2 = mkinsub("SFO", "Z3"),
+                    Z3 = mkinsub("SFO"))
## Successfully compiled differential equation model from auto-generated C code.
-
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)
+

The error level of the fit, but especially of metabolite Z3, can be improved if the SFORB model is chosen for this metabolite, as this model is capable of representing the tailing of the metabolite decline phase.

-
Z.mkin.5 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
-                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
-                    Z2 = mkinsub("SFO", "Z3"),
-                    Z3 = mkinsub("SFORB"))
+
Z.mkin.5 <- mkinmod(Z0 = mkinsub("SFORB", "Z1", sink = FALSE),
+                    Z1 = mkinsub("SFO", "Z2", sink = FALSE),
+                    Z2 = mkinsub("SFO", "Z3"),
+                    Z3 = mkinsub("SFORB"))
## Successfully compiled differential equation model from auto-generated C code.
-
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)
+

The summary view of the backtransformed parameters shows that we get no confidence intervals due to overparameterisation. As the optimized is excessively small, it seems reasonable to fix it to zero.

-
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",
-                       quiet = TRUE)
-plot_sep(m.Z.mkin.5a)
+

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 is proposed as the best-fit model for the dataset from Appendix 7 of the FOCUS report.

A graphical representation of the confidence intervals can finally be obtained.

-
mkinparplot(m.Z.mkin.5a)
+
mkinparplot(m.Z.mkin.5a)

The endpoints obtained with this model are

-
endpoints(m.Z.mkin.5a)
+
endpoints(m.Z.mkin.5a)
## $ff
 ##   Z0_free_Z1        Z1_Z2      Z2_sink   Z2_Z3_free Z3_free_sink 
 ##      1.00000      1.00000      0.46344      0.53656      1.00000 
diff --git a/docs/articles/compiled_models.html b/docs/articles/compiled_models.html
index 183c9658..17387187 100644
--- a/docs/articles/compiled_models.html
+++ b/docs/articles/compiled_models.html
@@ -84,7 +84,7 @@
       

Performance benefit by using compiled model definitions in mkin

Johannes Ranke

-

2018-07-18

+

2018-09-06

@@ -97,37 +97,37 @@

Model that can also be solved with Eigenvalues

This evaluation is taken from the example section of mkinfit. When using an mkin version 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

-
Sys.which("gcc")
+
##            gcc 
 ## "/usr/bin/gcc"

First, we build a simple degradation model for a parent compound with one metabolite.

-
library("mkin", quietly = TRUE)
-SFO_SFO <- mkinmod(
-  parent = mkinsub("SFO", "m1"),
-  m1 = mkinsub("SFO"))
+
## Successfully compiled differential equation model from auto-generated C code.

We can compare the performance of the Eigenvalue based solution against the compiled version and the R implementation of the differential equations using the benchmark package.

-
if (require(rbenchmark)) {
-  b.1 <- benchmark(
-    "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,
-                                 solution_type = "eigen", quiet = TRUE),
-    "deSolve, compiled" = mkinfit(SFO_SFO, FOCUS_2006_D,
-                                  solution_type = "deSolve", quiet = TRUE),
-    replications = 3)
-  print(b.1)
-  factor_SFO_SFO <- round(b.1["1", "relative"])
-} else {
-  factor_SFO_SFO <- NA
-  print("R package benchmark is not available")
-}
+
## Lade nötiges Paket: rbenchmark
##                    test replications elapsed relative user.self sys.self
-## 3     deSolve, compiled            3   2.044    1.000     2.043        0
-## 1 deSolve, not compiled            3  16.571    8.107    16.565        0
-## 2      Eigenvalue based            3   2.499    1.223     2.496        0
+## 3     deSolve, compiled            3   2.112    1.000     2.110        0
+## 1 deSolve, not compiled            3  16.633    7.875    16.624        0
+## 2      Eigenvalue based            3   2.637    1.249     2.635        0
 ##   user.child sys.child
 ## 3          0         0
 ## 1          0         0
@@ -138,31 +138,31 @@ SFO_SFO <- 
 Model that can not be solved with Eigenvalues
 

This evaluation is also taken from the example section of mkinfit.

-
if (require(rbenchmark)) {
-  FOMC_SFO <- mkinmod(
-    parent = mkinsub("FOMC", "m1"),
-    m1 = mkinsub( "SFO"))
-
-  b.2 <- benchmark(
-    "deSolve, not compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D,
-                                      use_compiled = FALSE, quiet = TRUE),
-    "deSolve, compiled" = mkinfit(FOMC_SFO, FOCUS_2006_D, quiet = TRUE),
-    replications = 3)
-  print(b.2)
-  factor_FOMC_SFO <- round(b.2["1", "relative"])
-} else {
-  factor_FOMC_SFO <- NA
-  print("R package benchmark is not available")
-}
+
## Successfully compiled differential equation model from auto-generated C code.
##                    test replications elapsed relative user.self sys.self
-## 2     deSolve, compiled            3   3.592    1.000     3.589        0
-## 1 deSolve, not compiled            3  35.340    9.839    35.324        0
+## 2     deSolve, compiled            3   3.720    1.000     3.718        0
+## 1 deSolve, not compiled            3  34.677    9.322    34.661        0
 ##   user.child sys.child
 ## 2          0         0
 ## 1          0         0
-

Here we get a performance benefit of a factor of 10 using the version of the differential equation model compiled from C code!

-

This vignette was built with mkin 0.9.47.1 on

+

Here we get a performance benefit of a factor of 9 using the version of the differential equation model compiled from C code!

+

This vignette was built with mkin 0.9.47.2 on

## R version 3.5.1 (2018-07-02)
 ## Platform: x86_64-pc-linux-gnu (64-bit)
 ## Running under: Debian GNU/Linux 9 (stretch)
diff --git a/docs/articles/mkin.html b/docs/articles/mkin.html index 14a2f9b9..234c6885 100644 --- a/docs/articles/mkin.html +++ b/docs/articles/mkin.html @@ -84,7 +84,7 @@

Introduction to mkin

Johannes Ranke

-

2018-07-18

+

2018-09-06

@@ -98,34 +98,34 @@

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. The R add-on package mkin (Ranke 2016) 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 metabolites.

-
library("mkin", quietly = TRUE)
-# Define the kinetic model
-m_SFO_SFO_SFO <- mkinmod(parent = mkinsub("SFO", "M1"),
-                         M1 = mkinsub("SFO", "M2"),
-                         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,
-    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
-# 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,
-                             n = 1, seed = 123456789 )
-
-# Fit the model to the dataset
-f_SFO_SFO_SFO <- mkinfit(m_SFO_SFO_SFO, d_SFO_SFO_SFO_err[[1]], quiet = TRUE)
-
-# Plot the results separately for parent and metabolites
-plot_sep(f_SFO_SFO_SFO, lpos = c("topright", "bottomright", "bottomright"))
+

diff --git a/docs/articles/twa.html b/docs/articles/twa.html index 0c5fe558..1a8a7eb2 100644 --- a/docs/articles/twa.html +++ b/docs/articles/twa.html @@ -84,7 +84,7 @@

Calculation of time weighted average concentrations with mkin

Johannes Ranke

-

2018-07-18

+

2018-09-06

diff --git a/docs/index.html b/docs/index.html index 6796cf1f..11a699ff 100644 --- a/docs/index.html +++ b/docs/index.html @@ -96,7 +96,7 @@

Installation

You can install the latest released version from CRAN from within R:

-
install.packages("mkin")
+

diff --git a/docs/news/index.html b/docs/news/index.html index 7bfa82c4..95995810 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -117,9 +117,9 @@

-
+

-mkin 0.9.47.2 Unreleased +mkin 0.9.47.2 (2018-07-09) 2018-07-19

  • ‘sigma_twocomp’: Rename ‘sigma_rl’ to ‘sigma_twocomp’ as the Rocke and Lorenzato model assumes lognormal distribution for large y. Correct references to the Rocke and Lorenzato model accordingly.

  • @@ -639,7 +639,7 @@

    Contents

    #> mkin version used for fitting: 0.9.47.2 #> R version used for fitting: 3.5.1 -#> Date of fit: Wed Jul 18 15:16:02 2018 -#> Date of summary: Wed Jul 18 15:16:02 2018 +#> Date of fit: Thu Sep 6 11:51:05 2018 +#> Date of summary: Thu Sep 6 11:51:05 2018 #> #> Equations: #> d_T245/dt = - k_T245_sink * T245 - k_T245_phenol * T245 @@ -177,7 +177,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 246 model solutions performed in 1.416 s +#> Fitted with method Port using 246 model solutions performed in 1.51 s #> #> Weighting: none #> diff --git a/docs/reference/mkinfit.html b/docs/reference/mkinfit.html index 9e59c7e6..e99e7d9e 100644 --- a/docs/reference/mkinfit.html +++ b/docs/reference/mkinfit.html @@ -325,13 +325,13 @@ weight

    only if err=NULL: how to weight the residuals, one of "none", - "std", "mean", see details of modCost, or "tc" for the - two component error model of Rocke and Lorenzato.

    + "std", "mean", see details of modCost, or "tc" for the + two component error model.

    tc -

    The two components of the Rocke and Lorenzato error model as used - for (initial) weighting

    +

    The two components of the error model as used for (initial) + weighting

    scaleVar @@ -367,7 +367,8 @@ reweight.tol or up to the maximum number of iterations specified by reweight.max.iter. The second reweighting method is called "tc" (two-component error model). - When using this method, the two components an error model similar to + When using this method, the two components of an error model similar to + the one described by Rocke and Lorenzato (1995) are estimated from the fit and the resulting variances are used for weighting the residuals in each iteration until convergence of these components or up to the maximum number of iterations @@ -432,15 +433,15 @@ fit <- mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE) summary(fit)
    #> mkin version used for fitting: 0.9.47.2 #> R version used for fitting: 3.5.1 -#> Date of fit: Wed Jul 18 15:16:04 2018 -#> Date of summary: Wed Jul 18 15:16:04 2018 +#> Date of fit: Thu Sep 6 11:51:08 2018 +#> Date of summary: Thu Sep 6 11:51:08 2018 #> #> Equations: #> d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent #> #> Model predictions using solution type analytical #> -#> Fitted with method Port using 64 model solutions performed in 0.134 s +#> Fitted with method Port using 64 model solutions performed in 0.142 s #> #> Weighting: none #> @@ -509,7 +510,7 @@ m1 = mkinsub("SFO"))
    #> Successfully compiled differential equation model from auto-generated C code.
    # 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)))
    #> User System verstrichen -#> 0.863 0.000 0.864
    coef(fit)
    #> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink +#> 0.895 0.000 0.898
    coef(fit)
    #> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink #> 99.59848 -3.03822 -2.98030 -5.24750
    #> $ff #> parent_sink parent_m1 m1_sink #> 0.485524 0.514476 1.000000 diff --git a/docs/reference/mkinpredict.html b/docs/reference/mkinpredict.html index d5357ef6..5e2e5449 100644 --- a/docs/reference/mkinpredict.html +++ b/docs/reference/mkinpredict.html @@ -326,12 +326,12 @@ c(parent = 100, m1 = 0), seq(0, 20, by = 0.1), solution_type = "deSolve")[201,]))
    #> time parent m1 #> 201 20 4.978707 27.46227
    #> User System verstrichen -#> 0.002 0.000 0.002
    system.time( +#> 0.002 0.000 0.001
    system.time( print(mkinpredict(SFO_SFO, c(k_parent_m1 = 0.05, k_parent_sink = 0.1, k_m1_sink = 0.01), c(parent = 100, m1 = 0), seq(0, 20, by = 0.1), solution_type = "deSolve", use_compiled = FALSE)[201,]))
    #> time parent m1 #> 201 20 4.978707 27.46227
    #> User System verstrichen -#> 0.035 0.000 0.035
+#> 0.035 0.000 0.034