From 38f9e15f0c972c1516ae737a2bca8d7789581bbd Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 6 Oct 2016 09:19:21 +0200 Subject: Static documentation rebuilt by pkgdown::build_site() --- docs/articles/FOCUS_D.html | 245 ++++ .../figure-html/unnamed-chunk-5-1.png | Bin 0 -> 74304 bytes .../figure-html/unnamed-chunk-6-1.png | Bin 0 -> 13789 bytes docs/articles/FOCUS_L.html | 661 +++++++++++ .../figure-html/unnamed-chunk-10-1.png | Bin 0 -> 28716 bytes .../figure-html/unnamed-chunk-12-1.png | Bin 0 -> 52644 bytes .../figure-html/unnamed-chunk-13-1.png | Bin 0 -> 21438 bytes .../figure-html/unnamed-chunk-15-1.png | Bin 0 -> 36854 bytes .../figure-html/unnamed-chunk-4-1.png | Bin 0 -> 23253 bytes .../figure-html/unnamed-chunk-5-1.png | Bin 0 -> 14728 bytes .../figure-html/unnamed-chunk-6-1.png | Bin 0 -> 23593 bytes .../figure-html/unnamed-chunk-8-1.png | Bin 0 -> 27575 bytes .../figure-html/unnamed-chunk-9-1.png | Bin 0 -> 28058 bytes docs/articles/compiled_models.html | 146 +++ .../figure-html/benchmark_FOMC_SFO-1.png | Bin 0 -> 9925 bytes .../figure-html/benchmark_SFO_SFO-1.png | Bin 0 -> 11448 bytes docs/articles/index.html | 99 ++ docs/articles/mkin.html | 171 +++ .../mkin_files/figure-html/unnamed-chunk-2-1.png | Bin 0 -> 112161 bytes docs/index.html | 330 ++---- docs/news/index.html | 401 +++++++ docs/pkgdown.css | 59 + docs/pkgdown.js | 13 + docs/reference/DFOP.solution.html | 132 +++ docs/reference/Extract.mmkin.html | 1192 ++++++++++++++++++++ docs/reference/FOCUS_2006_DFOP_ref_A_to_B.html | 129 +++ docs/reference/FOCUS_2006_FOMC_ref_A_to_F.html | 128 +++ docs/reference/FOCUS_2006_HS_ref_A_to_F.html | 129 +++ docs/reference/FOCUS_2006_SFO_ref_A_to_F.html | 127 +++ docs/reference/FOCUS_2006_datasets.html | 130 +++ docs/reference/FOMC.solution.html | 147 +++ docs/reference/HS.solution.html | 131 +++ docs/reference/IORE.solution.html | 149 +++ docs/reference/SFO.solution.html | 124 ++ docs/reference/SFORB.solution.html | 133 +++ docs/reference/add_err.html | 196 ++++ docs/reference/endpoints.html | 123 ++ docs/reference/geometric_mean.html | 115 ++ docs/reference/ilr.html | 152 +++ docs/reference/index.html | 111 ++ docs/reference/mccall81_245T.html | 229 ++++ docs/reference/mkin_long_to_wide.html | 152 +++ docs/reference/mkin_wide_to_long.html | 131 +++ docs/reference/mkinds.html | 120 ++ docs/reference/mkinerrmin.html | 150 +++ docs/reference/mkinfit.html | 531 +++++++++ docs/reference/mkinmod.html | 206 ++++ docs/reference/mkinparplot.html | 122 ++ docs/reference/mkinplot.html | 118 ++ docs/reference/mkinpredict.html | 318 ++++++ docs/reference/mkinresplot.html | 166 +++ docs/reference/mkinsub.html | 147 +++ docs/reference/mmkin.html | 178 +++ docs/reference/plot.mkinfit.html | 231 ++++ docs/reference/plot.mmkin.html | 156 +++ docs/reference/print.mkinds.html | 109 ++ docs/reference/print.mkinmod.html | 109 ++ docs/reference/schaefer07_complex_case.html | 131 +++ docs/reference/summary.mkinfit.html | 229 ++++ docs/reference/synthetic_data_for_UBA.html | 157 +++ docs/reference/transform_odeparms.html | 276 +++++ docs/reference/unknown-10.png | Bin 0 -> 18197 bytes docs/reference/unknown-2.png | Bin 0 -> 10552 bytes docs/reference/unknown-4.png | Bin 0 -> 10559 bytes docs/reference/unknown-6.png | Bin 0 -> 7945 bytes docs/reference/unknown-8.png | Bin 0 -> 13728 bytes 66 files changed, 9217 insertions(+), 222 deletions(-) create mode 100644 docs/articles/FOCUS_D.html create mode 100644 docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-5-1.png create mode 100644 docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-6-1.png create mode 100644 docs/articles/FOCUS_L.html create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-10-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-12-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-13-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-15-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-4-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-5-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-6-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-8-1.png create mode 100644 docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-9-1.png create mode 100644 docs/articles/compiled_models.html create mode 100644 docs/articles/compiled_models_files/figure-html/benchmark_FOMC_SFO-1.png create mode 100644 docs/articles/compiled_models_files/figure-html/benchmark_SFO_SFO-1.png create mode 100644 docs/articles/index.html create mode 100644 docs/articles/mkin.html create mode 100644 docs/articles/mkin_files/figure-html/unnamed-chunk-2-1.png create mode 100644 docs/news/index.html create mode 100644 docs/pkgdown.css create mode 100644 docs/pkgdown.js create mode 100644 docs/reference/DFOP.solution.html create mode 100644 docs/reference/Extract.mmkin.html create mode 100644 docs/reference/FOCUS_2006_DFOP_ref_A_to_B.html create mode 100644 docs/reference/FOCUS_2006_FOMC_ref_A_to_F.html create mode 100644 docs/reference/FOCUS_2006_HS_ref_A_to_F.html create mode 100644 docs/reference/FOCUS_2006_SFO_ref_A_to_F.html create mode 100644 docs/reference/FOCUS_2006_datasets.html create mode 100644 docs/reference/FOMC.solution.html create mode 100644 docs/reference/HS.solution.html create mode 100644 docs/reference/IORE.solution.html create mode 100644 docs/reference/SFO.solution.html create mode 100644 docs/reference/SFORB.solution.html create mode 100644 docs/reference/add_err.html create mode 100644 docs/reference/endpoints.html create mode 100644 docs/reference/geometric_mean.html create mode 100644 docs/reference/ilr.html create mode 100644 docs/reference/index.html create mode 100644 docs/reference/mccall81_245T.html create mode 100644 docs/reference/mkin_long_to_wide.html create mode 100644 docs/reference/mkin_wide_to_long.html create mode 100644 docs/reference/mkinds.html create mode 100644 docs/reference/mkinerrmin.html create mode 100644 docs/reference/mkinfit.html create mode 100644 docs/reference/mkinmod.html create mode 100644 docs/reference/mkinparplot.html create mode 100644 docs/reference/mkinplot.html create mode 100644 docs/reference/mkinpredict.html create mode 100644 docs/reference/mkinresplot.html create mode 100644 docs/reference/mkinsub.html create mode 100644 docs/reference/mmkin.html create mode 100644 docs/reference/plot.mkinfit.html create mode 100644 docs/reference/plot.mmkin.html create mode 100644 docs/reference/print.mkinds.html create mode 100644 docs/reference/print.mkinmod.html create mode 100644 docs/reference/schaefer07_complex_case.html create mode 100644 docs/reference/summary.mkinfit.html create mode 100644 docs/reference/synthetic_data_for_UBA.html create mode 100644 docs/reference/transform_odeparms.html create mode 100644 docs/reference/unknown-10.png create mode 100644 docs/reference/unknown-2.png create mode 100644 docs/reference/unknown-4.png create mode 100644 docs/reference/unknown-6.png create mode 100644 docs/reference/unknown-8.png (limited to 'docs') diff --git a/docs/articles/FOCUS_D.html b/docs/articles/FOCUS_D.html new file mode 100644 index 00000000..bbfc36b6 --- /dev/null +++ b/docs/articles/FOCUS_D.html @@ -0,0 +1,245 @@ + +Example evaluation of FOCUS Example Dataset D. mkin +
+
+ +
+
+ + + + +

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")
+print(FOCUS_2006_D)
+
##      name time  value
+## 1  parent    0  99.46
+## 2  parent    0 102.04
+## 3  parent    1  93.50
+## 4  parent    1  92.50
+## 5  parent    3  63.23
+## 6  parent    3  68.99
+## 7  parent    7  52.32
+## 8  parent    7  55.13
+## 9  parent   14  27.27
+## 10 parent   14  26.64
+## 11 parent   21  11.50
+## 12 parent   21  11.64
+## 13 parent   35   2.85
+## 14 parent   35   2.91
+## 15 parent   50   0.69
+## 16 parent   50   0.63
+## 17 parent   75   0.05
+## 18 parent   75   0.06
+## 19 parent  100     NA
+## 20 parent  100     NA
+## 21 parent  120     NA
+## 22 parent  120     NA
+## 23     m1    0   0.00
+## 24     m1    0   0.00
+## 25     m1    1   4.84
+## 26     m1    1   5.64
+## 27     m1    3  12.91
+## 28     m1    3  12.96
+## 29     m1    7  22.97
+## 30     m1    7  24.47
+## 31     m1   14  41.69
+## 32     m1   14  33.21
+## 33     m1   21  44.37
+## 34     m1   21  46.44
+## 35     m1   35  41.22
+## 36     m1   35  37.95
+## 37     m1   50  41.19
+## 38     m1   50  40.01
+## 39     m1   75  40.09
+## 40     m1   75  33.85
+## 41     m1  100  31.04
+## 42     m1  100  33.13
+## 43     m1  120  25.15
+## 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"))
+
## Successfully compiled differential equation model from auto-generated C code.
+
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)
+

A plot of the fit including a residual plot for both observed variables is obtained using the plot method for mkinfit objects.

+
plot(fit, show_residuals = TRUE)
+

+

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

+ +

+

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

+
summary(fit)
+
## mkin version:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:04 2016 
+## Date of summary: Thu Oct  6 08:54:04 2016 
+## 
+## Equations:
+## d_parent = - k_parent_sink * parent - k_parent_m1 * parent
+## d_m1 = + k_parent_m1 * parent - k_m1_sink * m1
+## 
+## Model predictions using solution type deSolve 
+## 
+## Fitted with method Port using 153 model solutions performed in 0.637 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##                  value   type
+## parent_0      100.7500  state
+## k_parent_sink   0.1000 deparm
+## k_parent_m1     0.1001 deparm
+## k_m1_sink       0.1002 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##                        value lower upper
+## parent_0          100.750000  -Inf   Inf
+## log_k_parent_sink  -2.302585  -Inf   Inf
+## log_k_parent_m1    -2.301586  -Inf   Inf
+## log_k_m1_sink      -2.300587  -Inf   Inf
+## 
+## Fixed parameter values:
+##      value  type
+## m1_0     0 state
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##                   Estimate Std. Error  Lower   Upper
+## parent_0            99.600    1.61400 96.330 102.900
+## log_k_parent_sink   -3.038    0.07826 -3.197  -2.879
+## log_k_parent_m1     -2.980    0.04124 -3.064  -2.897
+## log_k_m1_sink       -5.248    0.13610 -5.523  -4.972
+## 
+## Parameter correlation:
+##                   parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink
+## parent_0           1.00000            0.6075        -0.06625       -0.1701
+## log_k_parent_sink  0.60752            1.0000        -0.08740       -0.6253
+## log_k_parent_m1   -0.06625           -0.0874         1.00000        0.4716
+## log_k_m1_sink     -0.17006           -0.6253         0.47163        1.0000
+## 
+## Residual standard error: 3.211 on 36 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##                Estimate t value    Pr(>t)     Lower     Upper
+## parent_0      99.600000  61.720 2.024e-38 96.330000 1.029e+02
+## k_parent_sink  0.047920  12.780 3.050e-15  0.040890 5.616e-02
+## k_parent_m1    0.050780  24.250 3.407e-24  0.046700 5.521e-02
+## k_m1_sink      0.005261   7.349 5.758e-09  0.003992 6.933e-03
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   6.398       4 15
+## parent     6.827       3  6
+## m1         4.490       1  9
+## 
+## Resulting formation fractions:
+##                 ff
+## parent_sink 0.4855
+## parent_m1   0.5145
+## m1_sink     1.0000
+## 
+## Estimated disappearance times:
+##           DT50   DT90
+## parent   7.023  23.33
+## m1     131.761 437.70
+## 
+## Data:
+##  time variable observed predicted   residual
+##     0   parent    99.46 9.960e+01 -1.385e-01
+##     0   parent   102.04 9.960e+01  2.442e+00
+##     1   parent    93.50 9.024e+01  3.262e+00
+##     1   parent    92.50 9.024e+01  2.262e+00
+##     3   parent    63.23 7.407e+01 -1.084e+01
+##     3   parent    68.99 7.407e+01 -5.083e+00
+##     7   parent    52.32 4.991e+01  2.408e+00
+##     7   parent    55.13 4.991e+01  5.218e+00
+##    14   parent    27.27 2.501e+01  2.257e+00
+##    14   parent    26.64 2.501e+01  1.627e+00
+##    21   parent    11.50 1.253e+01 -1.035e+00
+##    21   parent    11.64 1.253e+01 -8.946e-01
+##    35   parent     2.85 3.148e+00 -2.979e-01
+##    35   parent     2.91 3.148e+00 -2.379e-01
+##    50   parent     0.69 7.162e-01 -2.624e-02
+##    50   parent     0.63 7.162e-01 -8.624e-02
+##    75   parent     0.05 6.074e-02 -1.074e-02
+##    75   parent     0.06 6.074e-02 -7.382e-04
+##   100   parent       NA 5.151e-03         NA
+##   100   parent       NA 5.151e-03         NA
+##   120   parent       NA 7.155e-04         NA
+##   120   parent       NA 7.155e-04         NA
+##     0       m1     0.00 0.000e+00  0.000e+00
+##     0       m1     0.00 0.000e+00  0.000e+00
+##     1       m1     4.84 4.803e+00  3.704e-02
+##     1       m1     5.64 4.803e+00  8.370e-01
+##     3       m1    12.91 1.302e+01 -1.140e-01
+##     3       m1    12.96 1.302e+01 -6.400e-02
+##     7       m1    22.97 2.504e+01 -2.075e+00
+##     7       m1    24.47 2.504e+01 -5.748e-01
+##    14       m1    41.69 3.669e+01  5.000e+00
+##    14       m1    33.21 3.669e+01 -3.480e+00
+##    21       m1    44.37 4.165e+01  2.717e+00
+##    21       m1    46.44 4.165e+01  4.787e+00
+##    35       m1    41.22 4.331e+01 -2.093e+00
+##    35       m1    37.95 4.331e+01 -5.363e+00
+##    50       m1    41.19 4.122e+01 -2.831e-02
+##    50       m1    40.01 4.122e+01 -1.208e+00
+##    75       m1    40.09 3.645e+01  3.643e+00
+##    75       m1    33.85 3.645e+01 -2.597e+00
+##   100       m1    31.04 3.198e+01 -9.416e-01
+##   100       m1    33.13 3.198e+01  1.148e+00
+##   120       m1    25.15 2.879e+01 -3.640e+00
+##   120       m1    33.31 2.879e+01  4.520e+00
+
+ + + +
+ + +
+ + diff --git a/docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 00000000..c0b0c2db Binary files /dev/null and b/docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 00000000..6700e527 Binary files /dev/null and b/docs/articles/FOCUS_D_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/FOCUS_L.html b/docs/articles/FOCUS_L.html new file mode 100644 index 00000000..353f1484 --- /dev/null +++ b/docs/articles/FOCUS_L.html @@ -0,0 +1,661 @@ + +Example evaluation of FOCUS Laboratory Data L1 to L3. mkin +
+
+ +
+
+ + + + +
+

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:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:05 2016 
+## Date of summary: Thu Oct  6 08:54:05 2016 
+## 
+## Equations:
+## d_parent = - k_parent_sink * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 37 model solutions performed in 0.087 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##               value   type
+## parent_0      89.85  state
+## k_parent_sink  0.10 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##                       value lower upper
+## parent_0          89.850000  -Inf   Inf
+## log_k_parent_sink -2.302585  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##                   Estimate Std. Error  Lower  Upper
+## parent_0            92.470    1.36800 89.570 95.370
+## log_k_parent_sink   -2.347    0.04057 -2.433 -2.261
+## 
+## Parameter correlation:
+##                   parent_0 log_k_parent_sink
+## parent_0            1.0000            0.6248
+## log_k_parent_sink   0.6248            1.0000
+## 
+## Residual standard error: 2.948 on 16 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##               Estimate t value    Pr(>t)    Lower   Upper
+## parent_0      92.47000   67.58 2.170e-21 89.57000 95.3700
+## k_parent_sink  0.09561   24.65 1.867e-14  0.08773  0.1042
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   3.424       2  7
+## parent     3.424       2  7
+## 
+## Resulting formation fractions:
+##             ff
+## parent_sink  1
+## 
+## Estimated disappearance times:
+##         DT50  DT90
+## parent 7.249 24.08
+## 
+## Data:
+##  time variable observed predicted residual
+##     0   parent     88.3    92.471  -4.1710
+##     0   parent     91.4    92.471  -1.0710
+##     1   parent     85.6    84.039   1.5610
+##     1   parent     84.5    84.039   0.4610
+##     2   parent     78.9    76.376   2.5241
+##     2   parent     77.6    76.376   1.2241
+##     3   parent     72.0    69.412   2.5884
+##     3   parent     71.9    69.412   2.4884
+##     5   parent     50.3    57.330  -7.0301
+##     5   parent     59.4    57.330   2.0699
+##     7   parent     47.0    47.352  -0.3515
+##     7   parent     45.1    47.352  -2.2515
+##    14   parent     27.7    24.247   3.4528
+##    14   parent     27.3    24.247   3.0528
+##    21   parent     10.0    12.416  -2.4163
+##    21   parent     10.4    12.416  -2.0163
+##    30   parent      2.9     5.251  -2.3513
+##    30   parent      4.0     5.251  -1.2513
+

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")
+

+

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)
+
## Warning in mkinfit("FOMC", FOCUS_2006_L1_mkin, quiet = TRUE): Optimisation by method Port did not converge.
+## Convergence code is 1
+
plot(m.L1.FOMC, show_errmin = TRUE, main = "FOCUS L1 - FOMC")
+

+
summary(m.L1.FOMC, data = FALSE)
+
## mkin version:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:06 2016 
+## Date of summary: Thu Oct  6 08:54:06 2016 
+## 
+## 
+## Warning: Optimisation by method Port did not converge.
+## Convergence code is 1 
+## 
+## 
+## Equations:
+## d_parent = - (alpha/beta) * 1/((time/beta) + 1) * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 188 model solutions performed in 0.437 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##          value   type
+## parent_0 89.85  state
+## alpha     1.00 deparm
+## beta     10.00 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##               value lower upper
+## parent_0  89.850000  -Inf   Inf
+## log_alpha  0.000000  -Inf   Inf
+## log_beta   2.302585  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##           Estimate Std. Error  Lower Upper
+## parent_0     92.47      1.422  89.44 95.50
+## log_alpha    15.43     15.080 -16.71 47.58
+## log_beta     17.78     15.090 -14.37 49.93
+## 
+## Parameter correlation:
+##           parent_0 log_alpha log_beta
+## parent_0    1.0000    0.1129   0.1112
+## log_alpha   0.1129    1.0000   1.0000
+## log_beta    0.1112    1.0000   1.0000
+## 
+## Residual standard error: 3.045 on 15 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##           Estimate t value    Pr(>t)     Lower     Upper
+## parent_0 9.247e+01  65.150 4.044e-20 8.944e+01 9.550e+01
+## alpha    5.044e+06   1.271 1.115e-01 5.510e-08 4.618e+20
+## beta     5.276e+07   1.259 1.137e-01 5.732e-07 4.857e+21
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   3.619       3  6
+## parent     3.619       3  6
+## 
+## Estimated disappearance times:
+##        DT50  DT90 DT50back
+## parent 7.25 24.08     7.25
+

We get a warning that the default optimisation algorithm Port did not converge, which is an indication that the model is overparameterised, i.e. contains too many parameters that are ill-defined as a consequence.

+

And in fact, due to the higher number of parameters, and the lower number of degrees of freedom of the fit, the \(\chi^2\) error level is actually higher for the FOMC model (3.6%) than for the SFO model (3.4%). Additionally, the parameters log_alpha and log_beta internally fitted in the model have excessive confidence intervals, that span more than 25 orders of magnitude (!) when backtransformed to the scale of alpha and beta. Also, the t-test for significant difference from zero does not indicate such a significant difference, with p-values greater than 0.1, and finally, the parameter correlation of log_alpha and log_beta is 1.000, clearly indicating that the model is overparameterised.

+

The \(\chi^2\) error levels reported in Appendix 3 and Appendix 7 to the FOCUS kinetics report are rounded to integer percentages and partly deviate by one percentage point from the results calculated by mkin. The reason for this is not known. However, mkin gives the same \(\chi^2\) error levels as the kinfit package and the calculation routines of the kinfit package have been extensively compared to the results obtained by the KinGUI software, as documented in the kinfit package vignette. KinGUI was the first widely used standard package in this field. Also, the calculation of \(\chi^2\) error levels was compared with KinGUII, CAKE and DegKin manager in a project sponsored by the German Umweltbundesamt (Ranke, n.d.).

+
+
+

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.

+

We may add that it is difficult to judge the random nature of the residuals just from the three samplings at days 0, 1 and 3. Also, it is not clear a priori why a consistent underestimation after the approximate DT90 should be irrelevant. However, this can be rationalised by the fact that the FOCUS fate models generally only implement SFO kinetics.

+
+
+

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:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:07 2016 
+## Date of summary: Thu Oct  6 08:54:07 2016 
+## 
+## Equations:
+## d_parent = - (alpha/beta) * 1/((time/beta) + 1) * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 81 model solutions performed in 0.19 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##          value   type
+## parent_0 93.95  state
+## alpha     1.00 deparm
+## beta     10.00 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##               value lower upper
+## parent_0  93.950000  -Inf   Inf
+## log_alpha  0.000000  -Inf   Inf
+## log_beta   2.302585  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##           Estimate Std. Error   Lower   Upper
+## parent_0   93.7700     1.8560 89.5700 97.9700
+## log_alpha   0.3180     0.1867 -0.1044  0.7405
+## log_beta    0.2102     0.2943 -0.4555  0.8759
+## 
+## Parameter correlation:
+##           parent_0 log_alpha log_beta
+## parent_0   1.00000  -0.09553  -0.1863
+## log_alpha -0.09553   1.00000   0.9757
+## log_beta  -0.18628   0.97567   1.0000
+## 
+## Residual standard error: 2.628 on 9 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##          Estimate t value    Pr(>t)   Lower  Upper
+## parent_0   93.770  50.510 1.173e-12 89.5700 97.970
+## alpha       1.374   5.355 2.296e-04  0.9009  2.097
+## beta        1.234   3.398 3.949e-03  0.6341  2.401
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   6.205       3  3
+## parent     6.205       3  3
+## 
+## Estimated disappearance times:
+##          DT50  DT90 DT50back
+## parent 0.8092 5.356    1.612
+

The error level at which the \(\chi^2\) test passes is much lower in this case. Therefore, the FOMC model provides a better description of the data, as less experimental error has to be assumed in order to explain the data.

+
+
+

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:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:08 2016 
+## Date of summary: Thu Oct  6 08:54:08 2016 
+## 
+## Equations:
+## d_parent = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
+##            time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 *
+##            time))) * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 336 model solutions performed in 0.804 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##          value   type
+## parent_0 93.95  state
+## k1        0.10 deparm
+## k2        0.01 deparm
+## g         0.50 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##              value lower upper
+## parent_0 93.950000  -Inf   Inf
+## log_k1   -2.302585  -Inf   Inf
+## log_k2   -4.605170  -Inf   Inf
+## g_ilr     0.000000  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##          Estimate Std. Error Lower Upper
+## parent_0  93.9500         NA    NA    NA
+## log_k1     3.1370         NA    NA    NA
+## log_k2    -1.0880         NA    NA    NA
+## g_ilr     -0.2821         NA    NA    NA
+## 
+## Parameter correlation:
+
## Warning in print.summary.mkinfit(x): Could not estimate covariance matrix; singular system:
+
## Could not estimate covariance matrix; singular system:
+## 
+## Residual standard error: 1.732 on 8 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##          Estimate t value Pr(>t) Lower Upper
+## parent_0  93.9500      NA     NA    NA    NA
+## k1        23.0400      NA     NA    NA    NA
+## k2         0.3369      NA     NA    NA    NA
+## g          0.4016      NA     NA    NA    NA
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data    2.53       4  2
+## parent      2.53       4  2
+## 
+## Estimated disappearance times:
+##          DT50  DT90 DT50_k1 DT50_k2
+## parent 0.5335 5.311 0.03009   2.058
+

Here, the DFOP model is clearly the best-fit model for dataset L2 based on the chi^2 error level criterion. However, the failure to calculate the covariance matrix indicates that the parameter estimates correlate excessively. Therefore, the FOMC model may be preferred for this dataset.

+
+
+
+

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)
+
+

Use mmkin to 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.

+
+
+

Accessing elements of 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:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:09 2016 
+## Date of summary: Thu Oct  6 08:54:09 2016 
+## 
+## Equations:
+## d_parent = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
+##            time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 *
+##            time))) * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 137 model solutions performed in 0.319 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##          value   type
+## parent_0 97.80  state
+## k1        0.10 deparm
+## k2        0.01 deparm
+## g         0.50 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##              value lower upper
+## parent_0 97.800000  -Inf   Inf
+## log_k1   -2.302585  -Inf   Inf
+## log_k2   -4.605170  -Inf   Inf
+## g_ilr     0.000000  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##          Estimate Std. Error   Lower     Upper
+## parent_0  97.7500    1.43800 93.7500 101.70000
+## log_k1    -0.6612    0.13340 -1.0310  -0.29100
+## log_k2    -4.2860    0.05902 -4.4500  -4.12200
+## g_ilr     -0.1229    0.05121 -0.2651   0.01925
+## 
+## Parameter correlation:
+##          parent_0  log_k1   log_k2   g_ilr
+## parent_0  1.00000  0.1640  0.01315  0.4253
+## log_k1    0.16400  1.0000  0.46478 -0.5526
+## log_k2    0.01315  0.4648  1.00000 -0.6631
+## g_ilr     0.42526 -0.5526 -0.66310  1.0000
+## 
+## Residual standard error: 1.439 on 4 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##          Estimate t value    Pr(>t)    Lower     Upper
+## parent_0 97.75000  67.970 1.404e-07 93.75000 101.70000
+## k1        0.51620   7.499 8.460e-04  0.35650   0.74750
+## k2        0.01376  16.940 3.557e-05  0.01168   0.01621
+## g         0.45660  25.410 7.121e-06  0.40730   0.50680
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   2.225       4  4
+## parent     2.225       4  4
+## 
+## Estimated disappearance times:
+##         DT50 DT90 DT50_k1 DT50_k2
+## parent 7.464  123   1.343   50.37
+## 
+## Data:
+##  time variable observed predicted residual
+##     0   parent     97.8     97.75  0.05396
+##     3   parent     60.0     60.45 -0.44933
+##     7   parent     51.0     49.44  1.56338
+##    14   parent     43.0     43.84 -0.83632
+##    30   parent     35.0     35.15 -0.14707
+##    60   parent     22.0     23.26 -1.25919
+##    91   parent     15.0     15.18 -0.18181
+##   120   parent     12.0     10.19  1.81395
+
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.

+
+
+
+

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:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:10 2016 
+## Date of summary: Thu Oct  6 08:54:10 2016 
+## 
+## Equations:
+## d_parent = - k_parent_sink * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 46 model solutions performed in 0.158 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##               value   type
+## parent_0       96.6  state
+## k_parent_sink   0.1 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##                       value lower upper
+## parent_0          96.600000  -Inf   Inf
+## log_k_parent_sink -2.302585  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##                   Estimate Std. Error  Lower   Upper
+## parent_0             96.44    1.94900 91.670 101.200
+## log_k_parent_sink    -5.03    0.07999 -5.225  -4.834
+## 
+## Parameter correlation:
+##                   parent_0 log_k_parent_sink
+## parent_0            1.0000            0.5865
+## log_k_parent_sink   0.5865            1.0000
+## 
+## Residual standard error: 3.651 on 6 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##                Estimate t value    Pr(>t)     Lower     Upper
+## parent_0      96.440000   49.49 2.283e-09 91.670000 1.012e+02
+## k_parent_sink  0.006541   12.50 8.008e-06  0.005378 7.955e-03
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   3.287       2  6
+## parent     3.287       2  6
+## 
+## Resulting formation fractions:
+##             ff
+## parent_sink  1
+## 
+## Estimated disappearance times:
+##        DT50 DT90
+## parent  106  352
+
summary(mm.L4[["FOMC", 1]], data = FALSE)
+
## mkin version:    0.9.44.9000 
+## R version:       3.3.1 
+## Date of fit:     Thu Oct  6 08:54:10 2016 
+## Date of summary: Thu Oct  6 08:54:10 2016 
+## 
+## Equations:
+## d_parent = - (alpha/beta) * 1/((time/beta) + 1) * parent
+## 
+## Model predictions using solution type analytical 
+## 
+## Fitted with method Port using 66 model solutions performed in 0.151 s
+## 
+## Weighting: none
+## 
+## Starting values for parameters to be optimised:
+##          value   type
+## parent_0  96.6  state
+## alpha      1.0 deparm
+## beta      10.0 deparm
+## 
+## Starting values for the transformed parameters actually optimised:
+##               value lower upper
+## parent_0  96.600000  -Inf   Inf
+## log_alpha  0.000000  -Inf   Inf
+## log_beta   2.302585  -Inf   Inf
+## 
+## Fixed parameter values:
+## None
+## 
+## Optimised, transformed parameters with symmetric confidence intervals:
+##           Estimate Std. Error  Lower    Upper
+## parent_0   99.1400     1.6800 94.820 103.5000
+## log_alpha  -0.3506     0.3725 -1.308   0.6068
+## log_beta    4.1740     0.5635  2.726   5.6230
+## 
+## Parameter correlation:
+##           parent_0 log_alpha log_beta
+## parent_0    1.0000   -0.5365  -0.6083
+## log_alpha  -0.5365    1.0000   0.9913
+## log_beta   -0.6083    0.9913   1.0000
+## 
+## Residual standard error: 2.315 on 5 degrees of freedom
+## 
+## Backtransformed parameters:
+## Confidence intervals for internally transformed parameters are asymmetric.
+## t-test (unrealistically) based on the assumption of normal distribution
+## for estimators of untransformed parameters.
+##          Estimate t value    Pr(>t)   Lower   Upper
+## parent_0  99.1400  59.020 1.322e-08 94.8200 103.500
+## alpha      0.7042   2.685 2.178e-02  0.2703   1.835
+## beta      64.9800   1.775 6.807e-02 15.2600 276.600
+## 
+## Chi2 error levels in percent:
+##          err.min n.optim df
+## All data   2.029       3  5
+## parent     2.029       3  5
+## 
+## Estimated disappearance times:
+##         DT50 DT90 DT50back
+## parent 108.9 1644    494.9
+
+
+

References

+
+
+

Ranke, Johannes. n.d. “Prüfung und Validierung von Modellierungssoftware als Alternative zu ModelMaker 4.0.” Umweltbundesamt Projektnummer 27452.

+
+
+
+
+ + + +
+ + +
+ + diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 00000000..bb174c01 Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-12-1.png new file mode 100644 index 00000000..cab1f123 Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-13-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-13-1.png new file mode 100644 index 00000000..4ef79892 Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-13-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-15-1.png new file mode 100644 index 00000000..b8eef14c Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-15-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 00000000..860ec47b Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 00000000..5131f700 Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 00000000..2908e5ea Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 00000000..b4bcc8fc Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 00000000..21a8c2e3 Binary files /dev/null and b/docs/articles/FOCUS_L_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/compiled_models.html b/docs/articles/compiled_models.html new file mode 100644 index 00000000..1eeb78c6 --- /dev/null +++ b/docs/articles/compiled_models.html @@ -0,0 +1,146 @@ + +Performance benefit by using compiled model definitions in mkin. mkin +
+
+ +
+
+ + + + +
+

Benchmark for a 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")
+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 microbenchmark package.

+
library("microbenchmark")
+library("ggplot2")
+mb.1 <- microbenchmark(
+  "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),
+  times = 3, control = list(warmup = 0))
+
## Warning in microbenchmark(`deSolve, not compiled` = mkinfit(SFO_SFO,
+## FOCUS_2006_D, : Could not measure overhead. Your clock might lack
+## precision.
+
smb.1 <- summary(mb.1)
+print(mb.1)
+
## Unit: milliseconds
+##                   expr       min        lq      mean    median        uq
+##  deSolve, not compiled 6407.0333 6420.1971 6434.6510 6433.3609 6448.4598
+##       Eigenvalue based  887.4338  891.8401  906.9270  896.2463  916.6735
+##      deSolve, compiled  720.2433  727.8793  733.2019  735.5152  739.6812
+##        max neval cld
+##  6463.5587     3   c
+##   937.1007     3  b 
+##   743.8472     3 a
+
autoplot(mb.1)
+

+

We see that using the compiled model is by a factor of 8.7 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:

+
rownames(smb.1) <- smb.1$expr
+smb.1["median"]/smb.1["deSolve, compiled", "median"]
+
##                         median
+## deSolve, not compiled 8.746741
+## Eigenvalue based      1.218529
+## deSolve, compiled     1.000000
+
+
+

Benchmark for a model that can not be solved with Eigenvalues

+

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

+
FOMC_SFO <- mkinmod(
+  parent = mkinsub("FOMC", "m1"),
+  m1 = mkinsub( "SFO"))
+
## Successfully compiled differential equation model from auto-generated C code.
+
mb.2 <- microbenchmark(
+  "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))
+
## Warning in microbenchmark(`deSolve, not compiled` = mkinfit(FOMC_SFO,
+## FOCUS_2006_D, : Could not measure overhead. Your clock might lack
+## precision.
+
smb.2 <- summary(mb.2)
+print(mb.2)
+
## Unit: seconds
+##                   expr       min       lq      mean    median        uq
+##  deSolve, not compiled 13.501761 13.52142 13.697021 13.541086 13.794651
+##      deSolve, compiled  1.359921  1.35996  1.366796  1.359999  1.370233
+##        max neval cld
+##  14.048217     3   b
+##   1.380468     3  a
+
smb.2["median"]/smb.2["deSolve, compiled", "median"]
+
##   median
+## 1     NA
+## 2     NA
+
autoplot(mb.2)
+

+

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

+
## R version 3.3.1 (2016-06-21)
+## Platform: x86_64-pc-linux-gnu (64-bit)
+## Running under: Debian GNU/Linux 8 (jessie)
+
## CPU model: Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
+
+
+ + + +
+ + +
+ + diff --git a/docs/articles/compiled_models_files/figure-html/benchmark_FOMC_SFO-1.png b/docs/articles/compiled_models_files/figure-html/benchmark_FOMC_SFO-1.png new file mode 100644 index 00000000..e64a4b92 Binary files /dev/null and b/docs/articles/compiled_models_files/figure-html/benchmark_FOMC_SFO-1.png differ diff --git a/docs/articles/compiled_models_files/figure-html/benchmark_SFO_SFO-1.png b/docs/articles/compiled_models_files/figure-html/benchmark_SFO_SFO-1.png new file mode 100644 index 00000000..e19fbe7f Binary files /dev/null and b/docs/articles/compiled_models_files/figure-html/benchmark_SFO_SFO-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 00000000..4ed79733 --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,99 @@ + + + + + + + + +Articles. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + + + + +
+ + + diff --git a/docs/articles/mkin.html b/docs/articles/mkin.html new file mode 100644 index 00000000..44c9e9c5 --- /dev/null +++ b/docs/articles/mkin.html @@ -0,0 +1,171 @@ + +mkin - Kinetic evaluation of chemical degradation data. mkin +
+
+ +
+
+ + + + +

Wissenschaftlicher Berater, Kronacher Str. 8, 79639 Grenzach-Wyhlen, Germany
Privatdozent at the University of Bremen

+
+

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.

+
require(mkin)
+m_SFO_SFO_SFO <- mkinmod(parent = mkinsub("SFO", "M1"),
+                         M1 = mkinsub("SFO", "M2"),
+                         M2 = mkinsub("SFO"), 
+                         use_of_ff = "max", quiet = TRUE)
+
+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)
+
+d_SFO_SFO_SFO_err <- add_err(d_SFO_SFO_SFO, function(x) 3, n = 1, seed = 123456789 )
+
+f_SFO_SFO_SFO <- mkinfit(m_SFO_SFO_SFO, d_SFO_SFO_SFO_err[[1]], quiet = TRUE)
+
+plot_sep(f_SFO_SFO_SFO, lpos = c("topright", "bottomright", "bottomright"))
+

+
+
+

Background

+

Many approaches are possible regarding the evaluation of chemical degradation data.

+

The now deprecated kinfit package (Ranke 2015) in R (R Development Core Team 2016) implements the approach recommended in the kinetics report provided by the FOrum for Co-ordination of pesticide fate models and their USe (FOCUS Work Group on Degradation Kinetics 2006; 2014) for simple data series for one parent compound in one compartment.

+

The mkin package (Ranke 2016) extends this approach to data series with transformation products, commonly termed metabolites, and to more than one compartment. It is also possible to include back reactions, so equilibrium reactions and equilibrium partitioning can be specified, although this oftentimes leads to an overparameterisation of the model.

+

When the first mkin code was published in 2010, the most commonly used tools for fitting more complex kinetic degradation models to experimental data were KinGUI (Schäfer et al. 2007), a MATLAB based tool with a graphical user interface that was specifically tailored to the task and included some output as proposed by the FOCUS Kinetics Workgroup, and ModelMaker, a general purpose compartment based tool providing infrastructure for fitting dynamic simulation 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. the initial commit on 11 May 2010).

+

At that time, the R package FME (Flexible Modelling Environment) (Soetaert and Petzoldt 2010) 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 vignette) to specify the system of differential equations and to include the output requested by the FOCUS guidance, such as the relative standard deviation that has to be assumed for the residuals, such that the \(\chi^2\) goodness-of-fit test as defined by the FOCUS kinetics workgroup would pass using an significance level \(\alpha\) of 0.05.

+

Also, mkin introduced using analytical solutions for parent only kinetics for improved optimization speed. Later, Eigenvalue based solutions were introduced to mkin for the case of linear differential equations (i.e. where the FOMC or DFOP models were not used for the parent compound), greatly improving the optimization speed for these cases.

+

The possibility to specify back-reactions and a biphasic model (SFORB) for metabolites were present in mkin from the very beginning.

+
+

Derived software tools

+

Soon after the publication of mkin, two derived tools were published, namely KinGUII (available from Bayer Crop Science) and CAKE (commissioned to Tessella by Syngenta), which added a graphical user interface (GUI), and added fitting by iteratively reweighted least squares (IRLS) and characterisation of likely parameter distributions by Markov Chain Monte Carlo (MCMC) sampling.

+

CAKE focuses on a smooth use experience, sacrificing some flexibility in the model definition, originally allowing only two primary metabolites in parallel. The current version 3.2 of CAKE release in March 2016 uses a basic scheme for up to six metabolites in a flexible arrangement, but does not support back-reactions (non-instantaneous equilibria) or biphasic kinetics for metabolites.

+

KinGUI offers an even more flexible widget for specifying complex kinetic models. Back-reactions (non-instanteneous equilibria) were supported early on, 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 and manual 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 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.

+
+
+
+

Internal parameter transformations

+

For rate constants, the log transformation is used, as proposed by Bates and Watts (1988, 77, 149). Approximate intervals are constructed for the transformed rate constants (compare Bates and Watts 1988, 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 formation fractions, a home-made reparameterisation was used in order to ensure 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. CAKE uses penalties in the objective function in order to enforce this constraint.

+

In 2012, an alternative reparameterisation of the formation fractions was proposed together with René Lehmann (Ranke and Lehmann 2012), based on isometric logratio transformation (ILR). The aim was to improve the validity of the linear approximation of the objective function during the parameter estimation procedure as well as in the subsequent calculation of parameter 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 FME on the transformed parameters were simply all backtransformed one by one to yield asymetric confidence intervals for the backtransformed parameters.

+

However, while there is a 1:1 relation between the rate constants in the model and the transformed parameters fitted in the model, the parameters obtained by the isometric logratio transformation are calculated from the set of formation 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 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 author of this vignette to be more accurate than those obtained using a re-estimation of the Hessian matrix after backtransformation, as implemented in the FME package.

+
+
+

Parameter t-test based on untransformed parameters

+

The standard output of many nonlinear regression software packages includes the results from a test for significant difference from zero for all parameters. Such a test is also recommended to check the validity of rate constants in the FOCUS guidance (FOCUS Work Group on Degradation Kinetics 2014, 96ff).

+

It has been argued that the precondition for this test, i.e. normal distribution of the estimator for the parameters, is not fulfilled in the case of nonlinear regression (Ranke and Lehmann 2015). 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.

+

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 model definition before parameter transformation, i.e. in a similar way as in packages that do not apply such an internal parameter transformation. A note is included in the mkin output, pointing to the fact that the t-test is based on the unjustified assumption of normal distribution of the parameter estimators.

+
+
+
+

References

+ +
+
+

Bates, D., and D. Watts. 1988. Nonlinear Regression and Its Applications. Wiley-Interscience.

+
+
+

FOCUS Work Group on Degradation Kinetics. 2006. Guidance Document on Estimating Persistence and Degradation Kinetics from Environmental Fate Studies on Pesticides in Eu Registration. Report of the Focus Work Group on Degradation Kinetics. http://focus.jrc.ec.europa.eu/dk.

+
+
+

———. 2014. Generic Guidance for Estimating Persistence and Degradation Kinetics from Environmental Fate Studies on Pesticides in Eu Registration. 1.1 ed. http://focus.jrc.ec.europa.eu/dk.

+
+
+

R Development Core Team. 2016. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. http://www.R-project.org.

+
+
+

Ranke, J. 2015. ‘Kinfit‘: Routines for Fitting Simple Kinetic Models to Chemical Degradation Data. http://CRAN.R-project.org/package=kinfit.

+
+
+

———. 2016. ‘Mkin‘: Kinetic Evaluation of Chemical Degradation Data. http://CRAN.R-project.org/package=mkin.

+
+
+

Ranke, J., and R. Lehmann. 2012. “Parameter Reliability in Kinetic Evaluation of Environmental Metabolism Data - Assessment and the Influence of Model Specification.” In SETAC World 20-24 May. Berlin.

+
+
+

———. 2015. “To T-Test or Not to T-Test, That Is the Question.” In XV Symposium on Pesticide Chemistry 2-4 September 2015. Piacenza. http://chem.uft.uni-bremen.de/ranke/posters/piacenza_2015.pdf.

+
+
+

Schäfer, D., B. Mikolasch, P. Rainbird, and B. Harvey. 2007. “KinGUI: A New Kinetic Software Tool for Evaluations According to FOCUS Degradation Kinetics.” In Proceedings of the Xiii Symposium Pesticide Chemistry, edited by Del Re A. A. M., Capri E., Fragoulis G., and Trevisan M., 916–23. Piacenza.

+
+
+

Soetaert, Karline, and Thomas Petzoldt. 2010. “Inverse Modelling, Sensitivity and Monte Carlo Analysis in R Using Package FME.” Journal of Statistical Software 33 (3): 1–28. http://www.jstatsoft.org/v33/i03/.

+
+
+
+
+ + + +
+ + +
+ + diff --git a/docs/articles/mkin_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/mkin_files/figure-html/unnamed-chunk-2-1.png new file mode 100644 index 00000000..d34e3805 Binary files /dev/null and b/docs/articles/mkin_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/index.html b/docs/index.html index 0f351a2d..e5edc17c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,244 +1,130 @@ + - + - -Home. mkin 0.9.44.9000 + + - - - - - +Home. mkin - - - - - + + - - + + + -
-
- -
- -
-
-

mkin

+ + -

-

The R package mkin provides calculation routines for the analysis of -chemical degradation data, including multicompartment kinetics as -needed for modelling the formation and decline of transformation products, or -if several compartments are involved.

+ + + -

Installation

+ + -

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

- -
install.packages("mkin")
-
- -

Background

- -

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 and helpful tools have been developed as detailed in -'Credits and historical remarks' below.

- -

Usage

- -

For a start, have a look a the code examples provided for -plot.mkinfit -and -plot.mmkin, and -at the package vignettes -FOCUS L and -FOCUS D.

- -

Documentation

- -

The HTML documentation is -maintained at the R-Forge project site.

+ + -

Features

+ +
+
+ + + +
+
+
+ +

mkin

+

+

The R package mkin provides calculation routines for the analysis of chemical degradation data, including multicompartment kinetics as needed for modelling the formation and decline of transformation products, or if several compartments are involved.

+

Installation

+

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

+
install.packages("mkin")
+

Background

+

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 and helpful tools have been developed as detailed in ‘Credits and historical remarks’ below.

+

Usage

+

For a start, have a look a the code examples provided for plot.mkinfit and plot.mmkin, and at the package vignettes FOCUS L and FOCUS D.

+

Documentation

+

The HTML documentation is maintained at the R-Forge project site.

+

Features

    -
  • Highly flexible model specification using -mkinmod, -including equilibrium reactions and using the single first-order -reversible binding (SFORB) model, which will automatically create -two latent state variables for the observed variable.
  • -
  • As of version 0.9-39, fitting of several models to several datasets, optionally in -parallel, is supported, see for example -plot.mmkin.
  • -
  • Model solution (forward modelling) in the function -mkinpredict -is performed either using the analytical solution for the case of -parent only degradation, an eigenvalue based solution if only simple -first-order (SFO) or SFORB kinetics are used in the model, or -using a numeric solver from the deSolve package (default is lsoda).
  • -
  • If a C compiler is installed, the kinetic models are compiled from automatically -generated C code, see
    -vignette compiled_models. -The autogeneration of C code was -inspired by the ccSolve package. Thanks -to Karline Soetaert for her work on that.
  • -
  • By default, kinetic rate constants and kinetic formation fractions are -transformed internally using -transform_odeparms -so their estimators can more reasonably be expected to follow -a normal distribution. This has the side effect that no constraints -are needed in the optimisation. Thanks to René Lehmann for the nice -cooperation on this, especially the isometric logration transformation -that is now used for the formation fractions.
  • -
  • A side effect of this is that when parameter estimates are backtransformed -to match the model definition, confidence intervals calculated from -standard errors are also backtransformed to the correct scale, and will -not include meaningless values like negative rate constants or -formation fractions adding up to more than 1, which can not occur in -a single experiment with a single defined radiolabel position.
  • -
  • The usual one-sided t-test for significant difference from zero is nevertheless -shown based on estimators for the untransformed parameters.
  • -
  • Summary and plotting functions. The summary of an mkinfit object is in -fact a full report that should give enough information to be able to -approximately 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.
  • -
  • Iteratively reweighted least squares fitting is implemented in a similar way -as in KinGUII and CAKE (see below). Simply add the argument -reweight = "obs" to your call to mkinfit and a separate variance -componenent for each of the observed variables will be optimised -in a second stage after the primary optimisation algorithm has converged.
  • -
  • When a metabolite decline phase is not described well by SFO kinetics, -SFORB kinetics can be used for the metabolite.
  • +
  • Highly flexible model specification using mkinmod, including equilibrium reactions and using the single first-order reversible binding (SFORB) model, which will automatically create two latent state variables for the observed variable.
  • +
  • As of version 0.9-39, fitting of several models to several datasets, optionally in parallel, is supported, see for example plot.mmkin.
  • +
  • Model solution (forward modelling) in the function mkinpredict is performed either using the analytical solution for the case of parent only degradation, an eigenvalue based solution if only simple first-order (SFO) or SFORB kinetics are used in the model, or using a numeric solver from the deSolve package (default is lsoda).
  • +
  • If a C compiler is installed, the kinetic models are compiled from automatically generated C code, see
    vignette compiled_models. The autogeneration of C code was inspired by the ccSolve package. Thanks to Karline Soetaert for her work on that.
  • +
  • By default, kinetic rate constants and kinetic formation fractions are transformed internally using transform_odeparms so their estimators can more reasonably be expected to follow a normal distribution. This has the side effect that no constraints are needed in the optimisation. Thanks to René Lehmann for the nice cooperation on this, especially the isometric logration transformation that is now used for the formation fractions.
  • +
  • A side effect of this is that when parameter estimates are backtransformed to match the model definition, confidence intervals calculated from standard errors are also backtransformed to the correct scale, and will not include meaningless values like negative rate constants or formation fractions adding up to more than 1, which can not occur in a single experiment with a single defined radiolabel position.
  • +
  • The usual one-sided t-test for significant difference from zero is nevertheless shown based on estimators for the untransformed parameters.
  • +
  • Summary and plotting functions. The summary of an mkinfit object is in fact a full report that should give enough information to be able to approximately 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.
  • +
  • Iteratively reweighted least squares fitting is implemented in a similar way as in KinGUII and CAKE (see below). Simply add the argument reweight = "obs" to your call to mkinfit and a separate variance componenent for each of the observed variables will be optimised in a second stage after the primary optimisation algorithm has converged.
  • +
  • When a metabolite decline phase is not described well by SFO kinetics, SFORB kinetics can be used for the metabolite.
- -

GUI

- -

There is a graphical user interface that I consider useful for real work. Please -refer to its documentation page -for installation instructions and a manual.

- -

News

- -

Yes, there is a ChangeLog, for the latest CRAN release -and one for the github master branch.

- -

Credits and historical remarks

- -

mkin would not be possible without the underlying software stack consisting -of R and the packages deSolve -and FME, to say the least.

- -

It could not have been written without me being introduced to regulatory fate -modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories -Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows -the work done by the -FOCUS Degradation Kinetics Workgroup, -as detailed in their guidance document from 2006, slightly updated in 2011 and -2014.

- -

Also, it was inspired by the first version of KinGUI developed by -BayerCropScience, which is based on the MatLab runtime environment.

- -

The companion package -kinfit (now deprecated) was -started in 2008 and -first published on -CRAN on 01 May 2010.

- -

The first mkin code was -published on 11 May 2010 and the -first CRAN version -on 18 May 2010.

- -

In 2011, Bayer Crop Science started to distribute an R based successor to KinGUI named -KinGUII whose R code is based on mkin, but which added, amongst other -refinements, a closed source graphical user interface (GUI), iteratively -reweighted least squares (IRLS) optimisation of the variance for each of the -observed variables, and Markov Chain Monte Carlo (MCMC) simulation -functionality, similar to what is available e.g. in the FME package.

- -

Somewhat in parallel, Syngenta has sponsored the development of an mkin and -KinGUII based GUI application called CAKE, which also adds IRLS and MCMC, is -more limited in the model formulation, but puts more weight on usability. -CAKE is available for download from the CAKE -website, where you can also -find a zip archive of the R scripts derived from mkin, published under the GPL -license.

- -

Finally, there is -KineticEval, which contains -a further development of the scripts used for KinGUII, so the different tools -will hopefully be able to learn from each other in the future as well.

- -

Development

- -

Contributions are welcome! Your -mkin fork is just a mouse click -away… The master branch on github should always be in good shape, I implement -new features in separate branches now. If you prefer subversion, project -members for the -r-forge project are welcome as well. -Generally, the source code of the latest CRAN version should be available there. -You can also browse the source code at cgit.jrwb.de/mkin.

+

GUI

+

There is a graphical user interface that I consider useful for real work. Please refer to its documentation page for installation instructions and a manual.

+

News

+

Yes, there is a ChangeLog, for the latest CRAN release and one for the github master branch.

+

Credits and historical remarks

+

mkin would not be possible without the underlying software stack consisting of R and the packages deSolve and FME, to say the least.

+

It could not have been written without me being introduced to regulatory fate modelling of pesticides by Adrian Gurney during my time at Harlan Laboratories Ltd (formerly RCC Ltd). mkin greatly profits from and largely follows the work done by the FOCUS Degradation Kinetics Workgroup, as detailed in their guidance document from 2006, slightly updated in 2011 and

+
    +
  1. +
+

Also, it was inspired by the first version of KinGUI developed by BayerCropScience, which is based on the MatLab runtime environment.

+

The companion package kinfit (now deprecated) was started in 2008 and first published on CRAN on 01 May 2010.

+

The first mkin code was published on 11 May 2010 and the first CRAN version on 18 May 2010.

+

In 2011, Bayer Crop Science started to distribute an R based successor to KinGUI named KinGUII whose R code is based on mkin, but which added, amongst other refinements, a closed source graphical user interface (GUI), iteratively reweighted least squares (IRLS) optimisation of the variance for each of the observed variables, and Markov Chain Monte Carlo (MCMC) simulation functionality, similar to what is available e.g. in the FME package.

+

Somewhat in parallel, Syngenta has sponsored the development of an mkin and KinGUII based GUI application called CAKE, which also adds IRLS and MCMC, is more limited in the model formulation, but puts more weight on usability. CAKE is available for download from the CAKE website, where you can also find a zip archive of the R scripts derived from mkin, published under the GPL license.

+

Finally, there is KineticEval, which contains a further development of the scripts used for KinGUII, so the different tools will hopefully be able to learn from each other in the future as well.

+

Development

+

Contributions are welcome! Your mkin fork is just a mouse click away… The master branch on github should always be in good shape, I implement new features in separate branches now. If you prefer subversion, project members for the r-forge project are welcome as well. Generally, the source code of the latest CRAN version should be available there. You can also browse the source code at cgit.jrwb.de/mkin.

- -
- + -
+
+ - \ No newline at end of file + diff --git a/docs/news/index.html b/docs/news/index.html new file mode 100644 index 00000000..4e321474 --- /dev/null +++ b/docs/news/index.html @@ -0,0 +1,401 @@ + + + + + + + + +All news. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+
+

mkin 0.9.45

+
+

Minor changes

+
  • +plot.mkinfit: Plotting does not fail any more when the compiled model is not available, e.g. because it was removed from the temporary directory. In this case, the uncompiled model is now used for plotting
  • +
+
+
+

mkin 0.9.44 (2016-06-29)

+
+

Bug fixes

+
  • The test test_FOMC_ill-defined failed on several architectures, so the test is now skipped
  • +
+
+
+

mkin 0.9.43 (2016-06-28)

+
+

Major changes

+
  • The title was changed to Kinetic evaluations of chemical degradation data

  • +
  • plot.mkinfit: Add the possibility to show fits (and residual plots if requested) separately for the observed variables

  • +
  • plot.mkinfit: Add the possibility to show the chi2 error levels in the plot, similar to the way they are shown in plot.mmkin

  • +
  • plot_sep: Add this function as a convenience wrapper for plotting observed variables of mkinfit objects separately, with chi2 error values and residual plots.

  • +
  • Vignettes: The main vignette mkin was converted to R markdown and updated. The other vignettes were also updated to show current improved functionality.

  • +
  • The function add_err was added to the package, making it easy to generate simulated data using an error model based on the normal distribution

  • +
+
+

Minor changes

+
  • Remove an outdated reference to the inline package in the compiled_models vignette

  • +
  • mkinfit: Do not error out in cases where the fit converges, but the Jacobian for the untransformed model cost can not be estimated. Give a warning instead and return NA for the t-test results.

  • +
  • summary.mkinfit: Give a warning message when the covariance matrix can not be obtained.

  • +
  • A test has been added to containing a corresponding edge case to check that the warnings are correctly issued and the fit does not terminate.

  • +
  • plot.mmkin: Round the chi2 error value to three significant digits, instead of two decimal digits.

  • +
  • mkinfit: Return the err values used on weighted fits as a column named err. Also include these inverse weights when the column value in the observed data is used, which is returned as observed in the data component of the mkinfit object.

  • +
+
+

Bug fixes

+
  • endpoints: When the name of a substance degrading to a metabolite (e.g. a parent compound) used in the model formulation ended in the letter f, some rate parameters could be listed as formation fractions with mixed up names. These would also appear in the summary.

  • +
  • mkinfit: Check for all observed variables when checking if the user tried to fix formation fractions when fitting them using ilr transformation.

  • +
  • plot.mmkin: Set the plot margins correctly, also in the case of a single fit to be plotted, so the main title is placed in a reasonable way.

  • +
  • plot.mkinfit: Correct default values for col_obs, pch_obs and lty_obs for the case that obs_vars is specified.

  • +
+
+
+

mkin 0.9.42 (2016-03-25)

+
+

Major changes

+
  • Add the argument from_max_mean to mkinfit, for fitting only the decline from the maximum observed value for models with a single observed variable
  • +
+
+

Minor changes

+
  • Add plots to compiled_models vignette

  • +
  • Give an explanatory error message when mkinmod fails due to a missing definition of a target variable

  • +
  • print.mkinmod(): Improve formatting when printing mkinmod model definitions

  • +
+
+
+

mkin 0.9-41 (2015-11-09)

+
+

Minor changes

+
  • Add an R6 class mkinds representing datasets with a printing method

  • +
  • Add a printing method for mkinmod objects

  • +
  • Make it possible to specify arbitrary strings as names for the compounds in mkinmod, and show them in the plot

  • +
  • Use an index.r file to group help topics in static documentation

  • +
+
+

Bug fixes

+
  • +print.summary.mkinfit(): Avoid an error that occurred when printing summaries generated with mkin versions before 0.9-36
  • +
+
+
+

mkin 0.9-40 (2015-07-21)

+
+

Bug fixes

+
  • +endpoints(): For DFOP and SFORB models, where optimize() is used, make use of the fact that the DT50 must be between DT50_k1 and DT50_k2 (DFOP) or DT50_b1 and DT50_b2 (SFORB), as optimize() sometimes did not find the minimum. Likewise for finding DT90 values. Also fit on the log scale to make the function more efficient.
  • +
+
+

Internal changes

+
  • +DESCRIPTION, NAMESPACE, R/*.R: Import (from) stats, graphics and methods packages, and qualify some function calls for non-base packages installed with R to avoid NOTES made by R CMD check –as-cran with upcoming R versions.
  • +
+
+
+

mkin 0.9-39 (2015-06-26)

+
+

Major changes

+
  • New function mmkin(): This function takes a character vector of model shorthand names, or alternatively a list of mkinmod models, as well as a list of dataset as main arguments. It returns a matrix of mkinfit objects, with a row for each model and a column for each dataset. A subsetting method with single brackets is available. Fitting the models in parallel using the parallel package is supported.

  • +
  • New function plot.mmkin(): Plots single-row or single-column mmkin objects including residual plots.

  • +
+
+

Bug fixes

+
  • +mkinparplot(): Fix the x axis scaling for rate constants and formation fractions that got confused by the introduction of the t-values of transformed parameters.
  • +
+
+
+

mkin 0.9-38 (2015-06-24)

+
+

Minor changes

+
  • vignettes/compiled_models.html: Show the performance improvement factor actually obtained when building the vignette, as well as mkin version, some system info and the CPU model used for building the vignette.

  • +
  • GNUMakefile,vignettes/*: Clean up vignette generation and include table of contents in HTML vignettes.

  • +
+
+

Bug fixes

+
  • +mkinmod(): When generating the C code for the derivatives, only declare the time variable when it is needed and remove the ‘-W-no-unused-variable’ compiler flag as the C compiler used in the CRAN checks on Solaris does not know it.
  • +
+
+
+

mkin 0.9-36 (2015-06-21)

+
+

Major changes

+
  • summary.mkinfit(): A one-sided t-test for significant difference of untransformed parameters from zero is now always shown, based on the assumption of normal distribution for estimators of all untransformed parameters. Use with caution, as this assumption is unrealistic e.g. for rate constants in these nonlinear kinetic models.

  • +
  • If a compiler (gcc) is installed, use a version of the differential equation model compiled from C code, which is a huge performance boost for models where only the deSolve method works.

  • +
  • mkinmod(): Create a list component $cf (of class CFuncList) in the list returned by mkinmod, if a version can be compiled from autogenerated C code (see above).

  • +
  • mkinfit(): Set the default solution_type to deSolve when a compiled version of the model is present, except when an analytical solution is possible.

  • +
+
+

Minor changes

+
  • Added a simple showcase vignette with an evaluation of FOCUS example dataset D
  • +
+
+
+

mkin 0.9-35 (2015-05-15)

+
+

Major changes

+
  • Switch from RUnit to testthat for testing
  • +
+
+

Bug fixes

+
  • mkinparplot(): Avoid warnings that occurred when not all confidence intervals were available in the summary of the fit

  • +
  • print.summary.mkinfit(): Fix printing the summary for the case that the number of iterations is not available

  • +
  • NAMESPACE: export S3 methods plot.mkinfit, summary.mkinfit and print.summary.mkinfit to satisfy R CMD check on R-devel

  • +
  • mkinparplot(): Avoid warning in R CMD check about undeclared global variable Lower

  • +
+
+

New features

+
  • mkinfit(): Report successful termination when quiet = FALSE. This is helpful for more difficult problems fitted with reweight.method = obs, as no progress is often indicated during the reweighting.

  • +
  • A first test using results established in the expertise written for the German Federal Environmental Agency (UBA) was added.

  • +
  • Add synthetic datasets generated for expertise written for the German Federal Environmental Agency UBA

  • +
  • Add tests based on these datasets

  • +
+
+
+

mkin 0.9-34 (2014-11-22)

+
+

New features

+
  • Add the convenience function mkinsub() for creating the lists used in mkinmod()

  • +
  • Add the possibility to fit indeterminate order rate equation (IORE) models using an analytical solution (parent only) or a numeric solution. Paths from IORE compounds to metabolites are supported when using formation fractions (use_of_ff = ‘max’). Note that the numerical solution (method.ode = ‘deSolve’) of the IORE differential equations sometimes fails due to numerical problems.

  • +
  • Switch to using the Port algorithm (using a model/trust region approach) per default. While needing more iterations than the Levenberg-Marquardt algorithm previously used per default, it is less sensitive to starting parameters.

  • +
+
+

Minor changes

+
  • The formatting of differential equations in the summary was further improved

  • +
  • Always include 0 on y axis when plotting during the fit

  • +
+
+
+

mkin 0.9-33 (2014-10-22)

+
+

New features

+
  • The initial value (state.ini) for the observed variable with the highest observed residue is set to 100 in case it has no time zero observation and state.ini = "auto"

  • +
  • A basic unit test for mkinerrmin() was written

  • +
+
+

Bug fixes

+
  • mkinfit(): The internally fitted parameter for g was named g_ilr even when transform_fractions=FALSE

  • +
  • mkinfit(): The initial value (state.ini) for the parent compound was not set when the parent was not the (only) variable with the highest value in the observed data.

  • +
  • mkinerrmin(): When checking for degrees of freedom for metabolites, check if their time zero value is fixed instead of checking if the observed value is zero. This ensures correct calculation of degrees of freedom also in cases where the metabolite residue at time zero is greater zero.

  • +
  • plot.mkinfit(): Avoid a warning message about only using the first component of ylim that occurred when ylim was specified explicitly

  • +
+
+

Minor changes

+
  • The formatting of differential equations in the summary was improved by wrapping overly long lines

  • +
  • The FOCUS_Z vignette was rebuilt with the above improvement and using a width of 70 to avoid output outside of the grey area

  • +
  • print.summary.mkinfit(): Avoid a warning that occurred when gmkin showed summaries ofinitial fits without iterations

  • +
  • mkinfit(): Avoid a warning that occurred when summarising a fit that was performed with maxitmodFit = 0 as done in gmkin for configuring new fits.

  • +
+
+
+

mkin 0.9-32 (2014-07-24)

+
+

New features

+
  • The number of degrees of freedom is difficult to define in the case of ilr transformation of formation fractions. Now for each source compartment the number of ilr parameters (=number of optimised parameters) is divided by the number of pathways to metabolites (=number of affected data series) which leads to fractional degrees of freedom in some cases.

  • +
  • The default for the initial value for the first state value is now taken from the mean of the observations at time zero, if available.

  • +
  • The kinetic model can alternatively be specified with a shorthand name for parent only degradation models, e.g. SFO, or DFOP.

  • +
  • Optimisation method, number of model evaluations and time elapsed during optimisation are given in the summary of mkinfit objects.

  • +
  • The maximum number of iterations in the optimisation algorithm can be specified using the argument maxit.modFit to the mkinfit function.

  • +
  • mkinfit gives a warning when the fit does not converge (does not apply to SANN method). This warning is included in the summary.

  • +
+
+

Bug fixes

+
  • Avoid plotting an artifical 0 residual at time zero in mkinresplot

  • +
  • In the determination of the degrees of freedom in mkinerrmin, formation fractions were accounted for multiple times in the case of parallel formation of metabolites. See the new feature described above for the solution.

  • +
  • transform_rates=FALSE in mkinfit now also works for FOMC and HS models.

  • +
  • Initial values for formation fractions were not set in all cases.

  • +
  • No warning was given when the fit did not converge when a method other than the default Levenberg-Marquardt method Marq was used.

  • +
+
+

Minor changes

+
  • Vignettes were rebuilt to reflect the changes in the summary method.

  • +
  • Algorithm Pseudo was excluded because it needs user-defined parameter limits which are not supported.

  • +
  • Algorithm Newton was excluded because of its different way to specify the maximum number of iterations and because it does not appear to provide additional benefits.

  • +
+
+
+

mkin 0.9-31 (2014-07-14)

+
+

Bug fixes

+
  • The internal renaming of optimised parameters in Version 0.9-30 led to errors in the determination of the degrees of freedom for the chi2 error level calulations in mkinerrmin() used by the summary function.
  • +
+
+
+

mkin 0.9-30 (2014-07-11)

+
+

New features

+
  • It is now possible to use formation fractions in combination with turning off the sink in mkinmod().
  • +
+
+

Major changes

+
  • The original and the transformed parameters now have different names (e.g. k_parent and log_k_parent. They also differ in how many they are when we have formation fractions but no pathway to sink.

  • +
  • The order of some of the information blocks in print.summary.mkinfit.R() has been ordered in a more logical way.

  • +
+
+

Minor changes

+
  • The vignette FOCUS_Z has been simplified to use formation fractions with turning off the sink, and slightly amended to use the new versions of DT50 values calculated since mkin 0.9-29.

  • +
  • All vignettes have been rebuilt so they reflect all changes.

  • +
  • The ChangeLog was renamed to NEWS.md and the entries were converted to markdown syntax compatible with the tools::news() function built into R.

  • +
  • The test suite was overhauled. Tests of the DFOP and SFORB models with dataset FOCUS_2006_A were removed, as they were too much dependent on the optimisation algorithm and/or starting parameters, because the dataset is SFO (compare kinfit vignette).

  • +
  • Also, the Schaefer complex case can now be fitted using formation fractions, and with the ‘Port’ optimisation method we also fit A2 in the same way as published in the Piacenza paper.

  • +
  • Some more checks were introduced to mkinfit(), leading to warnings or stopping execution if unsupported combinations of methods and parameters are requested.

  • +
+
+
+

mkin 0.9-29 (2014-06-27)

+
  • R/mkinresplot.R: Make it possible to specify xlim

  • +
  • R/geometric_mean.R, man/geometric_mean.Rd: Add geometric mean function

  • +
  • R/endpoints.R, man/endpoints.Rd: Calculate additional (pseudo)-DT50 values for FOMC, DFOP, HS and SFORB. Avoid calculation of formation fractions from rate constants when they are directly fitted

  • +
+
+

mkin 0.9-28 (2014-05-20)

+
  • Do not backtransform confidence intervals for formation fractions if more than one compound is formed, as such parameters only define the pathways as a set

  • +
  • Add historical remarks and some background to the main package vignette

  • +
  • Correct ‘isotropic’ into ‘isometric’ for the ilr transformation

  • +
+
+

mkin 0.9-27 (2014-05-10)

+
  • Fork the GUI into a separate package gmkin

  • +
  • DESCRIPTION, NAMESPACE, TODO: Adapt and add copyright information

  • +
  • Remove files belonging to the GUI

  • +
  • Possibility to fit without parameter transformations, using bounds as implemented in FME

  • +
  • Add McCall 2,4,5-T dataset

  • +
  • Enable selection of observed variables in plotting

  • +
  • Add possibility to show residual plot in plot.mkinfit

  • +
  • R/mkinparplot.R, man/mkinparplot.Rd: plot parameters with confidence intervals

  • +
  • Change vignette format from Sweave to knitr

  • +
  • Split examples vignette to FOCUS_L and FOCUS_Z

  • +
  • Remove warning about constant formation fractions in mkinmod as it was based on a misconception

  • +
  • Restrict the unit test with the Schaefer data to parent and primary metabolites as formation fraction and DT50 for A2 are higly correlated and passing the test is platform dependent. For example, the test fails in 1 out of 14 platforms on CRAN as of today.

  • +
  • Add Eurofins Regulatory AG copyright notices

  • +
  • Import FME and deSolve instead of depending on them to have clean startup

  • +
  • Add a starter function for the GUI: gmkin()

  • +
  • Change the format of the workspace files of gmkin so they can be distributed and documented in the package

  • +
  • Add gmkin workspace datasets FOCUS_2006_gmkin and FOCUS_2006_Z_gmkin

  • +
+
+

mkin 0.9-24 (2013-11-06)

+
  • Bugfix re-enabling the fixing of any combination of initial values for state variables

  • +
  • Default values for kinetic rate constants are not all 0.1 any more but are “salted” with a small increment to avoid numeric artefacts with the eigenvalue based solutions

  • +
  • Backtransform fixed ODE parameters for the summary

  • +
+
+

mkin 0.9-22 (2013-10-26)

+
  • Get rid of the optimisation step in mkinerrmin - this was unnecessary. Thanks to KinGUII for the inspiration - actually this is equation 6-2 in FOCUS kinetics p. 91 that I had overlooked originally

  • +
  • Fix plot.mkinfit as it passed graphical arguments like main to the solver

  • +
  • Do not use plot=TRUE in mkinfit() example

  • +
  • The first successful fits in the not so simple GUI

  • +
  • Fix iteratively reweighted least squares for the case of many metabolites

  • +
  • Unify naming of initial values of state variables

  • +
  • Unify naming in dataframes of optimised and fixed parameters in the summary

  • +
  • Show the weighting method for residuals in the summary

  • +
  • Correct the output of the data in the case of manual weighting

  • +
  • Implement IRLS assuming different variances for observed variables

  • +
  • Do not use 0 values at time zero for chi2 error level calculations. This is the way it is done in KinGUII and it makes sense. It does impact the chi2 error levels in the output. Generally they seem to be lower for metabolites now, presumably because the mean of the observed values is higher

  • +

For a detailed list of changes to the mkin source please consult the commit history on http://github.com/jranke/mkin

+
+
+ + + +
+ + +
+ + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 00000000..2edd2759 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,59 @@ +body { + position: relative; +} + +.icon img { + float: right; + border: 1px solid #ccc; +} +.index .internal {display: none;} +ul.index li {margin-bottom: 0.5em; clear: both;} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; +} +footer p { + margin-bottom: 0; + color: #555; +} + +/* Fixes for fixed navbar --------------------------*/ + +body { + position: relative; + padding-top: 60px; +} + +.section h1, .section h2, .section h3, .section h4 { + padding-top: 60px; + margin-top: -60px; +} + +/* Table of contents --------------------------*/ + +#tocnav h2 { + margin-top: 0; + font-size: 1.5em; +} + + +/* Syntax highlighting ---------------------------------------------------- */ + +.fl,.number {color:rgb(21,20,181);} +.fu,.functioncall {color:#264D66 ;} +.ch,.st,.string {color:#375D81 ;} +.kw,.keyword {font-weight:bolder ;color:black;} +.argument {color:#264D66 ;} +.co,.comment {color: #333;} +.formalargs {color: #264D66;} +.eqformalargs {color:#264D66;} +.slot {font-style:italic;} +.symbol {color:black ;} +.prompt {color:black ;} + +pre img { + background-color: #fff; + display: block; +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 00000000..ded9e7df --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,13 @@ +$(function() { + + $('#tocnav').affix({ + offset: { + top: $('#tocnav').offset().top - 80 + } + }); + $('body').scrollspy({ + target: '#tocnav', + offset: 80 + }); + +}); diff --git a/docs/reference/DFOP.solution.html b/docs/reference/DFOP.solution.html new file mode 100644 index 00000000..3422c206 --- /dev/null +++ b/docs/reference/DFOP.solution.html @@ -0,0 +1,132 @@ + + + + + + + + +DFOP.solution. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function describing decline from a defined starting value using the sum + of two exponential decline functions.

+ + +
DFOP.solution(t, parent.0, k1, k2, g)
+ +

Arguments

+
+
t
+
Time.
+
parent.0
+
Starting value for the response variable at time zero.
+
k1
+
First kinetic constant.
+
k2
+
Second kinetic constant.
+
g
+
Fraction of the starting value declining according to the + first kinetic constant. +
+
+ +
+

Value

+ +

The value of the response variable at time t.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
plot(function(x) DFOP.solution(x, 100, 5, 0.5, 0.3), 0, 4, ylim=c(0,100))
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/Extract.mmkin.html b/docs/reference/Extract.mmkin.html new file mode 100644 index 00000000..b811eb95 --- /dev/null +++ b/docs/reference/Extract.mmkin.html @@ -0,0 +1,1192 @@ + + + + + + + + +[.mmkin. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Subsetting method for mmkin objects.

+ + +
# S3 method for mmkin
+[(x, i, j, ..., drop = FALSE)
+ +

Arguments

+
+
x
+
An mmkin object
+
i
+
Row index selecting the fits for specific models
+
j
+
Column index selecting the fits to specific datasets
+
...
+
Not used, only there to satisfy the generic method definition
+
drop
+
If FALSE, the method always returns an mmkin object, otherwise either + a list of mkinfit objects or a single mkinfit object.
+
+ +
+

Value

+ +

An object of class mmkin.

+
+ +

Examples

+
# Only use one core, to pass R CMD check --as-cran + fits <- mmkin(c("SFO", "FOMC"), list(B = FOCUS_2006_B, C = FOCUS_2006_C), + cores = 1, quiet = TRUE) + fits["FOMC", ]
#> dataset +#> model B C +#> FOMC List,42 List,42 +#> attr(,"class") +#> [1] "mmkin" +#>
fits[, "B"]
#> dataset +#> model B +#> SFO List,42 +#> FOMC List,42 +#> attr(,"class") +#> [1] "mmkin" +#>
fits[, "B", drop = TRUE]$FOMC
#> $par +#> parent_0 log_alpha log_beta +#> 99.666193 2.549849 5.050586 +#> +#> $ssr +#> [1] 28.58291 +#> +#> $convergence +#> [1] 0 +#> +#> $iterations +#> [1] 21 +#> +#> $evaluations +#> function gradient +#> 25 78 +#> +#> $counts +#> [1] "both X-convergence and relative convergence (5)" +#> +#> $hessian +#> parent_0 log_alpha log_beta +#> parent_0 4.123033 -95.69983 93.17699 +#> log_alpha -95.699832 6618.85833 -6352.46648 +#> log_beta 93.176993 -6352.46648 6101.23483 +#> +#> $residuals +#> parent parent parent parent parent parent +#> 1.046192647 -3.322396479 3.655156669 -1.705316770 0.406306255 -0.123734689 +#> parent parent +#> -0.036886982 -0.006240458 +#> +#> $ms +#> [1] 3.572863 +#> +#> $var_ms +#> parent +#> 3.572863 +#> +#> $var_ms_unscaled +#> parent +#> 3.572863 +#> +#> $var_ms_unweighted +#> parent +#> 3.572863 +#> +#> $rank +#> [1] 3 +#> +#> $df.residual +#> [1] 5 +#> +#> $solution_type +#> [1] "analytical" +#> +#> $transform_rates +#> [1] TRUE +#> +#> $transform_fractions +#> [1] TRUE +#> +#> $method.modFit +#> [1] "Port" +#> +#> $maxit.modFit +#> [1] "auto" +#> +#> $calls +#> [1] 111 +#> +#> $time +#> user system elapsed +#> 0.256 0.000 0.257 +#> +#> $mkinmod +#> <mkinmod> model generated with +#> Use of formation fractions $use_of_ff: min +#> Specification $spec: +#> $parent +#> $type: FOMC; $sink: TRUE +#> +#> $observed +#> name time value +#> 1 parent 0 98.62 +#> 2 parent 3 81.43 +#> 3 parent 7 53.18 +#> 4 parent 14 34.89 +#> 5 parent 30 10.09 +#> 6 parent 62 1.50 +#> 7 parent 90 0.33 +#> 8 parent 118 0.08 +#> +#> $obs_vars +#> [1] "parent" +#> +#> $predicted +#> name time value +#> 1 parent 0.000000 99.66619265 +#> 2 parent 1.191919 90.41690342 +#> 3 parent 2.383838 82.08630014 +#> 4 parent 3.000000 78.10760352 +#> 5 parent 3.575758 74.57722848 +#> 6 parent 4.767677 67.80342415 +#> 7 parent 5.959596 61.68822425 +#> 8 parent 7.000000 56.83515667 +#> 9 parent 7.151515 56.16343898 +#> 10 parent 8.343434 51.16836285 +#> 11 parent 9.535354 46.64890734 +#> 12 parent 10.727273 42.55683931 +#> 13 parent 11.919192 38.84911158 +#> 14 parent 13.111111 35.48727414 +#> 15 parent 14.000000 33.18468323 +#> 16 parent 14.303030 32.43695565 +#> 17 parent 15.494949 29.66740651 +#> 18 parent 16.686869 27.15109578 +#> 19 parent 17.878788 24.86335532 +#> 20 parent 19.070707 22.78206538 +#> 21 parent 20.262626 20.88737647 +#> 22 parent 21.454545 19.16146324 +#> 23 parent 22.646465 17.58830644 +#> 24 parent 23.838384 16.15349953 +#> 25 parent 25.030303 14.84407724 +#> 26 parent 26.222222 13.64836315 +#> 27 parent 27.414141 12.55583436 +#> 28 parent 28.606061 11.55700107 +#> 29 parent 29.797980 10.64329940 +#> 30 parent 30.000000 10.49630626 +#> 31 parent 30.989899 9.80699593 +#> 32 parent 32.181818 9.04110261 +#> 33 parent 33.373737 8.33930082 +#> 34 parent 34.565657 7.69587362 +#> 35 parent 35.757576 7.10564515 +#> 36 parent 36.949495 6.56392657 +#> 37 parent 38.141414 6.06646759 +#> 38 parent 39.333333 5.60941311 +#> 39 parent 40.525253 5.18926438 +#> 40 parent 41.717172 4.80284421 +#> 41 parent 42.909091 4.44726569 +#> 42 parent 44.101010 4.11990420 +#> 43 parent 45.292929 3.81837216 +#> 44 parent 46.484848 3.54049644 +#> 45 parent 47.676768 3.28429799 +#> 46 parent 48.868687 3.04797350 +#> 47 parent 50.060606 2.82987892 +#> 48 parent 51.252525 2.62851456 +#> 49 parent 52.444444 2.44251172 +#> 50 parent 53.636364 2.27062056 +#> 51 parent 54.828283 2.11169922 +#> 52 parent 56.020202 1.96470393 +#> 53 parent 57.212121 1.82868009 +#> 54 parent 58.404040 1.70275424 +#> 55 parent 59.595960 1.58612677 +#> 56 parent 60.787879 1.47806529 +#> 57 parent 61.979798 1.37789865 +#> 58 parent 62.000000 1.37626531 +#> 59 parent 63.171717 1.28501157 +#> 60 parent 64.363636 1.19883967 +#> 61 parent 65.555556 1.11886504 +#> 62 parent 66.747475 1.04461220 +#> 63 parent 67.939394 0.97564441 +#> 64 parent 69.131313 0.91156031 +#> 65 parent 70.323232 0.85199096 +#> 66 parent 71.515152 0.79659697 +#> 67 parent 72.707071 0.74506609 +#> 68 parent 73.898990 0.69711084 +#> 69 parent 75.090909 0.65246649 +#> 70 parent 76.282828 0.61088912 +#> 71 parent 77.474747 0.57215389 +#> 72 parent 78.666667 0.53605348 +#> 73 parent 79.858586 0.50239663 +#> 74 parent 81.050505 0.47100683 +#> 75 parent 82.242424 0.44172111 +#> 76 parent 83.434343 0.41438896 +#> 77 parent 84.626263 0.38887128 +#> 78 parent 85.818182 0.36503953 +#> 79 parent 87.010101 0.34277481 +#> 80 parent 88.202020 0.32196716 +#> 81 parent 89.393939 0.30251479 +#> 82 parent 90.000000 0.29311302 +#> 83 parent 90.585859 0.28432347 +#> 84 parent 91.777778 0.26730596 +#> 85 parent 92.969697 0.25138141 +#> 86 parent 94.161616 0.23647487 +#> 87 parent 95.353535 0.22251689 +#> 88 parent 96.545455 0.20944302 +#> 89 parent 97.737374 0.19719349 +#> 90 parent 98.929293 0.18571281 +#> 91 parent 100.121212 0.17494947 +#> 92 parent 101.313131 0.16485560 +#> 93 parent 102.505051 0.15538676 +#> 94 parent 103.696970 0.14650163 +#> 95 parent 104.888889 0.13816179 +#> 96 parent 106.080808 0.13033150 +#> 97 parent 107.272727 0.12297753 +#> 98 parent 108.464646 0.11606895 +#> 99 parent 109.656566 0.10957695 +#> 100 parent 110.848485 0.10347470 +#> 101 parent 112.040404 0.09773723 +#> 102 parent 113.232323 0.09234125 +#> 103 parent 114.424242 0.08726506 +#> 104 parent 115.616162 0.08248842 +#> 105 parent 116.808081 0.07799245 +#> 106 parent 118.000000 0.07375954 +#> +#> $cost +#> function (P) +#> { +#> assign("calls", calls + 1, inherits = TRUE) +#> if (trace_parms) +#> cat(P, "\n") +#> if (length(state.ini.optim) > 0) { +#> odeini <- c(P[1:length(state.ini.optim)], state.ini.fixed) +#> names(odeini) <- c(state.ini.optim.boxnames, state.ini.fixed.boxnames) +#> } +#> else { +#> odeini <- state.ini.fixed +#> names(odeini) <- state.ini.fixed.boxnames +#> } +#> odeparms <- c(P[(length(state.ini.optim) + 1):length(P)], +#> transparms.fixed) +#> parms <- backtransform_odeparms(odeparms, mkinmod, transform_rates = transform_rates, +#> transform_fractions = transform_fractions) +#> out <- mkinpredict(mkinmod, parms, odeini, outtimes, solution_type = solution_type, +#> use_compiled = use_compiled, method.ode = method.ode, +#> atol = atol, rtol = rtol, ...) +#> assign("out_predicted", out, inherits = TRUE) +#> mC <- modCost(out, observed, y = "value", err = err, weight = weight, +#> scaleVar = scaleVar) +#> if (mC$model < cost.old) { +#> if (!quiet) +#> cat("Model cost at call ", calls, ": ", mC$model, +#> "\n") +#> if (plot) { +#> outtimes_plot = seq(min(observed$time), max(observed$time), +#> length.out = 100) +#> out_plot <- mkinpredict(mkinmod, parms, odeini, outtimes_plot, +#> solution_type = solution_type, use_compiled = use_compiled, +#> method.ode = method.ode, atol = atol, rtol = rtol, +#> ...) +#> plot(0, type = "n", xlim = range(observed$time), +#> ylim = c(0, max(observed$value, na.rm = TRUE)), +#> xlab = "Time", ylab = "Observed") +#> col_obs <- pch_obs <- 1:length(obs_vars) +#> lty_obs <- rep(1, length(obs_vars)) +#> names(col_obs) <- names(pch_obs) <- names(lty_obs) <- obs_vars +#> for (obs_var in obs_vars) { +#> points(subset(observed, name == obs_var, c(time, +#> value)), pch = pch_obs[obs_var], col = col_obs[obs_var]) +#> } +#> matlines(out_plot$time, out_plot[-1], col = col_obs, +#> lty = lty_obs) +#> legend("topright", inset = c(0.05, 0.05), legend = obs_vars, +#> col = col_obs, pch = pch_obs, lty = 1:length(pch_obs)) +#> } +#> assign("cost.old", mC$model, inherits = TRUE) +#> } +#> return(mC) +#> } +#> <environment: 0x27fc328> +#> +#> $cost_notrans +#> function (P) +#> { +#> if (length(state.ini.optim) > 0) { +#> odeini <- c(P[1:length(state.ini.optim)], state.ini.fixed) +#> names(odeini) <- c(state.ini.optim.boxnames, state.ini.fixed.boxnames) +#> } +#> else { +#> odeini <- state.ini.fixed +#> names(odeini) <- state.ini.fixed.boxnames +#> } +#> odeparms <- c(P[(length(state.ini.optim) + 1):length(P)], +#> parms.fixed) +#> out <- mkinpredict(mkinmod, odeparms, odeini, outtimes, solution_type = solution_type, +#> use_compiled = use_compiled, method.ode = method.ode, +#> atol = atol, rtol = rtol, ...) +#> mC <- modCost(out, observed, y = "value", err = err, weight = weight, +#> scaleVar = scaleVar) +#> return(mC) +#> } +#> <environment: 0x27fc328> +#> +#> $hessian_notrans +#> parent_0 alpha beta +#> parent_0 4.1230329 -7.473531 0.5968527 +#> alpha -7.4735307 40.365690 -3.1777189 +#> beta 0.5968527 -3.177719 0.2503425 +#> +#> $start +#> value type +#> parent_0 98.62 state +#> alpha 1.00 deparm +#> beta 10.00 deparm +#> +#> $start_transformed +#> value lower upper +#> parent_0 98.620000 -Inf Inf +#> log_alpha 0.000000 -Inf Inf +#> log_beta 2.302585 -Inf Inf +#> +#> $fixed +#> [1] value type +#> <0 rows> (or 0-length row.names) +#> +#> $data +#> time variable observed predicted residual +#> 1 0 parent 98.62 99.66619265 -1.046192647 +#> 2 3 parent 81.43 78.10760352 3.322396479 +#> 3 7 parent 53.18 56.83515667 -3.655156669 +#> 4 14 parent 34.89 33.18468323 1.705316770 +#> 5 30 parent 10.09 10.49630626 -0.406306255 +#> 6 62 parent 1.50 1.37626531 0.123734689 +#> 7 90 parent 0.33 0.29311302 0.036886982 +#> 8 118 parent 0.08 0.07375954 0.006240458 +#> +#> $atol +#> [1] 1e-08 +#> +#> $rtol +#> [1] 1e-10 +#> +#> $weight.ini +#> [1] "none" +#> +#> $reweight.tol +#> [1] 1e-08 +#> +#> $reweight.max.iter +#> [1] 10 +#> +#> $bparms.optim +#> parent_0 alpha beta +#> 99.66619 12.80517 156.11390 +#> +#> $bparms.fixed +#> numeric(0) +#> +#> $bparms.ode +#> alpha beta +#> 12.80517 156.11390 +#> +#> $bparms.state +#> parent +#> 99.66619 +#> +#> $date +#> [1] "Thu Oct 6 09:17:52 2016" +#> +#> attr(,"class") +#> [1] "mkinfit" "modFit" +#>
fits["SFO", "B"]
#> dataset +#> model B +#> SFO List,42 +#> attr(,"class") +#> [1] "mmkin" +#>
fits[["SFO", "B"]] # This is equivalent to
#> $par +#> parent_0 log_k_parent_sink +#> 99.174072 -2.549028 +#> +#> $ssr +#> [1] 30.65564 +#> +#> $convergence +#> [1] 0 +#> +#> $iterations +#> [1] 5 +#> +#> $evaluations +#> function gradient +#> 8 15 +#> +#> $counts +#> [1] "relative convergence (4)" +#> +#> $hessian +#> parent_0 log_k_parent_sink +#> parent_0 4.163631 -94.09343 +#> log_k_parent_sink -94.093431 6311.34610 +#> +#> $residuals +#> parent parent parent parent parent parent +#> 0.55407218 -2.98452128 4.20445742 -1.68599939 -0.58185357 -0.72033730 +#> parent parent +#> -0.24260405 -0.07020339 +#> +#> $ms +#> [1] 3.831956 +#> +#> $var_ms +#> parent +#> 3.831956 +#> +#> $var_ms_unscaled +#> parent +#> 3.831956 +#> +#> $var_ms_unweighted +#> parent +#> 3.831956 +#> +#> $rank +#> [1] 2 +#> +#> $df.residual +#> [1] 6 +#> +#> $solution_type +#> [1] "analytical" +#> +#> $transform_rates +#> [1] TRUE +#> +#> $transform_fractions +#> [1] TRUE +#> +#> $method.modFit +#> [1] "Port" +#> +#> $maxit.modFit +#> [1] "auto" +#> +#> $calls +#> [1] 29 +#> +#> $time +#> user system elapsed +#> 0.068 0.000 0.068 +#> +#> $mkinmod +#> <mkinmod> model generated with +#> Use of formation fractions $use_of_ff: min +#> Specification $spec: +#> $parent +#> $type: SFO; $sink: TRUE +#> Coefficient matrix $coefmat available +#> +#> $observed +#> name time value +#> 1 parent 0 98.62 +#> 2 parent 3 81.43 +#> 3 parent 7 53.18 +#> 4 parent 14 34.89 +#> 5 parent 30 10.09 +#> 6 parent 62 1.50 +#> 7 parent 90 0.33 +#> 8 parent 118 0.08 +#> +#> $obs_vars +#> [1] "parent" +#> +#> $predicted +#> name time value +#> 1 parent 0.000000 99.17407218 +#> 2 parent 1.191919 90.35253561 +#> 3 parent 2.383838 82.31567498 +#> 4 parent 3.000000 78.44547872 +#> 5 parent 3.575758 74.99369333 +#> 6 parent 4.767677 68.32300215 +#> 7 parent 5.959596 62.24566915 +#> 8 parent 7.000000 57.38445742 +#> 9 parent 7.151515 56.70891509 +#> 10 parent 8.343434 51.66465547 +#> 11 parent 9.535354 47.06908288 +#> 12 parent 10.727273 42.88228661 +#> 13 parent 11.919192 39.06790599 +#> 14 parent 13.111111 35.59281463 +#> 15 parent 14.000000 33.20400061 +#> 16 parent 14.303030 32.42683275 +#> 17 parent 15.494949 29.54246504 +#> 18 parent 16.686869 26.91466193 +#> 19 parent 17.878788 24.52060198 +#> 20 parent 19.070707 22.33949373 +#> 21 parent 20.262626 20.35239512 +#> 22 parent 21.454545 18.54204899 +#> 23 parent 22.646465 16.89273320 +#> 24 parent 23.838384 15.39012410 +#> 25 parent 25.030303 14.02117212 +#> 26 parent 26.222222 12.77398846 +#> 27 parent 27.414141 11.63774182 +#> 28 parent 28.606061 10.60256435 +#> 29 parent 29.797980 9.65946594 +#> 30 parent 30.000000 9.50814643 +#> 31 parent 30.989899 8.80025617 +#> 32 parent 32.181818 8.01747313 +#> 33 parent 33.373737 7.30431867 +#> 34 parent 34.565657 6.65459931 +#> 35 parent 35.757576 6.06267251 +#> 36 parent 36.949495 5.52339762 +#> 37 parent 38.141414 5.03209124 +#> 38 parent 39.333333 4.58448658 +#> 39 parent 40.525253 4.17669637 +#> 40 parent 41.717172 3.80517911 +#> 41 parent 42.909091 3.46670832 +#> 42 parent 44.101010 3.15834451 +#> 43 parent 45.292929 2.87740968 +#> 44 parent 46.484848 2.62146400 +#> 45 parent 47.676768 2.38828471 +#> 46 parent 48.868687 2.17584671 +#> 47 parent 50.060606 1.98230508 +#> 48 parent 51.252525 1.80597899 +#> 49 parent 52.444444 1.64533711 +#> 50 parent 53.636364 1.49898432 +#> 51 parent 54.828283 1.36564963 +#> 52 parent 56.020202 1.24417505 +#> 53 parent 57.212121 1.13350565 +#> 54 parent 58.404040 1.03268029 +#> 55 parent 59.595960 0.94082335 +#> 56 parent 60.787879 0.85713708 +#> 57 parent 61.979798 0.78089471 +#> 58 parent 62.000000 0.77966270 +#> 59 parent 63.171717 0.71143411 +#> 60 parent 64.363636 0.64815202 +#> 61 parent 65.555556 0.59049888 +#> 62 parent 66.747475 0.53797399 +#> 63 parent 67.939394 0.49012119 +#> 64 parent 69.131313 0.44652489 +#> 65 parent 70.323232 0.40680649 +#> 66 parent 71.515152 0.37062104 +#> 67 parent 72.707071 0.33765429 +#> 68 parent 73.898990 0.30761993 +#> 69 parent 75.090909 0.28025713 +#> 70 parent 76.282828 0.25532825 +#> 71 parent 77.474747 0.23261679 +#> 72 parent 78.666667 0.21192552 +#> 73 parent 79.858586 0.19307474 +#> 74 parent 81.050505 0.17590074 +#> 75 parent 82.242424 0.16025436 +#> 76 parent 83.434343 0.14599973 +#> 77 parent 84.626263 0.13301305 +#> 78 parent 85.818182 0.12118154 +#> 79 parent 87.010101 0.11040244 +#> 80 parent 88.202020 0.10058214 +#> 81 parent 89.393939 0.09163535 +#> 82 parent 90.000000 0.08739595 +#> 83 parent 90.585859 0.08348439 +#> 84 parent 91.777778 0.07605845 +#> 85 parent 92.969697 0.06929305 +#> 86 parent 94.161616 0.06312943 +#> 87 parent 95.353535 0.05751406 +#> 88 parent 96.545455 0.05239819 +#> 89 parent 97.737374 0.04773737 +#> 90 parent 98.929293 0.04349113 +#> 91 parent 100.121212 0.03962259 +#> 92 parent 101.313131 0.03609816 +#> 93 parent 102.505051 0.03288723 +#> 94 parent 103.696970 0.02996191 +#> 95 parent 104.888889 0.02729679 +#> 96 parent 106.080808 0.02486874 +#> 97 parent 107.272727 0.02265667 +#> 98 parent 108.464646 0.02064136 +#> 99 parent 109.656566 0.01880531 +#> 100 parent 110.848485 0.01713257 +#> 101 parent 112.040404 0.01560863 +#> 102 parent 113.232323 0.01422024 +#> 103 parent 114.424242 0.01295535 +#> 104 parent 115.616162 0.01180297 +#> 105 parent 116.808081 0.01075310 +#> 106 parent 118.000000 0.00979661 +#> +#> $cost +#> function (P) +#> { +#> assign("calls", calls + 1, inherits = TRUE) +#> if (trace_parms) +#> cat(P, "\n") +#> if (length(state.ini.optim) > 0) { +#> odeini <- c(P[1:length(state.ini.optim)], state.ini.fixed) +#> names(odeini) <- c(state.ini.optim.boxnames, state.ini.fixed.boxnames) +#> } +#> else { +#> odeini <- state.ini.fixed +#> names(odeini) <- state.ini.fixed.boxnames +#> } +#> odeparms <- c(P[(length(state.ini.optim) + 1):length(P)], +#> transparms.fixed) +#> parms <- backtransform_odeparms(odeparms, mkinmod, transform_rates = transform_rates, +#> transform_fractions = transform_fractions) +#> out <- mkinpredict(mkinmod, parms, odeini, outtimes, solution_type = solution_type, +#> use_compiled = use_compiled, method.ode = method.ode, +#> atol = atol, rtol = rtol, ...) +#> assign("out_predicted", out, inherits = TRUE) +#> mC <- modCost(out, observed, y = "value", err = err, weight = weight, +#> scaleVar = scaleVar) +#> if (mC$model < cost.old) { +#> if (!quiet) +#> cat("Model cost at call ", calls, ": ", mC$model, +#> "\n") +#> if (plot) { +#> outtimes_plot = seq(min(observed$time), max(observed$time), +#> length.out = 100) +#> out_plot <- mkinpredict(mkinmod, parms, odeini, outtimes_plot, +#> solution_type = solution_type, use_compiled = use_compiled, +#> method.ode = method.ode, atol = atol, rtol = rtol, +#> ...) +#> plot(0, type = "n", xlim = range(observed$time), +#> ylim = c(0, max(observed$value, na.rm = TRUE)), +#> xlab = "Time", ylab = "Observed") +#> col_obs <- pch_obs <- 1:length(obs_vars) +#> lty_obs <- rep(1, length(obs_vars)) +#> names(col_obs) <- names(pch_obs) <- names(lty_obs) <- obs_vars +#> for (obs_var in obs_vars) { +#> points(subset(observed, name == obs_var, c(time, +#> value)), pch = pch_obs[obs_var], col = col_obs[obs_var]) +#> } +#> matlines(out_plot$time, out_plot[-1], col = col_obs, +#> lty = lty_obs) +#> legend("topright", inset = c(0.05, 0.05), legend = obs_vars, +#> col = col_obs, pch = pch_obs, lty = 1:length(pch_obs)) +#> } +#> assign("cost.old", mC$model, inherits = TRUE) +#> } +#> return(mC) +#> } +#> <environment: 0x2e966b0> +#> +#> $cost_notrans +#> function (P) +#> { +#> if (length(state.ini.optim) > 0) { +#> odeini <- c(P[1:length(state.ini.optim)], state.ini.fixed) +#> names(odeini) <- c(state.ini.optim.boxnames, state.ini.fixed.boxnames) +#> } +#> else { +#> odeini <- state.ini.fixed +#> names(odeini) <- state.ini.fixed.boxnames +#> } +#> odeparms <- c(P[(length(state.ini.optim) + 1):length(P)], +#> parms.fixed) +#> out <- mkinpredict(mkinmod, odeparms, odeini, outtimes, solution_type = solution_type, +#> use_compiled = use_compiled, method.ode = method.ode, +#> atol = atol, rtol = rtol, ...) +#> mC <- modCost(out, observed, y = "value", err = err, weight = weight, +#> scaleVar = scaleVar) +#> return(mC) +#> } +#> <environment: 0x2e966b0> +#> +#> $hessian_notrans +#> parent_0 k_parent_sink +#> parent_0 4.163631 -1203.894 +#> k_parent_sink -1203.893702 1033188.753 +#> +#> $start +#> value type +#> parent_0 98.62 state +#> k_parent_sink 0.10 deparm +#> +#> $start_transformed +#> value lower upper +#> parent_0 98.620000 -Inf Inf +#> log_k_parent_sink -2.302585 -Inf Inf +#> +#> $fixed +#> [1] value type +#> <0 rows> (or 0-length row.names) +#> +#> $data +#> time variable observed predicted residual +#> 1 0 parent 98.62 99.17407218 -0.55407218 +#> 2 3 parent 81.43 78.44547872 2.98452128 +#> 3 7 parent 53.18 57.38445742 -4.20445742 +#> 4 14 parent 34.89 33.20400061 1.68599939 +#> 5 30 parent 10.09 9.50814643 0.58185357 +#> 6 62 parent 1.50 0.77966270 0.72033730 +#> 7 90 parent 0.33 0.08739595 0.24260405 +#> 8 118 parent 0.08 0.00979661 0.07020339 +#> +#> $atol +#> [1] 1e-08 +#> +#> $rtol +#> [1] 1e-10 +#> +#> $weight.ini +#> [1] "none" +#> +#> $reweight.tol +#> [1] 1e-08 +#> +#> $reweight.max.iter +#> [1] 10 +#> +#> $bparms.optim +#> parent_0 k_parent_sink +#> 99.17407218 0.07815759 +#> +#> $bparms.fixed +#> numeric(0) +#> +#> $bparms.ode +#> k_parent_sink +#> 0.07815759 +#> +#> $bparms.state +#> parent +#> 99.17407 +#> +#> $date +#> [1] "Thu Oct 6 09:17:51 2016" +#> +#> attr(,"class") +#> [1] "mkinfit" "modFit" +#>
fits["SFO", "B", drop = TRUE]
#> [[1]] +#> $par +#> parent_0 log_k_parent_sink +#> 99.174072 -2.549028 +#> +#> $ssr +#> [1] 30.65564 +#> +#> $convergence +#> [1] 0 +#> +#> $iterations +#> [1] 5 +#> +#> $evaluations +#> function gradient +#> 8 15 +#> +#> $counts +#> [1] "relative convergence (4)" +#> +#> $hessian +#> parent_0 log_k_parent_sink +#> parent_0 4.163631 -94.09343 +#> log_k_parent_sink -94.093431 6311.34610 +#> +#> $residuals +#> parent parent parent parent parent parent +#> 0.55407218 -2.98452128 4.20445742 -1.68599939 -0.58185357 -0.72033730 +#> parent parent +#> -0.24260405 -0.07020339 +#> +#> $ms +#> [1] 3.831956 +#> +#> $var_ms +#> parent +#> 3.831956 +#> +#> $var_ms_unscaled +#> parent +#> 3.831956 +#> +#> $var_ms_unweighted +#> parent +#> 3.831956 +#> +#> $rank +#> [1] 2 +#> +#> $df.residual +#> [1] 6 +#> +#> $solution_type +#> [1] "analytical" +#> +#> $transform_rates +#> [1] TRUE +#> +#> $transform_fractions +#> [1] TRUE +#> +#> $method.modFit +#> [1] "Port" +#> +#> $maxit.modFit +#> [1] "auto" +#> +#> $calls +#> [1] 29 +#> +#> $time +#> user system elapsed +#> 0.068 0.000 0.068 +#> +#> $mkinmod +#> <mkinmod> model generated with +#> Use of formation fractions $use_of_ff: min +#> Specification $spec: +#> $parent +#> $type: SFO; $sink: TRUE +#> Coefficient matrix $coefmat available +#> +#> $observed +#> name time value +#> 1 parent 0 98.62 +#> 2 parent 3 81.43 +#> 3 parent 7 53.18 +#> 4 parent 14 34.89 +#> 5 parent 30 10.09 +#> 6 parent 62 1.50 +#> 7 parent 90 0.33 +#> 8 parent 118 0.08 +#> +#> $obs_vars +#> [1] "parent" +#> +#> $predicted +#> name time value +#> 1 parent 0.000000 99.17407218 +#> 2 parent 1.191919 90.35253561 +#> 3 parent 2.383838 82.31567498 +#> 4 parent 3.000000 78.44547872 +#> 5 parent 3.575758 74.99369333 +#> 6 parent 4.767677 68.32300215 +#> 7 parent 5.959596 62.24566915 +#> 8 parent 7.000000 57.38445742 +#> 9 parent 7.151515 56.70891509 +#> 10 parent 8.343434 51.66465547 +#> 11 parent 9.535354 47.06908288 +#> 12 parent 10.727273 42.88228661 +#> 13 parent 11.919192 39.06790599 +#> 14 parent 13.111111 35.59281463 +#> 15 parent 14.000000 33.20400061 +#> 16 parent 14.303030 32.42683275 +#> 17 parent 15.494949 29.54246504 +#> 18 parent 16.686869 26.91466193 +#> 19 parent 17.878788 24.52060198 +#> 20 parent 19.070707 22.33949373 +#> 21 parent 20.262626 20.35239512 +#> 22 parent 21.454545 18.54204899 +#> 23 parent 22.646465 16.89273320 +#> 24 parent 23.838384 15.39012410 +#> 25 parent 25.030303 14.02117212 +#> 26 parent 26.222222 12.77398846 +#> 27 parent 27.414141 11.63774182 +#> 28 parent 28.606061 10.60256435 +#> 29 parent 29.797980 9.65946594 +#> 30 parent 30.000000 9.50814643 +#> 31 parent 30.989899 8.80025617 +#> 32 parent 32.181818 8.01747313 +#> 33 parent 33.373737 7.30431867 +#> 34 parent 34.565657 6.65459931 +#> 35 parent 35.757576 6.06267251 +#> 36 parent 36.949495 5.52339762 +#> 37 parent 38.141414 5.03209124 +#> 38 parent 39.333333 4.58448658 +#> 39 parent 40.525253 4.17669637 +#> 40 parent 41.717172 3.80517911 +#> 41 parent 42.909091 3.46670832 +#> 42 parent 44.101010 3.15834451 +#> 43 parent 45.292929 2.87740968 +#> 44 parent 46.484848 2.62146400 +#> 45 parent 47.676768 2.38828471 +#> 46 parent 48.868687 2.17584671 +#> 47 parent 50.060606 1.98230508 +#> 48 parent 51.252525 1.80597899 +#> 49 parent 52.444444 1.64533711 +#> 50 parent 53.636364 1.49898432 +#> 51 parent 54.828283 1.36564963 +#> 52 parent 56.020202 1.24417505 +#> 53 parent 57.212121 1.13350565 +#> 54 parent 58.404040 1.03268029 +#> 55 parent 59.595960 0.94082335 +#> 56 parent 60.787879 0.85713708 +#> 57 parent 61.979798 0.78089471 +#> 58 parent 62.000000 0.77966270 +#> 59 parent 63.171717 0.71143411 +#> 60 parent 64.363636 0.64815202 +#> 61 parent 65.555556 0.59049888 +#> 62 parent 66.747475 0.53797399 +#> 63 parent 67.939394 0.49012119 +#> 64 parent 69.131313 0.44652489 +#> 65 parent 70.323232 0.40680649 +#> 66 parent 71.515152 0.37062104 +#> 67 parent 72.707071 0.33765429 +#> 68 parent 73.898990 0.30761993 +#> 69 parent 75.090909 0.28025713 +#> 70 parent 76.282828 0.25532825 +#> 71 parent 77.474747 0.23261679 +#> 72 parent 78.666667 0.21192552 +#> 73 parent 79.858586 0.19307474 +#> 74 parent 81.050505 0.17590074 +#> 75 parent 82.242424 0.16025436 +#> 76 parent 83.434343 0.14599973 +#> 77 parent 84.626263 0.13301305 +#> 78 parent 85.818182 0.12118154 +#> 79 parent 87.010101 0.11040244 +#> 80 parent 88.202020 0.10058214 +#> 81 parent 89.393939 0.09163535 +#> 82 parent 90.000000 0.08739595 +#> 83 parent 90.585859 0.08348439 +#> 84 parent 91.777778 0.07605845 +#> 85 parent 92.969697 0.06929305 +#> 86 parent 94.161616 0.06312943 +#> 87 parent 95.353535 0.05751406 +#> 88 parent 96.545455 0.05239819 +#> 89 parent 97.737374 0.04773737 +#> 90 parent 98.929293 0.04349113 +#> 91 parent 100.121212 0.03962259 +#> 92 parent 101.313131 0.03609816 +#> 93 parent 102.505051 0.03288723 +#> 94 parent 103.696970 0.02996191 +#> 95 parent 104.888889 0.02729679 +#> 96 parent 106.080808 0.02486874 +#> 97 parent 107.272727 0.02265667 +#> 98 parent 108.464646 0.02064136 +#> 99 parent 109.656566 0.01880531 +#> 100 parent 110.848485 0.01713257 +#> 101 parent 112.040404 0.01560863 +#> 102 parent 113.232323 0.01422024 +#> 103 parent 114.424242 0.01295535 +#> 104 parent 115.616162 0.01180297 +#> 105 parent 116.808081 0.01075310 +#> 106 parent 118.000000 0.00979661 +#> +#> $cost +#> function (P) +#> { +#> assign("calls", calls + 1, inherits = TRUE) +#> if (trace_parms) +#> cat(P, "\n") +#> if (length(state.ini.optim) > 0) { +#> odeini <- c(P[1:length(state.ini.optim)], state.ini.fixed) +#> names(odeini) <- c(state.ini.optim.boxnames, state.ini.fixed.boxnames) +#> } +#> else { +#> odeini <- state.ini.fixed +#> names(odeini) <- state.ini.fixed.boxnames +#> } +#> odeparms <- c(P[(length(state.ini.optim) + 1):length(P)], +#> transparms.fixed) +#> parms <- backtransform_odeparms(odeparms, mkinmod, transform_rates = transform_rates, +#> transform_fractions = transform_fractions) +#> out <- mkinpredict(mkinmod, parms, odeini, outtimes, solution_type = solution_type, +#> use_compiled = use_compiled, method.ode = method.ode, +#> atol = atol, rtol = rtol, ...) +#> assign("out_predicted", out, inherits = TRUE) +#> mC <- modCost(out, observed, y = "value", err = err, weight = weight, +#> scaleVar = scaleVar) +#> if (mC$model < cost.old) { +#> if (!quiet) +#> cat("Model cost at call ", calls, ": ", mC$model, +#> "\n") +#> if (plot) { +#> outtimes_plot = seq(min(observed$time), max(observed$time), +#> length.out = 100) +#> out_plot <- mkinpredict(mkinmod, parms, odeini, outtimes_plot, +#> solution_type = solution_type, use_compiled = use_compiled, +#> method.ode = method.ode, atol = atol, rtol = rtol, +#> ...) +#> plot(0, type = "n", xlim = range(observed$time), +#> ylim = c(0, max(observed$value, na.rm = TRUE)), +#> xlab = "Time", ylab = "Observed") +#> col_obs <- pch_obs <- 1:length(obs_vars) +#> lty_obs <- rep(1, length(obs_vars)) +#> names(col_obs) <- names(pch_obs) <- names(lty_obs) <- obs_vars +#> for (obs_var in obs_vars) { +#> points(subset(observed, name == obs_var, c(time, +#> value)), pch = pch_obs[obs_var], col = col_obs[obs_var]) +#> } +#> matlines(out_plot$time, out_plot[-1], col = col_obs, +#> lty = lty_obs) +#> legend("topright", inset = c(0.05, 0.05), legend = obs_vars, +#> col = col_obs, pch = pch_obs, lty = 1:length(pch_obs)) +#> } +#> assign("cost.old", mC$model, inherits = TRUE) +#> } +#> return(mC) +#> } +#> <environment: 0x2e966b0> +#> +#> $cost_notrans +#> function (P) +#> { +#> if (length(state.ini.optim) > 0) { +#> odeini <- c(P[1:length(state.ini.optim)], state.ini.fixed) +#> names(odeini) <- c(state.ini.optim.boxnames, state.ini.fixed.boxnames) +#> } +#> else { +#> odeini <- state.ini.fixed +#> names(odeini) <- state.ini.fixed.boxnames +#> } +#> odeparms <- c(P[(length(state.ini.optim) + 1):length(P)], +#> parms.fixed) +#> out <- mkinpredict(mkinmod, odeparms, odeini, outtimes, solution_type = solution_type, +#> use_compiled = use_compiled, method.ode = method.ode, +#> atol = atol, rtol = rtol, ...) +#> mC <- modCost(out, observed, y = "value", err = err, weight = weight, +#> scaleVar = scaleVar) +#> return(mC) +#> } +#> <environment: 0x2e966b0> +#> +#> $hessian_notrans +#> parent_0 k_parent_sink +#> parent_0 4.163631 -1203.894 +#> k_parent_sink -1203.893702 1033188.753 +#> +#> $start +#> value type +#> parent_0 98.62 state +#> k_parent_sink 0.10 deparm +#> +#> $start_transformed +#> value lower upper +#> parent_0 98.620000 -Inf Inf +#> log_k_parent_sink -2.302585 -Inf Inf +#> +#> $fixed +#> [1] value type +#> <0 rows> (or 0-length row.names) +#> +#> $data +#> time variable observed predicted residual +#> 1 0 parent 98.62 99.17407218 -0.55407218 +#> 2 3 parent 81.43 78.44547872 2.98452128 +#> 3 7 parent 53.18 57.38445742 -4.20445742 +#> 4 14 parent 34.89 33.20400061 1.68599939 +#> 5 30 parent 10.09 9.50814643 0.58185357 +#> 6 62 parent 1.50 0.77966270 0.72033730 +#> 7 90 parent 0.33 0.08739595 0.24260405 +#> 8 118 parent 0.08 0.00979661 0.07020339 +#> +#> $atol +#> [1] 1e-08 +#> +#> $rtol +#> [1] 1e-10 +#> +#> $weight.ini +#> [1] "none" +#> +#> $reweight.tol +#> [1] 1e-08 +#> +#> $reweight.max.iter +#> [1] 10 +#> +#> $bparms.optim +#> parent_0 k_parent_sink +#> 99.17407218 0.07815759 +#> +#> $bparms.fixed +#> numeric(0) +#> +#> $bparms.ode +#> k_parent_sink +#> 0.07815759 +#> +#> $bparms.state +#> parent +#> 99.17407 +#> +#> $date +#> [1] "Thu Oct 6 09:17:51 2016" +#> +#> attr(,"class") +#> [1] "mkinfit" "modFit" +#> +#>
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/FOCUS_2006_DFOP_ref_A_to_B.html b/docs/reference/FOCUS_2006_DFOP_ref_A_to_B.html new file mode 100644 index 00000000..5c0faa43 --- /dev/null +++ b/docs/reference/FOCUS_2006_DFOP_ref_A_to_B.html @@ -0,0 +1,129 @@ + + + + + + + + +FOCUS_2006_DFOP_ref_A_to_B. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

A table with the fitted parameters and the resulting DT50 and DT90 values +generated with different software packages. Taken directly from FOCUS (2006). +The results from fitting the data with the Topfit software was removed, as +the initial concentration of the parent compound was fixed to a value of 100 +in this fit.

+ + +
data(FOCUS_2006_DFOP_ref_A_to_B)
+ +
+

Format

+ +

A data frame containing the following variables. +

+
package
a factor giving the name of the software package
+
M0
The fitted initial concentration of the parent compound
+
f
The fitted f parameter
+
k1
The fitted k1 parameter
+
k2
The fitted k2 parameter
+
DT50
The resulting half-life of the parent compound
+
DT90
The resulting DT90 of the parent compound
+
dataset
The FOCUS dataset that was used
+

+
+ +
+

Source

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
data(FOCUS_2006_DFOP_ref_A_to_B)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/FOCUS_2006_FOMC_ref_A_to_F.html b/docs/reference/FOCUS_2006_FOMC_ref_A_to_F.html new file mode 100644 index 00000000..89faecbf --- /dev/null +++ b/docs/reference/FOCUS_2006_FOMC_ref_A_to_F.html @@ -0,0 +1,128 @@ + + + + + + + + +FOCUS_2006_FOMC_ref_A_to_F. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

A table with the fitted parameters and the resulting DT50 and DT90 values +generated with different software packages. Taken directly from FOCUS (2006). +The results from fitting the data with the Topfit software was removed, as +the initial concentration of the parent compound was fixed to a value of 100 +in this fit.

+ + +
data(FOCUS_2006_FOMC_ref_A_to_F)
+ +
+

Format

+ +

A data frame containing the following variables. +

+
package
a factor giving the name of the software package
+
M0
The fitted initial concentration of the parent compound
+
alpha
The fitted alpha parameter
+
beta
The fitted beta parameter
+
DT50
The resulting half-life of the parent compound
+
DT90
The resulting DT90 of the parent compound
+
dataset
The FOCUS dataset that was used
+

+
+ +
+

Source

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
data(FOCUS_2006_FOMC_ref_A_to_F)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/FOCUS_2006_HS_ref_A_to_F.html b/docs/reference/FOCUS_2006_HS_ref_A_to_F.html new file mode 100644 index 00000000..2dfafec6 --- /dev/null +++ b/docs/reference/FOCUS_2006_HS_ref_A_to_F.html @@ -0,0 +1,129 @@ + + + + + + + + +FOCUS_2006_HS_ref_A_to_F. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

A table with the fitted parameters and the resulting DT50 and DT90 values +generated with different software packages. Taken directly from FOCUS (2006). +The results from fitting the data with the Topfit software was removed, as +the initial concentration of the parent compound was fixed to a value of 100 +in this fit.

+ + +
data(FOCUS_2006_HS_ref_A_to_F)
+ +
+

Format

+ +

A data frame containing the following variables. +

+
package
a factor giving the name of the software package
+
M0
The fitted initial concentration of the parent compound
+
tb
The fitted tb parameter
+
k1
The fitted k1 parameter
+
k2
The fitted k2 parameter
+
DT50
The resulting half-life of the parent compound
+
DT90
The resulting DT90 of the parent compound
+
dataset
The FOCUS dataset that was used
+

+
+ +
+

Source

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
data(FOCUS_2006_HS_ref_A_to_F)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/FOCUS_2006_SFO_ref_A_to_F.html b/docs/reference/FOCUS_2006_SFO_ref_A_to_F.html new file mode 100644 index 00000000..ed3a4aff --- /dev/null +++ b/docs/reference/FOCUS_2006_SFO_ref_A_to_F.html @@ -0,0 +1,127 @@ + + + + + + + + +FOCUS_2006_SFO_ref_A_to_F. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

A table with the fitted parameters and the resulting DT50 and DT90 values +generated with different software packages. Taken directly from FOCUS (2006). +The results from fitting the data with the Topfit software was removed, as +the initial concentration of the parent compound was fixed to a value of 100 +in this fit.

+ + +
data(FOCUS_2006_SFO_ref_A_to_F)
+ +
+

Format

+ +

A data frame containing the following variables. +

+
package
a factor giving the name of the software package
+
M0
The fitted initial concentration of the parent compound
+
k
The fitted first-order degradation rate constant
+
DT50
The resulting half-life of the parent compound
+
DT90
The resulting DT90 of the parent compound
+
dataset
The FOCUS dataset that was used
+

+
+ +
+

Source

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
data(FOCUS_2006_SFO_ref_A_to_F)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/FOCUS_2006_datasets.html b/docs/reference/FOCUS_2006_datasets.html new file mode 100644 index 00000000..c1eacbd8 --- /dev/null +++ b/docs/reference/FOCUS_2006_datasets.html @@ -0,0 +1,130 @@ + + + + + + + + +FOCUS_2006_datasets. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Data taken from FOCUS (2006), p. 258.

+ + +
FOCUS_2006_datasets
+ +
+

Format

+ +

6 datasets with observations on the following variables. +

+
name
a factor containing the name of the observed variable
+
time
a numeric vector containing time points
+
value
a numeric vector containing concentrations in percent of applied radioactivity
+

+
+ +
+

Source

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
FOCUS_2006_C
#> name time value +#> 1 parent 0 85.1 +#> 2 parent 1 57.9 +#> 3 parent 3 29.9 +#> 4 parent 7 14.6 +#> 5 parent 14 9.7 +#> 6 parent 28 6.6 +#> 7 parent 63 4.0 +#> 8 parent 91 3.9 +#> 9 parent 119 0.6 +#>
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/FOMC.solution.html b/docs/reference/FOMC.solution.html new file mode 100644 index 00000000..912cf414 --- /dev/null +++ b/docs/reference/FOMC.solution.html @@ -0,0 +1,147 @@ + + + + + + + + +FOMC.solution. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function describing exponential decline from a defined starting value, with + a decreasing rate constant.

+ +

The form given here differs slightly from the original reference by Gustafson + and Holden (1990). The parameter beta corresponds to 1/beta in the + original equation.

+ + +
FOMC.solution(t, parent.0, alpha, beta)
+ +

Arguments

+
+
t
+
Time.
+
parent.0
+
Starting value for the response variable at time zero.
+
alpha
+
+ Shape parameter determined by coefficient of variation of rate constant + values.
+
beta
+
+ Location parameter. +
+
+ +
+

Note

+ +

The solution of the FOMC kinetic model reduces to the + SFO.solution for large values of alpha and + beta with + \(k = \frac{\beta}{\alpha}\).

+
+ +
+

Value

+ +

The value of the response variable at time t.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+

Gustafson DI and Holden LR (1990) Nonlinear pesticide dissipation in soil: A + new model based on spatial variability. Environmental Science and + Technology 24, 1032-1038

+
+ +

Examples

+
plot(function(x) FOMC.solution(x, 100, 10, 2), 0, 2, ylim = c(0, 100))
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/HS.solution.html b/docs/reference/HS.solution.html new file mode 100644 index 00000000..994f8373 --- /dev/null +++ b/docs/reference/HS.solution.html @@ -0,0 +1,131 @@ + + + + + + + + +HS.solution. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function describing two exponential decline functions with a break point + between them.

+ + +
HS.solution(t, parent.0, k1, k2, tb)
+ +

Arguments

+
+
t
+
Time.
+
parent.0
+
Starting value for the response variable at time zero.
+
k1
+
First kinetic constant.
+
k2
+
Second kinetic constant.
+
tb
+
Break point. Before this time, exponential decline according + to k1 is calculated, after this time, exponential decline proceeds + according to k2.
+
+ +
+

Value

+ +

The value of the response variable at time t.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
plot(function(x) HS.solution(x, 100, 2, 0.3, 0.5), 0, 2, ylim=c(0,100))
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/IORE.solution.html b/docs/reference/IORE.solution.html new file mode 100644 index 00000000..06f5c1ad --- /dev/null +++ b/docs/reference/IORE.solution.html @@ -0,0 +1,149 @@ + + + + + + + + +IORE.solution. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function describing exponential decline from a defined starting value, with + a concentration dependent rate constant.

+ + +
IORE.solution(t, parent.0, k__iore, N)
+ +

Arguments

+
+
t
+
Time.
+
parent.0
+
Starting value for the response variable at time zero.
+
k__iore
+
Rate constant. Note that this depends on the concentration units used.
+
N
+
Exponent describing the nonlinearity of the rate equation
+
+ +
+

Note

+ +

The solution of the IORE kinetic model reduces to the + SFO.solution if N = 1. + The parameters of the IORE model can be transformed to equivalent parameters + of the FOMC mode - see the NAFTA guidance for details.

+
+ +
+

Value

+ +

The value of the response variable at time t.

+
+ +
+

References

+ +

NAFTA Technical Working Group on Pesticides (not dated) Guidance for + Evaluating and Calculating Degradation Kinetics in Environmental + Media

+
+ +

Examples

+
plot(function(x) IORE.solution(x, 100, 0.2, 1.3), 0, 2, + ylim = c(0, 100))
fit.fomc <- mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE) + fit.iore <- mkinfit("IORE", FOCUS_2006_C, quiet = TRUE) + fit.iore.deS <- mkinfit("IORE", FOCUS_2006_C, solution_type = "deSolve", quiet = TRUE) + + print(data.frame(coef(fit.fomc), coef(fit.iore), coef(fit.iore.deS), + row.names = paste("model par", 1:3)))
#> coef.fit.fomc. coef.fit.iore. coef.fit.iore.deS. +#> model par 1 85.87489063 85.874891 85.874890 +#> model par 2 0.05192238 -4.826631 -4.826631 +#> model par 3 0.65096665 1.949403 1.949403 +#>
print(rbind(fomc = endpoints(fit.fomc)$distimes, iore = endpoints(fit.iore)$distimes, + iore.deS = endpoints(fit.iore)$distimes))
#> DT50 DT90 DT50back +#> fomc 1.785233 15.1479 4.559973 +#> iore 1.785233 15.1479 4.559973 +#> iore.deS 1.785233 15.1479 4.559973 +#>
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/SFO.solution.html b/docs/reference/SFO.solution.html new file mode 100644 index 00000000..9cf069d7 --- /dev/null +++ b/docs/reference/SFO.solution.html @@ -0,0 +1,124 @@ + + + + + + + + +SFO.solution. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function describing exponential decline from a defined starting value.

+ + +
SFO.solution(t, parent.0, k)
+ +

Arguments

+
+
t
+
Time.
+
parent.0
+
Starting value for the response variable at time zero.
+
k
+
Kinetic constant.
+
+ +
+

Value

+ +

The value of the response variable at time t.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
## Not run: plot(function(x) SFO.solution(x, 100, 3), 0, 2)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/SFORB.solution.html b/docs/reference/SFORB.solution.html new file mode 100644 index 00000000..57959f26 --- /dev/null +++ b/docs/reference/SFORB.solution.html @@ -0,0 +1,133 @@ + + + + + + + + +SFORB.solution. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function describing the solution of the differential equations describing + the kinetic model with first-order terms for a two-way transfer from a free + to a bound fraction, and a first-order degradation term for the free + fraction. The initial condition is a defined amount in the free fraction and + no substance in the bound fraction.

+ + +
SFORB.solution(t, parent.0, k_12, k_21, k_1output)
+ +

Arguments

+
+
t
+
Time.
+
parent.0
+
Starting value for the response variable at time zero.
+
k_12
+
Kinetic constant describing transfer from free to bound.
+
k_21
+
Kinetic constant describing transfer from bound to free.
+
k_1output
+
Kinetic constant describing degradation of the free fraction.
+
+ +
+

Value

+ +

The value of the response variable, which is the sum of free and bound + fractions at time t.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
## Not run: plot(function(x) SFORB.solution(x, 100, 0.5, 2, 3), 0, 2)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/add_err.html b/docs/reference/add_err.html new file mode 100644 index 00000000..cbc925ca --- /dev/null +++ b/docs/reference/add_err.html @@ -0,0 +1,196 @@ + + + + + + + + +add_err. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Normally distributed errors are added to data predicted for a specific + degradation model using mkinpredict. The variance of the error + may depend on the predicted value and is specified as a standard deviation.

+ + +
add_err(prediction, sdfunc,
+          n = 1000, LOD = 0.1, reps = 2,
+          digits = 1, seed = NA)
+ +

Arguments

+
+
prediction
+
+ A prediction from a kinetic model as produced by mkinpredict. +
+
sdfunc
+
+ A function taking the predicted value as its only argument and returning + a standard deviation that should be used for generating the random error + terms for this value. +
+
n
+
+ The number of datasets to be generated. +
+
LOD
+
+ The limit of detection (LOD). Values that are below the LOD after adding + the random error will be set to NA. +
+
reps
+
+ The number of replicates to be generated within the datasets. +
+
digits
+
+ The number of digits to which the values will be rounded. +
+
seed
+
+ The seed used for the generation of random numbers. If NA, the seed + is not set. +
+
+ +
+

Value

+ +

A list of datasets compatible with mmkin, i.e. + the components of the list are datasets compatible with + mkinfit.

+
+ +
+

References

+ +

Ranke J and Lehmann R (2015) To t-test or not to t-test, that is the question. XV Symposium on Pesticide Chemistry 2-4 September 2015, Piacenza, Italy + http://chem.uft.uni-bremen.de/ranke/posters/piacenza_2015.pdf

+
+ +

Examples

+
# The kinetic model +m_SFO_SFO <- mkinmod(parent = mkinsub("SFO", "M1"), + M1 = mkinsub("SFO"), use_of_ff = "max")
Successfully compiled differential equation model from auto-generated C code.
+# Generate a prediction for a specific set of parameters +sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) + +# This is the prediction used for the "Type 2 datasets" on the Piacenza poster +# from 2015 +d_SFO_SFO <- mkinpredict(m_SFO_SFO, + c(k_parent = 0.1, f_parent_to_M1 = 0.5, + k_M1 = log(2)/1000), + c(parent = 100, M1 = 0), + sampling_times) + +# Add an error term with a constant (independent of the value) standard deviation +# of 10, and generate three datasets +d_SFO_SFO_err <- add_err(d_SFO_SFO, function(x) 10, n = 3, seed = 123456789 ) + +# Name the datasets for nicer plotting +names(d_SFO_SFO_err) <- paste("Dataset", 1:3) + +# Name the model in the list of models (with only one member in this case) +# for nicer plotting later on. +# Be quiet and use the faster Levenberg-Marquardt algorithm, as the datasets +# are easy and examples are run often. Use only one core not to offend CRAN +# checks +f_SFO_SFO <- mmkin(list("SFO-SFO" = m_SFO_SFO), + d_SFO_SFO_err, cores = 1, + quiet = TRUE, method.modFit = "Marq") + +plot(f_SFO_SFO)
+# We would like to inspect the fit for dataset 3 more closely +# Using double brackets makes the returned object an mkinfit object +# instead of a list of mkinfit objects, so plot.mkinfit is used +plot(f_SFO_SFO[[3]], show_residuals = TRUE)
+# If we use single brackets, we should give two indices (model and dataset), +# and plot.mmkin is used +plot(f_SFO_SFO[1, 3])
+
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/endpoints.html b/docs/reference/endpoints.html new file mode 100644 index 00000000..8ceb39d9 --- /dev/null +++ b/docs/reference/endpoints.html @@ -0,0 +1,123 @@ + + + + + + + + +endpoints. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function calculates DT50 and DT90 values as well as formation fractions from kinetic models +fitted with mkinfit. If the SFORB model was specified for one of the parents or metabolites, +the Eigenvalues are returned. These are equivalent to the rate constantes of the DFOP model, but +with the advantage that the SFORB model can also be used for metabolites.

+ + +
endpoints(fit)
+ +

Arguments

+
+
fit
+
+ An object of class mkinfit. +
+
+ +
+

Note

+ +

The function is used internally by summary.mkinfit.

+
+ +
+

Value

+ +

A list with the components mentioned above.

+
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/geometric_mean.html b/docs/reference/geometric_mean.html new file mode 100644 index 00000000..1d9a9e66 --- /dev/null +++ b/docs/reference/geometric_mean.html @@ -0,0 +1,115 @@ + + + + + + + + +geometric_mean. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Function calculating the geometric mean of numeric vectors

+ + +
geometric_mean(x, na.rm = FALSE)
+ +

Arguments

+
+
x
+
A numeric vector
+
na.rm
+
Should NA values be ignored
+
+ +
+

Value

+ +

The geometric mean.

+
+ +

Examples

+
geometric_mean(c(1,3, 9))
#> [1] 3 +#>
geometric_mean(c(1,3, NA))
#> [1] NA +#>
geometric_mean(c(1,3, NA), na.rm = TRUE)
#> [1] 1.732051 +#>
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/ilr.html b/docs/reference/ilr.html new file mode 100644 index 00000000..355cbb78 --- /dev/null +++ b/docs/reference/ilr.html @@ -0,0 +1,152 @@ + + + + + + + + +ilr. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This implementation is a special case of the class of isometric log-ratio transformations.

+ + +
ilr(x)
+  invilr(x)
+ +

Arguments

+
+
x
+
+ A numeric vector. Naturally, the forward transformation is only sensible for + vectors with all elements being greater than zero. +
+
+ +
+

Value

+ +

The result of the forward or backward transformation. The returned components always + sum to 1 for the case of the inverse log-ratio transformation.

+
+ +
+

References

+ +

Peter Filzmoser, Karel Hron (2008) Outlier Detection for Compositional Data Using Robust Methods. Math Geosci 40 233-248

+
+ +
+

See also

+ +

Another implementation can be found in R package robCompositions.

+
+ +

Examples

+
# Order matters +ilr(c(0.1, 1, 10))
#> [1] -1.628174 -2.820079 +#>
ilr(c(10, 1, 0.1))
#> [1] 1.628174 2.820079 +#>
# Equal entries give ilr transformations with zeros as elements +ilr(c(3, 3, 3))
#> [1] 0 0 +#>
# Almost equal entries give small numbers +ilr(c(0.3, 0.4, 0.3))
#> [1] -0.2034219 0.1174457 +#>
# Only the ratio between the numbers counts, not their sum +invilr(ilr(c(0.7, 0.29, 0.01)))
#> [1] 0.70 0.29 0.01 +#>
invilr(ilr(2.1 * c(0.7, 0.29, 0.01)))
#> [1] 0.70 0.29 0.01 +#>
# Inverse transformation of larger numbers gives unequal elements +invilr(-10)
#> [1] 7.213536e-07 9.999993e-01 +#>
invilr(c(-10, 0))
#> [1] 7.207415e-07 9.991507e-01 8.486044e-04 +#>
# The sum of the elements of the inverse ilr is 1 +sum(invilr(c(-10, 0)))
#> [1] 1 +#>
# This is why we do not need all elements of the inverse transformation to go back: +a <- c(0.1, 0.3, 0.5) +b <- invilr(a) +length(b) # Four elements
#> [1] 4 +#>
ilr(c(b[1:3], 1 - sum(b[1:3]))) # Gives c(0.1, 0.3, 0.5)
#> [1] 0.1 0.3 0.5 +#>
+
+
+

Author

+ + René Lehmann and Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 00000000..869f61dd --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,111 @@ + + + + + + + + +Function reference. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+
+

Main functions

+

Essential functionality

+ +
+
mkinfit
+
+
+
mkinmod
+
+
+
mmkin
+
+
+
+
+
+

Show results

+

+ +
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/mccall81_245T.html b/docs/reference/mccall81_245T.html new file mode 100644 index 00000000..edfce55a --- /dev/null +++ b/docs/reference/mccall81_245T.html @@ -0,0 +1,229 @@ + + + + + + + + +mccall81_245T. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Time course of 2,4,5-trichlorophenoxyacetic acid, and the corresponding + 2,4,5-trichlorophenol and 2,4,5-trichloroanisole as recovered in diethylether + extracts.

+ + +
mccall81_245T
+ +
+

Format

+ +

A dataframe containing the following variables. +

+
name
the name of the compound observed. Note that T245 is used as + an acronym for 2,4,5-T. T245 is a legitimate object name + in R, which is necessary for specifying models using + mkinmod.
+
time
a numeric vector containing sampling times in days after + treatment
+
value
a numeric vector containing concentrations in percent of applied radioactivity
+
soil
a factor containing the name of the soil
+

+
+ +
+

Source

+ +

McCall P, Vrona SA, Kelley SS (1981) Fate of uniformly carbon-14 ring labeled 2,4,5-Trichlorophenoxyacetic acid and 2,4-dichlorophenoxyacetic acid. J Agric Chem 29, 100-107 + http://dx.doi.org/10.1021/jf00103a026

+
+ +

Examples

+
SFO_SFO_SFO <- mkinmod(T245 = list(type = "SFO", to = "phenol"), + phenol = list(type = "SFO", to = "anisole"), + anisole = list(type = "SFO"))
Successfully compiled differential equation model from auto-generated C code.
## Not run: ------------------------------------ +# fit.1 <- mkinfit(SFO_SFO_SFO, subset(mccall81_245T, soil == "Commerce")) +# summary(fit.1, data = FALSE) +# +## --------------------------------------------- + # No covariance matrix and k_phenol_sink is really small, therefore fix it to zero + fit.2 <- mkinfit(SFO_SFO_SFO, subset(mccall81_245T, soil == "Commerce"), + parms.ini = c(k_phenol_sink = 0), + fixed_parms = "k_phenol_sink", quiet = TRUE) + summary(fit.2, data = FALSE)
#> mkin version: 0.9.44.9000 +#> R version: 3.3.1 +#> Date of fit: Thu Oct 6 09:17:57 2016 +#> Date of summary: Thu Oct 6 09:17:57 2016 +#> +#> Equations: +#> d_T245 = - k_T245_sink * T245 - k_T245_phenol * T245 +#> d_phenol = + k_T245_phenol * T245 - k_phenol_sink * phenol - +#> k_phenol_anisole * phenol +#> d_anisole = + k_phenol_anisole * phenol - k_anisole_sink * anisole +#> +#> Model predictions using solution type deSolve +#> +#> Fitted with method Port using 246 model solutions performed in 1.508 s +#> +#> Weighting: none +#> +#> Starting values for parameters to be optimised: +#> value type +#> T245_0 100.9000 state +#> k_T245_sink 0.1000 deparm +#> k_T245_phenol 0.1001 deparm +#> k_phenol_anisole 0.1002 deparm +#> k_anisole_sink 0.1003 deparm +#> +#> Starting values for the transformed parameters actually optimised: +#> value lower upper +#> T245_0 100.900000 -Inf Inf +#> log_k_T245_sink -2.302585 -Inf Inf +#> log_k_T245_phenol -2.301586 -Inf Inf +#> log_k_phenol_anisole -2.300587 -Inf Inf +#> log_k_anisole_sink -2.299590 -Inf Inf +#> +#> Fixed parameter values: +#> value type +#> phenol_0 0 state +#> anisole_0 0 state +#> k_phenol_sink 0 deparm +#> +#> Optimised, transformed parameters with symmetric confidence intervals: +#> Estimate Std. Error Lower Upper +#> T245_0 103.9000 2.35200 98.930 108.8000 +#> log_k_T245_sink -4.1130 0.13250 -4.390 -3.8350 +#> log_k_T245_phenol -3.6120 0.05002 -3.716 -3.5070 +#> log_k_phenol_anisole -0.9037 0.30580 -1.544 -0.2637 +#> log_k_anisole_sink -5.0090 0.11180 -5.243 -4.7750 +#> +#> Parameter correlation: +#> T245_0 log_k_T245_sink log_k_T245_phenol +#> T245_0 1.00000 0.63761 -0.1742 +#> log_k_T245_sink 0.63761 1.00000 -0.3831 +#> log_k_T245_phenol -0.17416 -0.38313 1.0000 +#> log_k_phenol_anisole -0.05948 0.08745 -0.3047 +#> log_k_anisole_sink -0.16208 -0.60469 0.5227 +#> log_k_phenol_anisole log_k_anisole_sink +#> T245_0 -0.05948 -0.1621 +#> log_k_T245_sink 0.08745 -0.6047 +#> log_k_T245_phenol -0.30470 0.5227 +#> log_k_phenol_anisole 1.00000 -0.1774 +#> log_k_anisole_sink -0.17744 1.0000 +#> +#> Residual standard error: 2.706 on 19 degrees of freedom +#> +#> Backtransformed parameters: +#> Confidence intervals for internally transformed parameters are asymmetric. +#> t-test (unrealistically) based on the assumption of normal distribution +#> for estimators of untransformed parameters. +#> Estimate t value Pr(>t) Lower Upper +#> T245_0 1.039e+02 44.160 6.462e-21 98.930000 108.80000 +#> k_T245_sink 1.636e-02 7.545 1.978e-07 0.012400 0.02159 +#> k_T245_phenol 2.701e-02 19.990 1.607e-14 0.024320 0.02999 +#> k_phenol_anisole 4.051e-01 3.270 2.014e-03 0.213600 0.76820 +#> k_anisole_sink 6.679e-03 8.942 1.544e-08 0.005285 0.00844 +#> +#> Chi2 error levels in percent: +#> err.min n.optim df +#> All data 9.831 5 17 +#> T245 7.908 3 5 +#> phenol 99.808 1 6 +#> anisole 5.379 1 6 +#> +#> Resulting formation fractions: +#> ff +#> T245_sink 0.3772 +#> T245_phenol 0.6228 +#> phenol_anisole 1.0000 +#> phenol_sink 0.0000 +#> anisole_sink 1.0000 +#> +#> Estimated disappearance times: +#> DT50 DT90 +#> T245 15.982 53.091 +#> phenol 1.711 5.685 +#> anisole 103.784 344.763 +#>
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/mkin_long_to_wide.html b/docs/reference/mkin_long_to_wide.html new file mode 100644 index 00000000..5b1a8353 --- /dev/null +++ b/docs/reference/mkin_long_to_wide.html @@ -0,0 +1,152 @@ + + + + + + + + +mkin_long_to_wide. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function takes a dataframe in the long form as required by modCost + and converts it into a dataframe with one independent variable and several + dependent variables as columns.

+ + +
mkin_long_to_wide(long_data, time = "time", outtime = "time")
+ +

Arguments

+
+
long_data
+
+ The dataframe must contain one variable called "time" with the time values specified by the + time argument, one column called "name" with the grouping of the observed values, and + finally one column of observed values called "value". +
+
time
+
+ The name of the time variable in the long input data. +
+
outtime
+
+ The name of the time variable in the wide output data. +
+
+ +
+

Value

+ +

Dataframe in wide format.

+
+ +

Examples

+
mkin_long_to_wide(FOCUS_2006_D)
#> time parent m1 +#> 1 0 99.46 0.00 +#> 2 0 102.04 0.00 +#> 3 1 93.50 4.84 +#> 4 1 92.50 5.64 +#> 5 3 63.23 12.91 +#> 6 3 68.99 12.96 +#> 7 7 52.32 22.97 +#> 8 7 55.13 24.47 +#> 9 14 27.27 41.69 +#> 10 14 26.64 33.21 +#> 11 21 11.50 44.37 +#> 12 21 11.64 46.44 +#> 13 35 2.85 41.22 +#> 14 35 2.91 37.95 +#> 15 50 0.69 41.19 +#> 16 50 0.63 40.01 +#> 17 75 0.05 40.09 +#> 18 75 0.06 33.85 +#> 19 100 NA 31.04 +#> 20 100 NA 33.13 +#> 21 120 NA 25.15 +#> 22 120 NA 33.31 +#>
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkin_wide_to_long.html b/docs/reference/mkin_wide_to_long.html new file mode 100644 index 00000000..2a70ebbe --- /dev/null +++ b/docs/reference/mkin_wide_to_long.html @@ -0,0 +1,131 @@ + + + + + + + + +mkin_wide_to_long. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function simply takes a dataframe with one independent variable and several + dependent variable and converts it into the long form as required by modCost.

+ + +
mkin_wide_to_long(wide_data, time = "t")
+ +

Arguments

+
+
wide_data
+
+ The dataframe must contain one variable with the time values specified by the + time argument and usually more than one column of observed values. +
+
time
+
+ The name of the time variable. +
+
+ +
+

Value

+ +

Dataframe in long format as needed for modCost.

+
+ +

Examples

+
wide <- data.frame(t = c(1,2,3), x = c(1,4,7), y = c(3,4,5)) +mkin_wide_to_long(wide)
#> name time value +#> 1 x 1 1 +#> 2 x 2 4 +#> 3 x 3 7 +#> 4 y 1 3 +#> 5 y 2 4 +#> 6 y 3 5 +#>
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinds.html b/docs/reference/mkinds.html new file mode 100644 index 00000000..0b4341aa --- /dev/null +++ b/docs/reference/mkinds.html @@ -0,0 +1,120 @@ + + + + + + + + +mkinds. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

A dataset class for mkin

+ + +
mkinds
+ +
+

Format

+ +

An R6Class generator object.

+
+ +
+

Fields

+ +

+

+
title
A full title for the dataset

+

sampling
times The sampling times

+

time_unit
The time unit

+

observed
Names of the observed compounds

+

unit
The unit of the observations

+

replicates
The number of replicates

+

data
A dataframe with at least the columns name, time and value +in order to be compatible with mkinfit
+

+
+ +

Examples

+
mds <- mkinds$new("FOCUS A", FOCUS_2006_A)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/mkinerrmin.html b/docs/reference/mkinerrmin.html new file mode 100644 index 00000000..cd9faf1a --- /dev/null +++ b/docs/reference/mkinerrmin.html @@ -0,0 +1,150 @@ + + + + + + + + +mkinerrmin. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function uses optimize in order to iteratively find the +smallest relative error still resulting in passing the chi-squared test +as defined in the FOCUS kinetics report from 2006.

+ + +
mkinerrmin(fit, alpha = 0.05)
+ +

Arguments

+
+
fit
+
+ an object of class mkinfit. +
+
alpha
+
+ The confidence level chosen for the chi-squared test. +
+
+ +
+

Value

+ +

A dataframe with the following components:

+

The dataframe has one row for the total dataset and one further row for + each observed state variable in the model.

+
+ +
+

Details

+ +

This function is used internally by summary.mkinfit.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
SFO_SFO = mkinmod(parent = list(type = "SFO", to = "m1"), + m1 = list(type = "SFO"), + use_of_ff = "max")
Successfully compiled differential equation model from auto-generated C code.
+fit_FOCUS_D = mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE) +round(mkinerrmin(fit_FOCUS_D), 4)
#> err.min n.optim df +#> All data 0.0640 4 15 +#> parent 0.0646 2 7 +#> m1 0.0469 2 8 +#>
fit_FOCUS_E = mkinfit(SFO_SFO, FOCUS_2006_E, quiet = TRUE) +round(mkinerrmin(fit_FOCUS_E), 4)
#> err.min n.optim df +#> All data 0.1544 4 13 +#> parent 0.1659 2 7 +#> m1 0.1095 2 6 +#>
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/mkinfit.html b/docs/reference/mkinfit.html new file mode 100644 index 00000000..d1441f8b --- /dev/null +++ b/docs/reference/mkinfit.html @@ -0,0 +1,531 @@ + + + + + + + + +mkinfit. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

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 = "none",
+  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, ...)
+ +

Arguments

+
+
mkinmod
+
+ A list of class 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 variable with the highest value in + observed. +
+
observed
+
+ The observed data. It has to be in the long format as described in + modFit, i.e. the first column called "name" must contain the + name of the observed variable for each data point. The second column must + contain the times of observation, named "time". The third column must be + named "value" and contain the observed values. Optionally, a further column + can contain weights for each data point. Its name must be passed as a + further argument named err which is then passed on to + modFit. +
+
parms.ini
+
+ A named vector of initial values for the parameters, including parameters + to be optimised and potentially also fixed parameters as indicated by + fixed_parms. If set to "auto", initial values for rate constants + are set to default values. Using parameter names that are not in the model + gives an error. + + 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 map component of 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. +
+
fixed_parms
+
+ The names of parameters that should not be optimised but rather kept at the + values specified in parms.ini. +
+
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 + deSolve is used. If set to "analytical", an analytical + solution of the model is used. This is only implemented for simple + degradation experiments with only one state variable, i.e. with no + metabolites. The default is "auto", which uses "analytical" if possible, + otherwise "eigen" if the model can be expressed using eigenvalues and + eigenvectors, and finally "deSolve" for the remaining models (time + dependence of degradation rates and metabolites). This argument is passed + on to the helper function mkinpredict. +
+
method.ode
+
+ The solution method passed via mkinpredict to + ode in case the solution type is "deSolve". The default + "lsoda" is performant, but sometimes fails to converge. +
+
use_compiled
+
+ If set to FALSE, no compiled version of the mkinmod + model is used, in the calls to mkinpredict even if + a compiled verion is present. +
+
method.modFit
+
+ The optimisation method passed to modFit. + + 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 + nls.lm from the package 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. + + The "Newton" algorithm is not included because its number of iterations + can not be controlled by control.modFit and it does not appear + to provide advantages over the other algorithms. +
+
maxit.modFit
+
+ Maximum number of iterations in the optimisation. If not "auto", this will + be passed to the method called by modFit, overriding + what may be specified in the next argument control.modFit. +
+
control.modFit
+
+ Additional arguments passed to the optimisation method used by + modFit. +
+
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 + ilr transformation. +
+
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 NULL, or the name of the column with the + error estimates, used to weigh the residuals (see details of + modCost); if NULL, then the residuals are not weighed. +
+
weight
+
+ only if err=NULL: how to weight the residuals, one of "none", + "std", "mean", see details of modCost. +
+
scaleVar
+
+ Will be passed to modCost. Default is not to scale Variables + according to the number of observations. +
+
atol
+
+ Absolute error tolerance, passed to ode. Default is 1e-8, + lower than in lsoda. +
+
rtol
+
+ Absolute error tolerance, passed to ode. Default is 1e-10, + much lower than in lsoda. +
+
n.outtimes
+
+ The length of the dataseries that is produced by the model prediction + function mkinpredict. This impacts the accuracy of + the numerical solver if that is used (see solution_type argument. + The default value is 100. +
+
reweight.method
+
+ The method used for iteratively reweighting residuals, also known + as iteratively reweighted least squares (IRLS). Default is NULL, + the other method implemented is called "obs", meaning that each + observed variable is assumed to have its own variance, this is + estimated from the fit and used for weighting the residuals + in each iteration until convergence of this estimate up to + reweight.tol or up to the maximum number of iterations + specified by reweight.max.iter. +
+
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? +
+
&#8230;
+
+ Further arguments that will be passed to modFit. +
+
+ +
+

Value

+ +

A list with "mkinfit" and "modFit" in the class attribute. + A summary can be obtained by summary.mkinfit.

+
+ +
+

See also

+ +

Plotting methods plot.mkinfit and + mkinparplot.

+

Fitting of several models to several datasets in a single call to + mmkin.

+
+ +
+

Note

+ +

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.

+
+ +
+

Note

+ +

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.

+
+ +

Examples

+
# Use shorthand notation for parent only degradation +fit <- mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE) +summary(fit)
#> mkin version: 0.9.44.9000 +#> R version: 3.3.1 +#> Date of fit: Thu Oct 6 09:17:59 2016 +#> Date of summary: Thu Oct 6 09:17:59 2016 +#> +#> Equations: +#> d_parent = - (alpha/beta) * 1/((time/beta) + 1) * parent +#> +#> Model predictions using solution type analytical +#> +#> Fitted with method Port using 64 model solutions performed in 0.153 s +#> +#> Weighting: none +#> +#> Starting values for parameters to be optimised: +#> value type +#> parent_0 85.1 state +#> alpha 1.0 deparm +#> beta 10.0 deparm +#> +#> Starting values for the transformed parameters actually optimised: +#> value lower upper +#> parent_0 85.100000 -Inf Inf +#> log_alpha 0.000000 -Inf Inf +#> log_beta 2.302585 -Inf Inf +#> +#> Fixed parameter values: +#> None +#> +#> Optimised, transformed parameters with symmetric confidence intervals: +#> Estimate Std. Error Lower Upper +#> parent_0 85.87000 2.2460 80.38000 91.3700 +#> log_alpha 0.05192 0.1605 -0.34080 0.4446 +#> log_beta 0.65100 0.2801 -0.03452 1.3360 +#> +#> Parameter correlation: +#> parent_0 log_alpha log_beta +#> parent_0 1.0000 -0.2033 -0.3624 +#> log_alpha -0.2033 1.0000 0.9547 +#> log_beta -0.3624 0.9547 1.0000 +#> +#> Residual standard error: 2.275 on 6 degrees of freedom +#> +#> Backtransformed parameters: +#> Confidence intervals for internally transformed parameters are asymmetric. +#> t-test (unrealistically) based on the assumption of normal distribution +#> for estimators of untransformed parameters. +#> Estimate t value Pr(>t) Lower Upper +#> parent_0 85.870 38.230 1.069e-08 80.3800 91.370 +#> alpha 1.053 6.231 3.953e-04 0.7112 1.560 +#> beta 1.917 3.570 5.895e-03 0.9661 3.806 +#> +#> Chi2 error levels in percent: +#> err.min n.optim df +#> All data 6.657 3 6 +#> parent 6.657 3 6 +#> +#> Estimated disappearance times: +#> DT50 DT90 DT50back +#> parent 1.785 15.15 4.56 +#> +#> Data: +#> time variable observed predicted residual +#> 0 parent 85.1 85.875 -0.7749 +#> 1 parent 57.9 55.191 2.7091 +#> 3 parent 29.9 31.845 -1.9452 +#> 7 parent 14.6 17.012 -2.4124 +#> 14 parent 9.7 9.241 0.4590 +#> 28 parent 6.6 4.754 1.8460 +#> 63 parent 4.0 2.102 1.8977 +#> 91 parent 3.9 1.441 2.4590 +#> 119 parent 0.6 1.092 -0.4919 +#>
+# 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"))
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 elapsed +#> 1.252 1.176 0.914 +#>
coef(fit)
#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink +#> 99.59848 -3.03822 -2.98030 -5.24750 +#>
endpoints(fit)
#> $ff +#> parent_sink parent_m1 m1_sink +#> 0.485524 0.514476 1.000000 +#> +#> $SFORB +#> logical(0) +#> +#> $distimes +#> DT50 DT90 +#> parent 7.022929 23.32967 +#> m1 131.760712 437.69961 +#> +#>
## Not run: ------------------------------------ +# # 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"))) +# coef(fit.deSolve) +# endpoints(fit.deSolve) +## --------------------------------------------- + +# Use stepwise fitting, using optimised parameters from parent only fit, FOMC +## Not run: ------------------------------------ +# FOMC_SFO <- mkinmod( +# parent = mkinsub("FOMC", "m1"), +# m1 = mkinsub("SFO")) +# # Fit the model to the FOCUS example dataset D using defaults +# fit.FOMC_SFO <- mkinfit(FOMC_SFO, FOCUS_2006_D) +# # Use starting parameters from parent only FOMC fit +# fit.FOMC = mkinfit("FOMC", FOCUS_2006_D, plot=TRUE) +# fit.FOMC_SFO <- mkinfit(FOMC_SFO, FOCUS_2006_D, +# parms.ini = fit.FOMC$bparms.ode, plot=TRUE) +# +# # 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")) +# # Fit the model to the FOCUS example dataset D using defaults +# fit.SFORB_SFO <- mkinfit(SFORB_SFO, FOCUS_2006_D) +# fit.SFORB_SFO.deSolve <- mkinfit(SFORB_SFO, FOCUS_2006_D, solution_type = "deSolve") +# # Use starting parameters from parent only SFORB fit (not really needed in this case) +# fit.SFORB = mkinfit("SFORB", FOCUS_2006_D) +# fit.SFORB_SFO <- mkinfit(SFORB_SFO, FOCUS_2006_D, parms.ini = fit.SFORB$bparms.ode) +## --------------------------------------------- + +## Not run: ------------------------------------ +# # Weighted fits, including IRLS +# SFO_SFO.ff <- mkinmod(parent = mkinsub("SFO", "m1"), +# m1 = mkinsub("SFO"), use_of_ff = "max") +# f.noweight <- mkinfit(SFO_SFO.ff, FOCUS_2006_D) +# summary(f.noweight) +# f.irls <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, reweight.method = "obs") +# summary(f.irls) +# f.w.mean <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, weight = "mean") +# summary(f.w.mean) +# f.w.value <- mkinfit(SFO_SFO.ff, subset(FOCUS_2006_D, value != 0), err = "value") +# summary(f.w.value) +## --------------------------------------------- + +## Not run: ------------------------------------ +# # 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") +# summary(f.w.man) +# f.w.man.irls <- mkinfit(SFO_SFO.ff, dw, err = "err.man", +# reweight.method = "obs") +# summary(f.w.man.irls) +## ---------------------------------------------
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinmod.html b/docs/reference/mkinmod.html new file mode 100644 index 00000000..9dd8fca0 --- /dev/null +++ b/docs/reference/mkinmod.html @@ -0,0 +1,206 @@ + + + + + + + + +mkinmod. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

The function usually takes several expressions, each assigning a compound name to + a list, specifying the kinetic model type and reaction or transfer to other + observed compartments. Instead of specifying several expressions, a list + of lists can be given in the speclist argument.

+ +

For the definition of model types and their parameters, the equations given + in the FOCUS and NAFTA guidance documents are used.

+ + +
mkinmod(..., use_of_ff = "min", speclist = NULL, quiet = FALSE, verbose = FALSE)
+ +

Arguments

+
+
...
+
+ For each observed variable, a list has to be specified as an argument, containing + at least a component type, specifying the type of kinetics to use + for the variable. Currently, single first order kinetics "SFO", + indeterminate order rate equation kinetics "IORE", or + single first order with reversible binding "SFORB" are implemented for all + variables, while + "FOMC", "DFOP" and "HS" can additionally be chosen for the first + variable which is assumed to be the source compartment. + Additionally, each component of the list can include a character vector to, + specifying names of variables to which a transfer is to be assumed in the + model. + If the argument use_of_ff is set to "min" (default) and the model for + the compartment is "SFO" or "SFORB", an additional component of the list + can be "sink=FALSE" effectively fixing the flux to sink to zero. +
+
use_of_ff
+
+ Specification of the use of formation fractions in the model equations and, if + applicable, the coefficient matrix. If "min", a minimum use of formation + fractions is made in order to avoid fitting the product of formation fractions + and rate constants. If "max", formation fractions are always used. +
+
speclist
+
+ The specification of the observed variables and their submodel types and + pathways can be given as a single list using this argument. Default is NULL. +
+
quiet
+
+ Should messages be suppressed? +
+
verbose
+
+ If TRUE, passed to cfunction if applicable to give + detailed information about the C function being built. +
+
+ +
+

Value

+ +

A list of class mkinmod for use with mkinfit, containing

+
+ +
+

Note

+ +

The IORE submodel is not well tested (yet). When using this model for metabolites, + you may want to read the second note in the help page to + mkinfit.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+

NAFTA Technical Working Group on Pesticides (not dated) Guidance for + Evaluating and Calculating Degradation Kinetics in Environmental + Media

+
+ +

Examples

+
# Specify the SFO model (this is not needed any more, as we can now mkinfit("SFO", ...) +SFO <- mkinmod(parent = list(type = "SFO")) + +# One parent compound, one metabolite, both single first order +SFO_SFO <- mkinmod( + parent = mkinsub("SFO", "m1"), + m1 = mkinsub("SFO"))
Successfully compiled differential equation model from auto-generated C code.
+## Not run: ------------------------------------ +# # The above model used to be specified like this, before the advent of mkinsub() +# SFO_SFO <- mkinmod( +# parent = list(type = "SFO", to = "m1"), +# m1 = list(type = "SFO")) +# +# # Show details of creating the C function +# SFO_SFO <- mkinmod( +# parent = mkinsub("SFO", "m1"), +# m1 = mkinsub("SFO"), verbose = TRUE) +# +# # If we have several parallel metabolites +# # (compare tests/testthat/test_synthetic_data_for_UBA_2014.R) +# m_synth_DFOP_par <- mkinmod(parent = mkinsub("DFOP", c("M1", "M2")), +# M1 = mkinsub("SFO"), +# M2 = mkinsub("SFO"), +# use_of_ff = "max", quiet = TRUE) +# +# fit_DFOP_par_c <- mkinfit(m_synth_DFOP_par, +# synthetic_data_for_UBA_2014[[12]]$data, +# quiet = TRUE) +## ---------------------------------------------
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinparplot.html b/docs/reference/mkinparplot.html new file mode 100644 index 00000000..f2fae22d --- /dev/null +++ b/docs/reference/mkinparplot.html @@ -0,0 +1,122 @@ + + + + + + + + +mkinparplot. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function plots the confidence intervals for the parameters + fitted using mkinfit.

+ + +
mkinparplot(object)
+ +

Arguments

+
+
object
+
+ A fit represented in an mkinfit object. +
+
+ +
+

Value

+ +

Nothing is returned by this function, as it is called for its side effect, namely to produce a plot.

+
+ +

Examples

+
model <- mkinmod( + T245 = list(type = "SFO", to = c("phenol"), sink = FALSE), + phenol = list(type = "SFO", to = c("anisole")), + anisole = list(type = "SFO"), use_of_ff = "max")
Successfully compiled differential equation model from auto-generated C code.
fit <- mkinfit(model, subset(mccall81_245T, soil == "Commerce"), quiet = TRUE) +mkinparplot(fit)
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinplot.html b/docs/reference/mkinplot.html new file mode 100644 index 00000000..51ca3992 --- /dev/null +++ b/docs/reference/mkinplot.html @@ -0,0 +1,118 @@ + + + + + + + + +mkinplot. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Deprecated function. It now only calls the plot method plot.mkinfit.

+ + +
mkinplot(fit, ...)
+ +

Arguments

+
+
fit
+
+ an object of class mkinfit. +
+
&#8230;
+
+ further arguments passed to plot.mkinfit. +
+
+ +
+

Value

+ +

The function is called for its side effect.

+
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinpredict.html b/docs/reference/mkinpredict.html new file mode 100644 index 00000000..730792c1 --- /dev/null +++ b/docs/reference/mkinpredict.html @@ -0,0 +1,318 @@ + + + + + + + + +mkinpredict. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function produces a time series for all the observed variables in a + kinetic model as specified by mkinmod, using a specific set of + kinetic parameters and initial values for the state variables.

+ + +
mkinpredict(mkinmod, odeparms, odeini, outtimes, solution_type = "deSolve",
+              use_compiled = "auto", method.ode = "lsoda", atol = 1e-08, rtol = 1e-10,
+        map_output = TRUE, ...)
+ +

Arguments

+
+
mkinmod
+
+ A kinetic model as produced by mkinmod. +
+
odeparms
+
+ A numeric vector specifying the parameters used in the kinetic model, which + is generally defined as a set of ordinary differential equations. +
+
odeini
+
+ A numeric vectory containing the initial values of the state variables of + the model. Note that the state variables can differ from the observed + variables, for example in the case of the SFORB model. +
+
outtimes
+
+ A numeric vector specifying the time points for which model predictions + should be generated. +
+
solution_type
+
+ The method that should be used for producing the predictions. This should + generally be "analytical" if there is only one observed variable, and + usually "deSolve" in the case of several observed variables. The third + possibility "eigen" is faster but not applicable to some models e.g. + using FOMC for the parent compound. +
+
method.ode
+
+ The solution method passed via mkinpredict to + ode in case the solution type is "deSolve". The default + "lsoda" is performant, but sometimes fails to converge. +
+
use_compiled
+
+ If set to FALSE, no compiled version of the mkinmod + model is used, even if is present. +
+
atol
+
+ Absolute error tolerance, passed to ode. Default is 1e-8, + lower than in lsoda. +
+
rtol
+
+ Absolute error tolerance, passed to ode. Default is 1e-10, + much lower than in lsoda. +
+
map_output
+
+ Boolean to specify if the output should list values for the observed + variables (default) or for all state variables (if set to FALSE). +
+
&#8230;
+
+ Further arguments passed to the ode solver in case such a solver is used. +
+
+ +
+

Value

+ +

A matrix in the same format as the output of ode.

+
+ +

Examples

+
SFO <- mkinmod(degradinol = list(type = "SFO")) + # Compare solution types + mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + solution_type = "analytical")
#> time degradinol +#> 1 0 100.0000000 +#> 2 1 74.0818221 +#> 3 2 54.8811636 +#> 4 3 40.6569660 +#> 5 4 30.1194212 +#> 6 5 22.3130160 +#> 7 6 16.5298888 +#> 8 7 12.2456428 +#> 9 8 9.0717953 +#> 10 9 6.7205513 +#> 11 10 4.9787068 +#> 12 11 3.6883167 +#> 13 12 2.7323722 +#> 14 13 2.0241911 +#> 15 14 1.4995577 +#> 16 15 1.1108997 +#> 17 16 0.8229747 +#> 18 17 0.6096747 +#> 19 18 0.4516581 +#> 20 19 0.3345965 +#> 21 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + solution_type = "deSolve")
#> time degradinol +#> 1 0 100.0000000 +#> 2 1 74.0818221 +#> 3 2 54.8811636 +#> 4 3 40.6569660 +#> 5 4 30.1194212 +#> 6 5 22.3130160 +#> 7 6 16.5298888 +#> 8 7 12.2456428 +#> 9 8 9.0717953 +#> 10 9 6.7205513 +#> 11 10 4.9787068 +#> 12 11 3.6883167 +#> 13 12 2.7323722 +#> 14 13 2.0241911 +#> 15 14 1.4995577 +#> 16 15 1.1108996 +#> 17 16 0.8229747 +#> 18 17 0.6096747 +#> 19 18 0.4516581 +#> 20 19 0.3345965 +#> 21 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + solution_type = "deSolve", use_compiled = FALSE)
#> time degradinol +#> 1 0 100.0000000 +#> 2 1 74.0818221 +#> 3 2 54.8811636 +#> 4 3 40.6569660 +#> 5 4 30.1194212 +#> 6 5 22.3130160 +#> 7 6 16.5298888 +#> 8 7 12.2456428 +#> 9 8 9.0717953 +#> 10 9 6.7205513 +#> 11 10 4.9787068 +#> 12 11 3.6883167 +#> 13 12 2.7323722 +#> 14 13 2.0241911 +#> 15 14 1.4995577 +#> 16 15 1.1108996 +#> 17 16 0.8229747 +#> 18 17 0.6096747 +#> 19 18 0.4516581 +#> 20 19 0.3345965 +#> 21 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + solution_type = "eigen")
#> time degradinol +#> 1 0 100.0000000 +#> 2 1 74.0818221 +#> 3 2 54.8811636 +#> 4 3 40.6569660 +#> 5 4 30.1194212 +#> 6 5 22.3130160 +#> 7 6 16.5298888 +#> 8 7 12.2456428 +#> 9 8 9.0717953 +#> 10 9 6.7205513 +#> 11 10 4.9787068 +#> 12 11 3.6883167 +#> 13 12 2.7323722 +#> 14 13 2.0241911 +#> 15 14 1.4995577 +#> 16 15 1.1108997 +#> 17 16 0.8229747 +#> 18 17 0.6096747 +#> 19 18 0.4516581 +#> 20 19 0.3345965 +#> 21 20 0.2478752 +#>
+ + # Compare integration methods to analytical solution + mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + solution_type = "analytical")[21,]
#> time degradinol +#> 21 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + method = "lsoda")[21,]
#> time degradinol +#> 21 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + method = "ode45")[21,]
#> time degradinol +#> 21 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), 0:20, + method = "rk4")[21,]
#> time degradinol +#> 21 20 0.2480043 +#>
# rk4 is not as precise here + + # The number of output times used to make a lot of difference until the + # default for atol was adjusted + mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), + seq(0, 20, by = 0.1))[201,]
#> time degradinol +#> 201 20 0.2478752 +#>
mkinpredict(SFO, c(k_degradinol_sink = 0.3), c(degradinol = 100), + seq(0, 20, by = 0.01))[2001,]
#> time degradinol +#> 2001 20 0.2478752 +#>
+ # Check compiled model versions - they are faster than the eigenvalue based solutions! + SFO_SFO = mkinmod(parent = list(type = "SFO", to = "m1"), + m1 = list(type = "SFO"))
Successfully compiled differential equation model from auto-generated C code.
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 = "eigen")[201,]))
#> time parent m1 +#> 201 20 4.978707 27.46227 +#>
#> user system elapsed +#> 0.000 0.028 0.004 +#>
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")[201,]))
#> time parent m1 +#> 201 20 4.978707 27.46227 +#>
#> user system elapsed +#> 0.016 0.004 0.002 +#>
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 elapsed +#> 0.036 0.000 0.035 +#>
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinresplot.html b/docs/reference/mkinresplot.html new file mode 100644 index 00000000..fb9ab40d --- /dev/null +++ b/docs/reference/mkinresplot.html @@ -0,0 +1,166 @@ + + + + + + + + +mkinresplot. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function plots the residuals for the specified subset of the + observed variables from an mkinfit object. A combined plot of the fitted + model and the residuals can be obtained using plot.mkinfit + using the argument show_residuals = TRUE.

+ + +
mkinresplot(object,
+    obs_vars = names(object$mkinmod$map),
+    xlim = c(0, 1.1 * max(object$data$time)),
+    xlab = "Time", ylab = "Residual",
+    maxabs = "auto", legend = TRUE, lpos = "topright", ...)
+ +

Arguments

+
+
object
+
+ A fit represented in an mkinfit object. +
+
obs_vars
+
+ A character vector of names of the observed variables for which residuals + should be plotted. Defaults to all observed variables in the model +
+
xlim
+
+ plot range in x direction. +
+
xlab
+
+ Label for the x axis. Defaults to "Time [days]". +
+
ylab
+
+ Label for the y axis. Defaults to "Residual [% of applied radioactivity]". +
+
maxabs
+
+ Maximum absolute value of the residuals. This is used for the scaling of + the y axis and defaults to "auto". +
+
legend
+
+ Should a legend be plotted? Defaults to "TRUE". +
+
lpos
+
+ Where should the legend be placed? Default is "topright". Will be passed on to + legend.
+
&#8230;
+
+ further arguments passed to plot. +
+
+ +
+

Value

+ +

Nothing is returned by this function, as it is called for its side effect, namely to produce a plot.

+
+ +
+

See also

+ +

mkinplot, for a way to plot the data and the fitted lines of the + mkinfit object.

+
+ +

Examples

+
model <- mkinmod(parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"))
Successfully compiled differential equation model from auto-generated C code.
fit <- mkinfit(model, FOCUS_2006_D, quiet = TRUE) +mkinresplot(fit, "m1")
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mkinsub.html b/docs/reference/mkinsub.html new file mode 100644 index 00000000..6b079c40 --- /dev/null +++ b/docs/reference/mkinsub.html @@ -0,0 +1,147 @@ + + + + + + + + +mkinsub. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This is a convenience function to set up the lists used as arguments for + mkinmod.

+ + +
mkinsub(submodel, to = NULL, sink = TRUE, full_name = NA)
+ +

Arguments

+
+
submodel
+
+ Character vector of length one to specify the submodel type. See + mkinmod for the list of allowed submodel names. +
+
to
+
+ Vector of the names of the state variable to which a transformation + shall be included in the model. +
+
sink
+
+ Should a pathway to sink be included in the model in addition to the + pathways to other state variables? +
+
full_name
+
+ An optional name to be used e.g. for plotting fits performed with the model. + You can use non-ASCII characters here, but then your R code will not be + portable, i.e. may produce unintended plot results on other + operating systems or system configurations. +
+
+ +
+

Value

+ +

A list for use with mkinmod.

+
+ +

Examples

+
# One parent compound, one metabolite, both single first order. +SFO_SFO <- mkinmod( + parent = list(type = "SFO", to = "m1"), + m1 = list(type = "SFO"))
Successfully compiled differential equation model from auto-generated C code.
+# The same model using mkinsub +SFO_SFO.2 <- mkinmod( + parent = mkinsub("SFO", "m1"), + m1 = mkinsub("SFO"))
Successfully compiled differential equation model from auto-generated C code.
+# Now supplying full names +SFO_SFO.2 <- mkinmod( + parent = mkinsub("SFO", "m1", full_name = "Test compound"), + m1 = mkinsub("SFO", full_name = "Metabolite M1"))
Successfully compiled differential equation model from auto-generated C code.
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/mmkin.html b/docs/reference/mmkin.html new file mode 100644 index 00000000..5b624893 --- /dev/null +++ b/docs/reference/mmkin.html @@ -0,0 +1,178 @@ + + + + + + + + +mmkin. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This function calls mkinfit on all combinations of models and datasets + specified in its first two arguments.

+ + +
mmkin(models, datasets,
+      cores = round(detectCores()/2), cluster = NULL, ...)
+ +

Arguments

+
+
models
+
+ Either a character vector of shorthand names ("SFO", "FOMC", "DFOP", + "HS", "SFORB"), or an optionally named list of mkinmod + objects. +
+
datasets
+
+ An optionally named list of datasets suitable as observed data for + mkinfit. +
+
cores
+
+ The number of cores to be used for multicore processing. This is only + used when the cluster argument is NULL. +
+
cluster
+
+ A cluster as returned by makeCluster to be used for parallel + execution. +
+
&#8230;
+
+ Further arguments that will be passed to mkinfit. +
+
+ +
+

Value

+ +

A matrix of mkinfit objects that can be indexed using the model + and dataset names as row and column indices.

+
+ +
+

See also

+ +

[.mmkin for subsetting, plot.mmkin for plotting.

+
+ +

Examples

+
## Not run: ------------------------------------ +# m_synth_SFO_lin <- mkinmod(parent = mkinsub("SFO", "M1"), +# M1 = mkinsub("SFO", "M2"), +# M2 = mkinsub("SFO"), use_of_ff = "max") +# +# m_synth_FOMC_lin <- mkinmod(parent = mkinsub("FOMC", "M1"), +# M1 = mkinsub("SFO", "M2"), +# M2 = mkinsub("SFO"), use_of_ff = "max") +# +# models <- list(SFO_lin = m_synth_SFO_lin, FOMC_lin = m_synth_FOMC_lin) +# datasets <- lapply(synthetic_data_for_UBA_2014[1:3], function(x) x$data) +# names(datasets) <- paste("Dataset", 1:3) +# +# time_default <- system.time(fits.0 <- mmkin(models, datasets)) +# time_1 <- system.time(fits.1 <- mmkin(models, datasets, cores = 1)) +# +# time_default +# time_1 +# +# endpoints(fits[["SFO_lin", 2]]) +# +# # Plot.mkinfit handles rows or columns of mmkin result objects +# plot(fits.0[1, ]) +# plot(fits.0[1, ], obs_var = c("M1", "M2")) +# plot(fits.0[, 1]) +# # Use double brackets to extract a single mkinfit object, which will be plotted +# # by plot.mkinfit +# plot(fits.0[[1, 1]], sep_obs = TRUE, show_residuals = TRUE, show_errmin = TRUE) +# # Plotting with mmkin (single brackets, extracting an mmkin object) does not +# # allow to plot the observed variables separately +# plot(fits.0[1, 1]) +## ---------------------------------------------
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/plot.mkinfit.html b/docs/reference/plot.mkinfit.html new file mode 100644 index 00000000..94aebf63 --- /dev/null +++ b/docs/reference/plot.mkinfit.html @@ -0,0 +1,231 @@ + + + + + + + + +plot.mkinfit. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Solves the differential equations with the optimised and fixed parameters + from a previous successful call to mkinfit and plots + the observed data together with the solution of the fitted model.

+ + +
# S3 method for mkinfit
+plot(x, fit = x,
+  obs_vars = names(fit$mkinmod$map),
+  xlab = "Time", ylab = "Observed", 
+  xlim = range(fit$data$time),
+  ylim = "default",
+  col_obs = 1:length(obs_vars), pch_obs = col_obs, 
+  lty_obs = rep(1, length(obs_vars)),
+  add = FALSE, legend = !add,
+  show_residuals = FALSE, maxabs = "auto",
+  sep_obs = FALSE, rel.height.middle = 0.9,
+  lpos = "topright", inset = c(0.05, 0.05), 
+  show_errmin = FALSE, errmin_digits = 3, …)
+plot_sep(fit, sep_obs = TRUE,  show_residuals = TRUE, show_errmin = TRUE, …)
+ +

Arguments

+
+
x
+
+ Alias for fit introduced for compatibility with the generic S3 method. +
+
fit
+
+ An object of class mkinfit. +
+
obs_vars
+
+ A character vector of names of the observed variables for which the + data and the model should be plotted. Defauls to all observed variables + in the model. +
+
xlab
+
+ Label for the x axis. +
+
ylab
+
+ Label for the y axis. +
+
xlim
+
+ Plot range in x direction. +
+
ylim
+
+ Plot range in y direction. +
+
col_obs
+
+ Colors used for plotting the observed data and the corresponding model prediction lines. +
+
pch_obs
+
+ Symbols to be used for plotting the data. +
+
lty_obs
+
+ Line types to be used for the model predictions. +
+
add
+
+ Should the plot be added to an existing plot? +
+
legend
+
+ Should a legend be added to the plot? +
+
show_residuals
+
+ Should residuals be shown? If only one plot of the fits is shown, the + residual plot is in the lower third of the plot? Otherwise, i.e. if + "sep_obs" is given, the residual plots will be located to the right of + the plots of the fitted curves. +
+
maxabs
+
+ Maximum absolute value of the residuals. This is used for the scaling of + the y axis and defaults to "auto". +
+
sep_obs
+
+ Should the observed variables be shown in separate subplots? If yes, residual plots + requested by "show_residuals" will be shown next to, not below the plot of the fits. +
+
rel.height.middle
+
+ The relative height of the middle plot, if more than two rows of plots are shown. +
+
lpos
+
+ Position(s) of the legend(s). Passed to legend as the first argument. + If not length one, this should be of the same length as the obs_var argument. +
+
inset
+
+ Passed to legend if applicable. +
+
show_errmin
+
+ Should the FOCUS chi2 error value be shown in the upper margin of the plot? +
+
errmin_digits
+
+ The number of significant digits for rounding the FOCUS chi2 error percentage. +
+
&#8230;
+
+ Further arguments passed to plot. +
+
+ +
+

Value

+ +

The function is called for its side effect.

+
+ +

Examples

+
# One parent compound, one metabolite, both single first order, path from +# parent to sink included, use Levenberg-Marquardt for speed +SFO_SFO <- mkinmod(parent = mkinsub("SFO", "m1", full = "Parent"), + m1 = mkinsub("SFO", full = "Metabolite M1" ))
Successfully compiled differential equation model from auto-generated C code.
fit <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE, method.modFit = "Marq") +plot(fit)
plot(fit, show_residuals = TRUE)
+# Show the observed variables separately +plot(fit, sep_obs = TRUE, lpos = c("topright", "bottomright"))
+# Show the observed variables separately, with residuals +plot(fit, sep_obs = TRUE, show_residuals = TRUE, lpos = c("topright", "bottomright"), + show_errmin = TRUE)
+# The same can be obtained with less typing, using the convenience function plot_sep +plot_sep(fit, lpos = c("topright", "bottomright"))
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/plot.mmkin.html b/docs/reference/plot.mmkin.html new file mode 100644 index 00000000..358da679 --- /dev/null +++ b/docs/reference/plot.mmkin.html @@ -0,0 +1,156 @@ + + + + + + + + +plot.mmkin. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

When x is a row selected from an mmkin object ([.mmkin), the same model + fitted for at least one dataset is shown. When it is a column, the fit of at least one model + to the same dataset is shown.

+ + +
# S3 method for mmkin
+plot(x, main = "auto", legends = 1, errmin_var = "All data", errmin_digits = 3,
+              cex = 0.7, rel.height.middle = 0.9, ...)
+ +

Arguments

+
+
x
+
+ An object of class mmkin, with either one row or one column. +
+
main
+
+ The main title placed on the outer margin of the plot. +
+
legends
+
+ An index for the fits for which legends should be shown. +
+
errmin_var
+
+ The variable for which the FOCUS chi2 error value should be shown. +
+
errmin_digits
+
+ The number of significant digits for rounding the FOCUS chi2 error percentage. +
+
cex
+
+ Passed to the plot functions and mtext. +
+
rel.height.middle
+
+ The relative height of the middle plot, if more than two rows of plots are shown. +
+
&#8230;
+
+ Further arguments passed to plot.mkinfit and mkinresplot. +
+
+ +
+

Value

+ +

The function is called for its side effect.

+
+ +

Examples

+
# Only use one core not to offend CRAN checks, use Levenberg-Marquardt for speed + fits <- mmkin(c("FOMC", "HS"), list("FOCUS B" = FOCUS_2006_B, "FOCUS C" = FOCUS_2006_C), + cores = 1, quiet = TRUE, method.modFit = "Marq") + plot(fits[, "FOCUS C"])
plot(fits["FOMC", ])
+ # We can also plot a single fit, if we like the way mmkin works, but then the plot + # height should be smaller than the plot width (this is not possible for the html pages + # generated by staticdocs, as far as I know). + plot(fits["FOMC", "FOCUS C"]) # same as plot(fits[1, 2])
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/print.mkinds.html b/docs/reference/print.mkinds.html new file mode 100644 index 00000000..dea5f75c --- /dev/null +++ b/docs/reference/print.mkinds.html @@ -0,0 +1,109 @@ + + + + + + + + +print.mkinds. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Print mkinds objects.

+ + +
# S3 method for mkinds
+print(x, ...)
+ +

Arguments

+
+
x
+
+ An mkinds object. +
+
&#8230;
+
+ Not used. +
+
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/print.mkinmod.html b/docs/reference/print.mkinmod.html new file mode 100644 index 00000000..38663f8f --- /dev/null +++ b/docs/reference/print.mkinmod.html @@ -0,0 +1,109 @@ + + + + + + + + +print.mkinmod. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Print mkinmod objects in a way that the user finds his way to get to its components.

+ + +
# S3 method for mkinmod
+print(x, ...)
+ +

Arguments

+
+
x
+
+ An mkinmod object. +
+
&#8230;
+
+ Not used. +
+
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/schaefer07_complex_case.html b/docs/reference/schaefer07_complex_case.html new file mode 100644 index 00000000..12776c74 --- /dev/null +++ b/docs/reference/schaefer07_complex_case.html @@ -0,0 +1,131 @@ + + + + + + + + +schaefer07_complex_case. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

This dataset was used for a comparison of KinGUI and ModelMaker to check the + software quality of KinGUI in the original publication (Schäfer et al., 2007). + The results from the fitting are also included.

+ + +
data(schaefer07_complex_case)
+ +
+

Format

+ +

The data set is a data frame with 8 observations on the following 6 variables. +

+
time
a numeric vector
+
parent
a numeric vector
+
A1
a numeric vector
+
B1
a numeric vector
+
C1
a numeric vector
+
A2
a numeric vector
+

+

The results are a data frame with 14 results for different parameter values

+
+ +
+

References

+ +

Schäfer D, Mikolasch B, Rainbird P and Harvey B (2007). KinGUI: a new kinetic + software tool for evaluations according to FOCUS degradation kinetics. In: Del + Re AAM, Capri E, Fragoulis G and Trevisan M (Eds.). Proceedings of the XIII + Symposium Pesticide Chemistry, Piacenza, 2007, p. 916-923.

+
+ +

Examples

+
data <- mkin_wide_to_long(schaefer07_complex_case, time = "time") +model <- mkinmod( + parent = list(type = "SFO", to = c("A1", "B1", "C1"), sink = FALSE), + A1 = list(type = "SFO", to = "A2"), + B1 = list(type = "SFO"), + C1 = list(type = "SFO"), + A2 = list(type = "SFO"), use_of_ff = "max")
Successfully compiled differential equation model from auto-generated C code.
## Not run: mkinfit(model, data, plot=TRUE)
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/summary.mkinfit.html b/docs/reference/summary.mkinfit.html new file mode 100644 index 00000000..e0cdfe23 --- /dev/null +++ b/docs/reference/summary.mkinfit.html @@ -0,0 +1,229 @@ + + + + + + + + +summary.mkinfit. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

Lists model equations, the summary as returned by summary.modFit, + the chi2 error levels calculated according to FOCUS guidance (2006) as far + as defined therein, and optionally the data, consisting of observed, predicted + and residual values.

+ + +
# S3 method for mkinfit
+summary(object, data = TRUE, distimes = TRUE, alpha = 0.05, ...)
+# S3 method for summary.mkinfit
+print(x, digits = max(3, getOption("digits") - 3), ...)
+ +

Arguments

+
+
object
+
+ an object of class mkinfit. +
+
x
+
+ an object of class summary.mkinfit. +
+
data
+
+ logical, indicating whether the data should be included in the summary. +
+
distimes
+
+ logical, indicating whether DT50 and DT90 values should be included. +
+
alpha
+
+ error level for confidence interval estimation from t distribution +
+
digits
+
+ Number of digits to use for printing +
+
&#8230;
+
+ optional arguments passed to methods like print. +
+
+ +
+

Value

+ +

The summary function returns a list derived from + summary.modFit, with components, among others

+

The print method is called for its side effect, i.e. printing the summary.

+
+ +
+

References

+ +

FOCUS (2006) “Guidance Document on Estimating Persistence and + Degradation Kinetics from Environmental Fate Studies on Pesticides in EU + Registration” Report of the FOCUS Work Group on Degradation Kinetics, + EC Document Reference Sanco/10058/2005 version 2.0, 434 pp, + http://focus.jrc.ec.europa.eu/dk

+
+ +

Examples

+
summary(mkinfit(mkinmod(parent = list(type = "SFO")), FOCUS_2006_A, quiet = TRUE))
#> mkin version: 0.9.44.9000 +#> R version: 3.3.1 +#> Date of fit: Thu Oct 6 09:18:07 2016 +#> Date of summary: Thu Oct 6 09:18:07 2016 +#> +#> Equations: +#> d_parent = - k_parent_sink * parent +#> +#> Model predictions using solution type analytical +#> +#> Fitted with method Port using 35 model solutions performed in 0.079 s +#> +#> Weighting: none +#> +#> Starting values for parameters to be optimised: +#> value type +#> parent_0 101.24 state +#> k_parent_sink 0.10 deparm +#> +#> Starting values for the transformed parameters actually optimised: +#> value lower upper +#> parent_0 101.240000 -Inf Inf +#> log_k_parent_sink -2.302585 -Inf Inf +#> +#> Fixed parameter values: +#> None +#> +#> Optimised, transformed parameters with symmetric confidence intervals: +#> Estimate Std. Error Lower Upper +#> parent_0 109.200 4.3910 98.410 119.900 +#> log_k_parent_sink -3.291 0.1152 -3.573 -3.009 +#> +#> Parameter correlation: +#> parent_0 log_k_parent_sink +#> parent_0 1.000 0.575 +#> log_k_parent_sink 0.575 1.000 +#> +#> Residual standard error: 6.08 on 6 degrees of freedom +#> +#> Backtransformed parameters: +#> Confidence intervals for internally transformed parameters are asymmetric. +#> t-test (unrealistically) based on the assumption of normal distribution +#> for estimators of untransformed parameters. +#> Estimate t value Pr(>t) Lower Upper +#> parent_0 109.20000 24.860 1.394e-07 98.41000 119.90000 +#> k_parent_sink 0.03722 8.679 6.457e-05 0.02807 0.04934 +#> +#> Chi2 error levels in percent: +#> err.min n.optim df +#> All data 8.385 2 6 +#> parent 8.385 2 6 +#> +#> Resulting formation fractions: +#> ff +#> parent_sink 1 +#> +#> Estimated disappearance times: +#> DT50 DT90 +#> parent 18.62 61.87 +#> +#> Data: +#> time variable observed predicted residual +#> 0 parent 101.24 109.153 -7.9132 +#> 3 parent 99.27 97.622 1.6484 +#> 7 parent 90.11 84.119 5.9913 +#> 14 parent 72.19 64.826 7.3641 +#> 30 parent 29.71 35.738 -6.0283 +#> 62 parent 5.98 10.862 -4.8818 +#> 90 parent 1.54 3.831 -2.2911 +#> 118 parent 0.39 1.351 -0.9613 +#>
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/synthetic_data_for_UBA.html b/docs/reference/synthetic_data_for_UBA.html new file mode 100644 index 00000000..04550199 --- /dev/null +++ b/docs/reference/synthetic_data_for_UBA.html @@ -0,0 +1,157 @@ + + + + + + + + +synthetic_data_for_UBA_2014. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

The 12 datasets were generated using four different models and three different + variance components. The four models are either the SFO or the DFOP model with either + two sequential or two parallel metabolites.

+ +

Variance component 'a' is based on a normal distribution with standard deviation of 3, + Variance component 'b' is also based on a normal distribution, but with a standard deviation of 7. + Variance component 'c' is based on the error model from Rocke and Lorenzato (1995), with the + minimum standard deviation (for small y values) of 0.5, and a proportionality constant of 0.07 + for the increase of the standard deviation with y.

+ +

Initial concentrations for metabolites and all values where adding the variance component resulted + in a value below the assumed limit of detection of 0.1 were set to NA.

+ +

As an example, the first dataset has the title SFO_lin_a and is based on the SFO model + with two sequential metabolites (linear pathway), with added variance component 'a'.

+ +

Compare also the code in the example section to see the degradation models.

+ + +
synthetic_data_for_UBA_2014
+ +
+

Format

+ +

A list containing datasets in the form internally used by the 'gmkin' package. + The list has twelfe components. Each of the components is one dataset that has, + among others, the following components +

+
title
The name of the dataset, e.g. SFO_lin_a
+
data
A data frame with the data in the form expected by mkinfit
+

+
+ +
+

Source

+ +

Ranke (2014) Prüfung und Validierung von Modellierungssoftware als Alternative + zu ModelMaker 4.0, Umweltbundesamt Projektnummer 27452

+

Rocke, David M. und Lorenzato, Stefan (1995) A two-component model for + measurement error in analytical chemistry. Technometrics 37(2), 176-184.

+
+ +

Examples

+
## Not run: ------------------------------------ +# m_synth_SFO_lin <- mkinmod(parent = list(type = "SFO", to = "M1"), +# M1 = list(type = "SFO", to = "M2"), +# M2 = list(type = "SFO"), use_of_ff = "max") +# +# +# m_synth_SFO_par <- mkinmod(parent = list(type = "SFO", to = c("M1", "M2"), +# sink = FALSE), +# M1 = list(type = "SFO"), +# M2 = list(type = "SFO"), use_of_ff = "max") +# +# m_synth_DFOP_lin <- mkinmod(parent = list(type = "DFOP", to = "M1"), +# M1 = list(type = "SFO", to = "M2"), +# M2 = list(type = "SFO"), use_of_ff = "max") +# +# m_synth_DFOP_par <- mkinmod(parent = list(type = "DFOP", to = c("M1", "M2"), +# sink = FALSE), +# M1 = list(type = "SFO"), +# M2 = list(type = "SFO"), use_of_ff = "max") +# +# mkinfit(m_synth_SFO_lin, synthetic_data_for_UBA_2014[[1]]$data) +## ---------------------------------------------
+
+
+
+
+ + +
+ + + diff --git a/docs/reference/transform_odeparms.html b/docs/reference/transform_odeparms.html new file mode 100644 index 00000000..3b8be856 --- /dev/null +++ b/docs/reference/transform_odeparms.html @@ -0,0 +1,276 @@ + + + + + + + + +transform_odeparms. mkin + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ + + +
+
+ +

The transformations are intended to map parameters that should only take + on restricted values to the full scale of real numbers. For kinetic rate + constants and other paramters that can only take on positive values, a + simple log transformation is used. For compositional parameters, such as + the formations fractions that should always sum up to 1 and can not be + negative, the ilr transformation is used.

+ +

The transformation of sets of formation fractions is fragile, as it supposes + the same ordering of the components in forward and backward transformation. + This is no problem for the internal use in mkinfit.

+ + +
transform_odeparms(parms, mkinmod,
+                   transform_rates = TRUE, transform_fractions = TRUE)
+backtransform_odeparms(transparms, mkinmod,
+                       transform_rates = TRUE, transform_fractions = TRUE)
+ +

Arguments

+
+
parms
+
+ Parameters of kinetic models as used in the differential equations. +
+
transparms
+
+ Transformed parameters of kinetic models as used in the fitting procedure. +
+
mkinmod
+
+ The kinetic model of class mkinmod, containing the names of + the model variables that are needed for grouping the formation fractions + before ilr transformation, the parameter names and + the information if the pathway to sink is included in the model. +
+
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. +
+
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. 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 ilr + transformation. +
+
+ +
+

Value

+ +

A vector of transformed or backtransformed parameters with the same names + as the original parameters.

+
+ +

Examples

+
SFO_SFO <- mkinmod( + parent = list(type = "SFO", to = "m1", sink = TRUE), + m1 = list(type = "SFO"))
Successfully compiled differential equation model from auto-generated C code.
# Fit the model to the FOCUS example dataset D using defaults +fit <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE) +summary(fit, data=FALSE) # See transformed and backtransformed parameters
#> mkin version: 0.9.44.9000 +#> R version: 3.3.1 +#> Date of fit: Thu Oct 6 09:18:08 2016 +#> Date of summary: Thu Oct 6 09:18:08 2016 +#> +#> Equations: +#> d_parent = - k_parent_sink * parent - k_parent_m1 * parent +#> d_m1 = + k_parent_m1 * parent - k_m1_sink * m1 +#> +#> Model predictions using solution type deSolve +#> +#> Fitted with method Port using 153 model solutions performed in 0.636 s +#> +#> Weighting: none +#> +#> Starting values for parameters to be optimised: +#> value type +#> parent_0 100.7500 state +#> k_parent_sink 0.1000 deparm +#> k_parent_m1 0.1001 deparm +#> k_m1_sink 0.1002 deparm +#> +#> Starting values for the transformed parameters actually optimised: +#> value lower upper +#> parent_0 100.750000 -Inf Inf +#> log_k_parent_sink -2.302585 -Inf Inf +#> log_k_parent_m1 -2.301586 -Inf Inf +#> log_k_m1_sink -2.300587 -Inf Inf +#> +#> Fixed parameter values: +#> value type +#> m1_0 0 state +#> +#> Optimised, transformed parameters with symmetric confidence intervals: +#> Estimate Std. Error Lower Upper +#> parent_0 99.600 1.61400 96.330 102.900 +#> log_k_parent_sink -3.038 0.07826 -3.197 -2.879 +#> log_k_parent_m1 -2.980 0.04124 -3.064 -2.897 +#> log_k_m1_sink -5.248 0.13610 -5.523 -4.972 +#> +#> Parameter correlation: +#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink +#> parent_0 1.00000 0.6075 -0.06625 -0.1701 +#> log_k_parent_sink 0.60752 1.0000 -0.08740 -0.6253 +#> log_k_parent_m1 -0.06625 -0.0874 1.00000 0.4716 +#> log_k_m1_sink -0.17006 -0.6253 0.47163 1.0000 +#> +#> Residual standard error: 3.211 on 36 degrees of freedom +#> +#> Backtransformed parameters: +#> Confidence intervals for internally transformed parameters are asymmetric. +#> t-test (unrealistically) based on the assumption of normal distribution +#> for estimators of untransformed parameters. +#> Estimate t value Pr(>t) Lower Upper +#> parent_0 99.600000 61.720 2.024e-38 96.330000 1.029e+02 +#> k_parent_sink 0.047920 12.780 3.050e-15 0.040890 5.616e-02 +#> k_parent_m1 0.050780 24.250 3.407e-24 0.046700 5.521e-02 +#> k_m1_sink 0.005261 7.349 5.758e-09 0.003992 6.933e-03 +#> +#> Chi2 error levels in percent: +#> err.min n.optim df +#> All data 6.398 4 15 +#> parent 6.827 3 6 +#> m1 4.490 1 9 +#> +#> Resulting formation fractions: +#> ff +#> parent_sink 0.4855 +#> parent_m1 0.5145 +#> m1_sink 1.0000 +#> +#> Estimated disappearance times: +#> DT50 DT90 +#> parent 7.023 23.33 +#> m1 131.761 437.70 +#>
+## Not run: ------------------------------------ +# fit.2 <- mkinfit(SFO_SFO, FOCUS_2006_D, transform_rates = FALSE) +# summary(fit.2, data=FALSE) +## --------------------------------------------- + +initials <- fit$start$value +names(initials) <- rownames(fit$start) +transformed <- fit$start_transformed$value +names(transformed) <- rownames(fit$start_transformed) +transform_odeparms(initials, SFO_SFO)
#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink +#> 100.750000 -2.302585 -2.301586 -2.300587 +#>
backtransform_odeparms(transformed, SFO_SFO)
#> parent_0 k_parent_sink k_parent_m1 k_m1_sink +#> 100.7500 0.1000 0.1001 0.1002 +#>
+## Not run: ------------------------------------ +# # The case of formation fractions +# SFO_SFO.ff <- mkinmod( +# parent = list(type = "SFO", to = "m1", sink = TRUE), +# m1 = list(type = "SFO"), +# use_of_ff = "max") +# +# fit.ff <- mkinfit(SFO_SFO.ff, FOCUS_2006_D) +# summary(fit.ff, data = FALSE) +# initials <- c("f_parent_to_m1" = 0.5) +# transformed <- transform_odeparms(initials, SFO_SFO.ff) +# backtransform_odeparms(transformed, SFO_SFO.ff) +# +# # And without sink +# SFO_SFO.ff.2 <- mkinmod( +# parent = list(type = "SFO", to = "m1", sink = FALSE), +# m1 = list(type = "SFO"), +# use_of_ff = "max") +# +# +# fit.ff.2 <- mkinfit(SFO_SFO.ff.2, FOCUS_2006_D) +# summary(fit.ff.2, data = FALSE) +## ---------------------------------------------
+
+
+

Author

+ + Johannes Ranke + +
+
+ + +
+ + + diff --git a/docs/reference/unknown-10.png b/docs/reference/unknown-10.png new file mode 100644 index 00000000..09bb687c Binary files /dev/null and b/docs/reference/unknown-10.png differ diff --git a/docs/reference/unknown-2.png b/docs/reference/unknown-2.png new file mode 100644 index 00000000..a26e413f Binary files /dev/null and b/docs/reference/unknown-2.png differ diff --git a/docs/reference/unknown-4.png b/docs/reference/unknown-4.png new file mode 100644 index 00000000..f23ed172 Binary files /dev/null and b/docs/reference/unknown-4.png differ diff --git a/docs/reference/unknown-6.png b/docs/reference/unknown-6.png new file mode 100644 index 00000000..dc24d92f Binary files /dev/null and b/docs/reference/unknown-6.png differ diff --git a/docs/reference/unknown-8.png b/docs/reference/unknown-8.png new file mode 100644 index 00000000..e4ab674a Binary files /dev/null and b/docs/reference/unknown-8.png differ -- cgit v1.2.1