From dd6c4a8f895fd470345e7ae773299daaa4de7aef Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 22 Feb 2019 20:51:13 +0100 Subject: Implement the NAFTA evaluation scheme --- NAMESPACE | 16 +- NEWS.md | 4 +- R/nafta.R | 105 ++++++++++++ data/NAFTA_2015.rda | Bin 0 -> 264 bytes docs/articles/FOCUS_D.html | 6 +- docs/articles/FOCUS_L.html | 42 ++--- docs/articles/web_only/compiled_models.html | 12 +- docs/news/index.html | 7 +- docs/reference/Extract.mmkin.html | 12 +- docs/reference/NAFTA_2015_datasets-1.png | Bin 0 -> 41450 bytes docs/reference/NAFTA_2015_datasets.html | 213 +++++++++++++++++++++++++ docs/reference/mccall81_245T.html | 12 +- docs/reference/mkinfit.html | 46 +++--- docs/reference/mkinmod.html | 2 +- docs/reference/mkinpredict.html | 6 +- docs/reference/mmkin.html | 4 +- docs/reference/nafta-1.png | Bin 0 -> 41450 bytes docs/reference/nafta.html | 239 ++++++++++++++++++++++++++++ docs/reference/plot.nafta.html | 190 ++++++++++++++++++++++ docs/reference/print.nafta.html | 178 +++++++++++++++++++++ docs/reference/summary.mkinfit.html | 6 +- docs/reference/transform_odeparms.html | 24 +-- man/NAFTA_2015_datasets.Rd | 35 ++++ man/nafta.Rd | 48 ++++++ man/plot.nafta.Rd | 31 ++++ man/print.nafta.Rd | 22 +++ tests/testthat/test_nafta.R | 41 +++++ 27 files changed, 1207 insertions(+), 94 deletions(-) create mode 100644 R/nafta.R create mode 100644 data/NAFTA_2015.rda create mode 100644 docs/reference/NAFTA_2015_datasets-1.png create mode 100644 docs/reference/NAFTA_2015_datasets.html create mode 100644 docs/reference/nafta-1.png create mode 100644 docs/reference/nafta.html create mode 100644 docs/reference/plot.nafta.html create mode 100644 docs/reference/print.nafta.html create mode 100644 man/NAFTA_2015_datasets.Rd create mode 100644 man/nafta.Rd create mode 100644 man/plot.nafta.Rd create mode 100644 man/print.nafta.Rd create mode 100644 tests/testthat/test_nafta.R diff --git a/NAMESPACE b/NAMESPACE index fc812f46..6ca41a43 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,26 +1,34 @@ -# Export all names +# Export all names except for those starting with a dot exportPattern("^[^\\.]") -S3method(print, mkinds) + S3method(print, mkinmod) +S3method(print, mkinds) +S3method(print, nafta) + S3method(plot, mkinfit) +S3method(plot, mmkin) +S3method(plot, nafta) + S3method(summary, mkinfit) S3method(print, summary.mkinfit) + S3method(logLik, mkinfit) -S3method(plot, mmkin) S3method("[", mmkin) S3method(AIC, mmkin) + S3method(mkinpredict, mkinmod) S3method(mkinpredict, mkinfit) import( stats, - graphics, + graphics, FME, minpack.lm, rootSolve, inline, parallel ) + importFrom(deSolve, ode) importFrom(methods, signature) importFrom(R6, R6Class) diff --git a/NEWS.md b/NEWS.md index 408eddda..36867dd6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# mkin 0.9.48.1 (2019-02-21) +# mkin 0.9.48.1 (2019-02-22) - Add the function 'logLik.mkinfit' which makes it possible to calculate an AIC for mkinfit objects @@ -18,6 +18,8 @@ - Implement the logistic model (only tested for parent fits) +- 'nafta': Add evaluations according to the NAFTA guidance + # mkin 0.9.47.5 (2018-09-14) - Make the two-component error model stop in cases where it is inadequate to avoid nls crashes on windows diff --git a/R/nafta.R b/R/nafta.R new file mode 100644 index 00000000..102a9ad6 --- /dev/null +++ b/R/nafta.R @@ -0,0 +1,105 @@ +# Copyright (C) 2019 Johannes Ranke +# Contact: jranke@uni-bremen.de + +# This file is part of the R package mkin + +# mkin is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +nafta <- function(ds, title = NA, quiet = FALSE) { + if (length(levels(ds$name)) > 1) { + stop("The NAFTA procedure is only defined for decline data for a single compound") + } + n <- nrow(subset(ds, !is.na(value))) + models <- c("SFO", "IORE", "DFOP") + + result <- list(title = title, data = ds) + result$mmkin <- mmkin(models, list(ds), quiet = TRUE) + + distimes <- lapply(result$mmkin, function(x) as.numeric(endpoints(x)$distimes["parent", ])) + + result$distimes <- matrix(NA, nrow = 3, ncol = 3, + dimnames = list(models, c("DT50", "DT90", "DT50_rep"))) + result$distimes["SFO", ] <- distimes[[1]][c(1, 2, 1)] + result$distimes["IORE", ] <- distimes[[2]][c(1, 2, 3)] + result$distimes["DFOP", ] <- distimes[[3]][c(1, 2, 4)] + + # Get parameters with statistics + result$parameters <- lapply(result$mmkin, function(x) { + summary(x)$bpar[, c(1, 4:6)] + }) + names(result$parameters) <- models + + # Compare the sum of squared residuals (SSR) to the upper bound of the + # confidence region of the SSR for the IORE model + result$S <- sapply(result$mmkin, function(x) x$ssr) + names(result$S) <- models + # Equation (3) on p. 3 + p <- 3 + result$S["IORE"] + result$S_c <- result$S[["IORE"]] * (1 + p/(n - p) * qf(0.5, p, n - p)) + + result$t_rep <- .evaluate_nafta_results(result$S, result$S_c, + result$distimes, quiet = quiet) + + class(result) <- "nafta" + return(result) +} + +plot.nafta <- function(x, legend = FALSE, main = "auto", ...) { + if (main == "auto") { + if (is.na(x$title)) main = "" + else main = x$title + } + plot(x$mmkin, ..., legend = legend, main = main) +} + +print.nafta <- function(x, quiet = TRUE, ...) { + cat("Parameters:\n") + print(x$parameters) + t_rep <- .evaluate_nafta_results(x$S, x$S_c, x$distimes, quiet = quiet) + cat("\nDTx values:\n") + print(round((x$distimes), digits = 0)) + cat("\nRepresentative half-life:\n") + print(t_rep) +} + +.evaluate_nafta_results <- function(S, S_c, distimes, quiet = FALSE) { + t_SFO <- distimes["IORE", "DT50"] + t_IORE <- distimes["IORE", "DT50_rep"] + t_DFOP2 <- distimes["DFOP", "DT50_rep"] + + if (S["SFO"] < S_c) { + if (!quiet) { + message("S_SFO is lower than the critical value S_c, use the SFO model") + } + t_rep <- t_SFO + } else { + if (!quiet) { + message("The SFO model is rejected as S_SFO is equal or higher than the critical value S_c") + } + if (t_IORE < t_DFOP2) { + if (!quiet) { + message("The half-life obtained from the IORE model may be used") + } + t_rep <- t_IORE + } else { + if (!quiet) { + message("The representative half-life of the IORE model is longer than the one corresponding to the terminal degradation rate found with the DFOP model.") + message("The reprentative half-life obtained from the DFOP model may be used") + } + t_rep <- t_DFOP2 + } + } + return(t_rep) +} diff --git a/data/NAFTA_2015.rda b/data/NAFTA_2015.rda new file mode 100644 index 00000000..48183048 Binary files /dev/null and b/data/NAFTA_2015.rda differ diff --git a/docs/articles/FOCUS_D.html b/docs/articles/FOCUS_D.html index 38e59d9d..ad8413dc 100644 --- a/docs/articles/FOCUS_D.html +++ b/docs/articles/FOCUS_D.html @@ -163,8 +163,8 @@
summary(fit)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:20 2019 
-## Date of summary: Fri Feb 22 09:51:21 2019 
+## Date of fit:     Fri Feb 22 20:48:30 2019 
+## Date of summary: Fri Feb 22 20:48:31 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent_sink * parent - k_parent_m1 * parent
@@ -172,7 +172,7 @@
 ## 
 ## Model predictions using solution type deSolve 
 ## 
-## Fitted with method Port using 153 model solutions performed in 0.693 s
+## Fitted with method Port using 153 model solutions performed in 0.731 s
 ## 
 ## Weighting: none
 ## 
diff --git a/docs/articles/FOCUS_L.html b/docs/articles/FOCUS_L.html
index 13131315..17c7bf59 100644
--- a/docs/articles/FOCUS_L.html
+++ b/docs/articles/FOCUS_L.html
@@ -111,15 +111,15 @@
 summary(m.L1.SFO)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:22 2019 
-## Date of summary: Fri Feb 22 09:51:22 2019 
+## Date of fit:     Fri Feb 22 20:48:32 2019 
+## Date of summary: Fri Feb 22 20:48:32 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent_sink * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 37 model solutions performed in 0.095 s
+## Fitted with method Port using 37 model solutions performed in 0.105 s
 ## 
 ## Weighting: none
 ## 
@@ -202,15 +202,15 @@
 
summary(m.L1.FOMC, data = FALSE)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:24 2019 
-## Date of summary: Fri Feb 22 09:51:24 2019 
+## Date of fit:     Fri Feb 22 20:48:34 2019 
+## Date of summary: Fri Feb 22 20:48:34 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 611 model solutions performed in 1.515 s
+## Fitted with method Port using 611 model solutions performed in 1.604 s
 ## 
 ## Weighting: none
 ## 
@@ -297,15 +297,15 @@
 
summary(m.L2.FOMC, data = FALSE)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:25 2019 
-## Date of summary: Fri Feb 22 09:51:25 2019 
+## Date of fit:     Fri Feb 22 20:48:35 2019 
+## Date of summary: Fri Feb 22 20:48:35 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 81 model solutions performed in 0.198 s
+## Fitted with method Port using 81 model solutions performed in 0.216 s
 ## 
 ## Weighting: none
 ## 
@@ -368,8 +368,8 @@
 
summary(m.L2.DFOP, data = FALSE)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:26 2019 
-## Date of summary: Fri Feb 22 09:51:26 2019 
+## Date of fit:     Fri Feb 22 20:48:36 2019 
+## Date of summary: Fri Feb 22 20:48:36 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) *
@@ -378,7 +378,7 @@
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 336 model solutions performed in 0.847 s
+## Fitted with method Port using 336 model solutions performed in 0.864 s
 ## 
 ## Weighting: none
 ## 
@@ -460,8 +460,8 @@
 
summary(mm.L3[["DFOP", 1]])
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:27 2019 
-## Date of summary: Fri Feb 22 09:51:27 2019 
+## Date of fit:     Fri Feb 22 20:48:37 2019 
+## Date of summary: Fri Feb 22 20:48:38 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) *
@@ -470,7 +470,7 @@
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 137 model solutions performed in 0.347 s
+## Fitted with method Port using 137 model solutions performed in 0.362 s
 ## 
 ## Weighting: none
 ## 
@@ -561,15 +561,15 @@
 
summary(mm.L4[["SFO", 1]], data = FALSE)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:27 2019 
-## Date of summary: Fri Feb 22 09:51:28 2019 
+## Date of fit:     Fri Feb 22 20:48:38 2019 
+## Date of summary: Fri Feb 22 20:48:38 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - k_parent_sink * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 46 model solutions performed in 0.112 s
+## Fitted with method Port using 46 model solutions performed in 0.123 s
 ## 
 ## Weighting: none
 ## 
@@ -621,15 +621,15 @@
 
summary(mm.L4[["FOMC", 1]], data = FALSE)
## mkin version used for fitting:    0.9.48.1 
 ## R version used for fitting:       3.5.2 
-## Date of fit:     Fri Feb 22 09:51:28 2019 
-## Date of summary: Fri Feb 22 09:51:28 2019 
+## Date of fit:     Fri Feb 22 20:48:38 2019 
+## Date of summary: Fri Feb 22 20:48:38 2019 
 ## 
 ## Equations:
 ## d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent
 ## 
 ## Model predictions using solution type analytical 
 ## 
-## Fitted with method Port using 66 model solutions performed in 0.165 s
+## Fitted with method Port using 66 model solutions performed in 0.184 s
 ## 
 ## Weighting: none
 ## 
diff --git a/docs/articles/web_only/compiled_models.html b/docs/articles/web_only/compiled_models.html
index e9f8fa99..fbf2de33 100644
--- a/docs/articles/web_only/compiled_models.html
+++ b/docs/articles/web_only/compiled_models.html
@@ -126,14 +126,14 @@
 }
## Lade nötiges Paket: rbenchmark
##                    test replications elapsed relative user.self sys.self
-## 3     deSolve, compiled            3   2.336    1.000     2.335        0
-## 1 deSolve, not compiled            3  17.610    7.539    17.602        0
-## 2      Eigenvalue based            3   2.899    1.241     2.897        0
+## 3     deSolve, compiled            3   2.484    1.000     2.483        0
+## 1 deSolve, not compiled            3  17.963    7.231    17.951        0
+## 2      Eigenvalue based            3   3.146    1.267     3.144        0
 ##   user.child sys.child
 ## 3          0         0
 ## 1          0         0
 ## 2          0         0
-

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

+

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

@@ -157,8 +157,8 @@ }

## Successfully compiled differential equation model from auto-generated C code.
##                    test replications elapsed relative user.self sys.self
-## 2     deSolve, compiled            3   4.122    1.000     4.119        0
-## 1 deSolve, not compiled            3  37.359    9.063    37.343        0
+## 2     deSolve, compiled            3   4.232    1.000     4.226    0.004
+## 1 deSolve, not compiled            3  37.946    8.966    37.924    0.000
 ##   user.child sys.child
 ## 2          0         0
 ## 1          0         0
diff --git a/docs/news/index.html b/docs/news/index.html index 2e62819c..cd82d187 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -119,9 +119,9 @@ -
+

-mkin 0.9.48.1 (2019-02-21) Unreleased +mkin 0.9.48.1 (2019-02-22) Unreleased

  • Add the function ‘logLik.mkinfit’ which makes it possible to calculate an AIC for mkinfit objects

  • @@ -133,6 +133,7 @@
  • ‘tests/testthat/test_irls.R’: Test if the components of the error model used to generate the data can be reproduced with moderate accuracy

  • Add the function ‘CAKE_export’ to facilitate cross-checking of results

  • Implement the logistic model (only tested for parent fits)

  • +
  • ‘nafta’: Add evaluations according to the NAFTA guidance

@@ -676,7 +677,7 @@

Contents

#> Successfully compiled differential equation model from auto-generated C code.
fit.1 <- mkinfit(SFO_SFO_SFO, subset(mccall81_245T, soil == "Commerce"), quiet = TRUE) summary(fit.1, data = FALSE)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:49:48 2019 -#> Date of summary: Fri Feb 22 09:49:48 2019 +#> Date of fit: Fri Feb 22 20:46:54 2019 +#> Date of summary: Fri Feb 22 20:46:54 2019 #> #> Equations: #> d_T245/dt = - k_T245_sink * T245 - k_T245_phenol * T245 @@ -171,7 +171,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 574 model solutions performed in 3.837 s +#> Fitted with method Port using 574 model solutions performed in 4.461 s #> #> Weighting: none #> @@ -249,8 +249,8 @@ fixed_parms = "k_phenol_sink", quiet = TRUE) summary(fit.2, data = FALSE)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:49:50 2019 -#> Date of summary: Fri Feb 22 09:49:50 2019 +#> Date of fit: Fri Feb 22 20:46:56 2019 +#> Date of summary: Fri Feb 22 20:46:56 2019 #> #> Equations: #> d_T245/dt = - k_T245_sink * T245 - k_T245_phenol * T245 @@ -260,7 +260,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 246 model solutions performed in 1.611 s +#> Fitted with method Port using 246 model solutions performed in 1.709 s #> #> Weighting: none #> diff --git a/docs/reference/mkinfit.html b/docs/reference/mkinfit.html index addb23e5..dfdddb25 100644 --- a/docs/reference/mkinfit.html +++ b/docs/reference/mkinfit.html @@ -438,15 +438,15 @@ fit <- mkinfit("FOMC", FOCUS_2006_C, quiet = TRUE) summary(fit)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:49:53 2019 -#> Date of summary: Fri Feb 22 09:49:53 2019 +#> Date of fit: Fri Feb 22 20:46:59 2019 +#> Date of summary: Fri Feb 22 20:46:59 2019 #> #> Equations: #> d_parent/dt = - (alpha/beta) * 1/((time/beta) + 1) * parent #> #> Model predictions using solution type analytical #> -#> Fitted with method Port using 64 model solutions performed in 0.159 s +#> Fitted with method Port using 64 model solutions performed in 0.185 s #> #> Weighting: none #> @@ -515,7 +515,7 @@ m1 = mkinsub("SFO"))
#> Successfully compiled differential equation model from auto-generated C code.
# Fit the model to the FOCUS example dataset D using defaults print(system.time(fit <- mkinfit(SFO_SFO, FOCUS_2006_D, solution_type = "eigen", quiet = TRUE)))
#> User System verstrichen -#> 1.015 0.000 1.016
coef(fit)
#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink +#> 1.071 0.000 1.072
coef(fit)
#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink #> 99.59848 -3.03822 -2.98030 -5.24750
#> $ff #> parent_sink parent_m1 m1_sink #> 0.485524 0.514476 1.000000 @@ -590,7 +590,7 @@ #> Model cost at call 146 : 371.2134 #> Optimisation by method Port successfully terminated. #> User System verstrichen -#> 0.821 0.000 0.822
coef(fit.deSolve)
#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink +#> 0.852 0.000 0.852
coef(fit.deSolve)
#> parent_0 log_k_parent_sink log_k_parent_m1 log_k_m1_sink #> 99.59848 -3.03822 -2.98030 -5.24750
endpoints(fit.deSolve)
#> $ff #> parent_sink parent_m1 m1_sink #> 0.485524 0.514476 1.000000 @@ -628,8 +628,8 @@ m1 = mkinsub("SFO"), use_of_ff = "max")
#> Successfully compiled differential equation model from auto-generated C code.
f.noweight <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, quiet = TRUE) summary(f.noweight)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:50:05 2019 -#> Date of summary: Fri Feb 22 09:50:05 2019 +#> Date of fit: Fri Feb 22 20:47:11 2019 +#> Date of summary: Fri Feb 22 20:47:11 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -637,7 +637,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 186 model solutions performed in 0.853 s +#> Fitted with method Port using 186 model solutions performed in 0.864 s #> #> Weighting: none #> @@ -745,8 +745,8 @@ #> 120 m1 33.31 28.78984 4.520e+00
f.irls <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, reweight.method = "obs", quiet = TRUE) summary(f.irls)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:50:07 2019 -#> Date of summary: Fri Feb 22 09:50:07 2019 +#> Date of fit: Fri Feb 22 20:47:14 2019 +#> Date of summary: Fri Feb 22 20:47:14 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -754,7 +754,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 551 model solutions performed in 2.535 s +#> Fitted with method Port using 551 model solutions performed in 2.584 s #> #> Weighting: none #> @@ -867,8 +867,8 @@ #> 120 m1 33.31 28.80898 4.501e+00 2.722
f.w.mean <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, weight = "mean", quiet = TRUE) summary(f.w.mean)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:50:08 2019 -#> Date of summary: Fri Feb 22 09:50:08 2019 +#> Date of fit: Fri Feb 22 20:47:15 2019 +#> Date of summary: Fri Feb 22 20:47:15 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -876,7 +876,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 155 model solutions performed in 0.717 s +#> Fitted with method Port using 155 model solutions performed in 0.716 s #> #> Weighting: mean #> @@ -985,8 +985,8 @@ quiet = TRUE) summary(f.w.value)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:50:09 2019 -#> Date of summary: Fri Feb 22 09:50:09 2019 +#> Date of fit: Fri Feb 22 20:47:16 2019 +#> Date of summary: Fri Feb 22 20:47:16 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -994,7 +994,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 174 model solutions performed in 0.796 s +#> Fitted with method Port using 174 model solutions performed in 0.83 s #> #> Weighting: manual #> @@ -1105,8 +1105,8 @@ f.w.man <- mkinfit(SFO_SFO.ff, dw, err = "err.man", quiet = TRUE) summary(f.w.man)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:50:11 2019 -#> Date of summary: Fri Feb 22 09:50:11 2019 +#> Date of fit: Fri Feb 22 20:47:17 2019 +#> Date of summary: Fri Feb 22 20:47:17 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -1114,7 +1114,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 270 model solutions performed in 1.325 s +#> Fitted with method Port using 270 model solutions performed in 1.286 s #> #> Weighting: manual #> @@ -1223,8 +1223,8 @@ reweight.method = "obs") summary(f.w.man.irls)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:50:14 2019 -#> Date of summary: Fri Feb 22 09:50:14 2019 +#> Date of fit: Fri Feb 22 20:47:21 2019 +#> Date of summary: Fri Feb 22 20:47:21 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -1232,7 +1232,7 @@ #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 692 model solutions performed in 3.303 s +#> Fitted with method Port using 692 model solutions performed in 3.38 s #> #> Weighting: manual #> diff --git a/docs/reference/mkinmod.html b/docs/reference/mkinmod.html index b2f290d1..64fba5e5 100644 --- a/docs/reference/mkinmod.html +++ b/docs/reference/mkinmod.html @@ -231,7 +231,7 @@ For the definition of model types and their parameters, the equations given SFO_SFO <- mkinmod( parent = mkinsub("SFO", "m1"), m1 = mkinsub("SFO"), verbose = TRUE)
#> Compilation argument: -#> /usr/lib/R/bin/R CMD SHLIB file4d9c2c394c1.c 2> file4d9c2c394c1.c.err.txt +#> /usr/lib/R/bin/R CMD SHLIB file622753352edd.c 2> file622753352edd.c.err.txt #> Program source: #> 1: #include <R.h> #> 2: diff --git a/docs/reference/mkinpredict.html b/docs/reference/mkinpredict.html index 6f789fa4..2b4c33aa 100644 --- a/docs/reference/mkinpredict.html +++ b/docs/reference/mkinpredict.html @@ -325,17 +325,17 @@ 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 verstrichen -#> 0.003 0.000 0.003
system.time( +#> 0.004 0.000 0.003
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 verstrichen -#> 0.001 0.000 0.002
system.time( +#> 0.002 0.000 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 verstrichen -#> 0.042 0.000 0.042
+#> 0.039 0.000 0.040
# Predict from a fitted model f <- mkinfit(SFO_SFO, FOCUS_2006_C)
#> Model cost at call 1 : 552.5739 #> Model cost at call 3 : 552.5739 diff --git a/docs/reference/mmkin.html b/docs/reference/mmkin.html index 73a25ef2..71ec89e8 100644 --- a/docs/reference/mmkin.html +++ b/docs/reference/mmkin.html @@ -191,8 +191,8 @@ time_1 <- system.time(fits.4 <- mmkin(models, datasets, cores = 1, quiet = TRUE)) time_default
#> User System verstrichen -#> 0.040 0.047 7.314
time_1
#> User System verstrichen -#> 22.751 0.000 22.766
+#> 0.052 0.044 7.383
time_1
#> User System verstrichen +#> 23.652 0.004 23.672
endpoints(fits.0[["SFO_lin", 2]])
#> $ff #> parent_M1 parent_sink M1_M2 M1_sink #> 0.7340480 0.2659520 0.7505686 0.2494314 diff --git a/docs/reference/nafta-1.png b/docs/reference/nafta-1.png new file mode 100644 index 00000000..c4f9f048 Binary files /dev/null and b/docs/reference/nafta-1.png differ diff --git a/docs/reference/nafta.html b/docs/reference/nafta.html new file mode 100644 index 00000000..c74c3939 --- /dev/null +++ b/docs/reference/nafta.html @@ -0,0 +1,239 @@ + + + + + + + + +Evaluate parent kinetics using the NAFTA guidance — nafta • mkin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

The function fits the SFO, IORE and DFOP models using + mmkin and returns an object of class + nafta that has methods for printing and plotting.

+ +
+ +
nafta(ds, title = NA, quiet = FALSE)
+ +

Arguments

+ + + + + + + + + + + + + + +
ds

A dataframe that 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".

title

Optional title of the dataset

quiet

Should the evaluation text be shown?

+ +

Value

+ +

An list of class nafta. The list element named "mmkin" is the + mmkin object containing the fits of the three models. + The list element named "title" contains the title of the dataset used. + The list element "data" contains the dataset used in the fits.

+ +

Source

+ +

NAFTA (2011) Guidance for evaluating and calculating degradation kinetics + in environmental media. NAFTA Technical Working Group on Pesticides + https://www.epa.gov/pesticide-science-and-assessing-pesticide-risks/guidance-evaluating-and-calculating-degradation + accessed 2019-02-22

+

US EPA (2015) Standard Operating Procedure for Using the NAFTA Guidance to + Calculate Representative Half-life Values and Characterizing Pesticide + Degradation + https://www.epa.gov/pesticide-science-and-assessing-pesticide-risks/standard-operating-procedure-using-nafta-guidance

+ + +

Examples

+
nafta_evaluation <- nafta(MRID_555555)
#> The SFO model is rejected as S_SFO is equal or higher than the critical value S_c
#> The representative half-life of the IORE model is longer than the one corresponding to the terminal degradation rate found with the DFOP model.
#> The reprentative half-life obtained from the DFOP model may be used
print(nafta_evaluation)
#> Parameters: +#> $SFO +#> Estimate Pr(>t) Lower Upper +#> parent_0 83.755751519 8.076390e-15 76.928220975 90.583282063 +#> k_parent_sink 0.001703321 7.452357e-05 0.001108568 0.002617164 +#> +#> $IORE +#> Estimate Pr(>t) Lower Upper +#> parent_0 9.685291e+01 NA 8.752855e+01 1.061773e+02 +#> k__iore_parent_sink 8.403374e-14 NA 1.092054e-19 6.466412e-08 +#> N_parent 6.684458e+00 NA 3.538511e+00 9.830405e+00 +#> +#> $DFOP +#> Estimate Pr(>t) Lower Upper +#> parent_0 9.755655e+01 4.439930e-13 8.884447e+01 1.062686e+02 +#> k1 4.240633e-02 3.554769e-02 1.414189e-02 1.271610e-01 +#> k2 8.237928e-04 2.060933e-02 3.172784e-04 2.138925e-03 +#> g 2.881037e-01 1.313715e-04 1.783967e-01 4.299694e-01 +#> +#> +#> DTx values: +#> DT50 DT90 DT50_rep +#> SFO 407 1352 407 +#> IORE 541 5192066 1562968 +#> DFOP 429 2383 841 +#> +#> Representative half-life: +#> [1] 841.4096
plot(nafta_evaluation)
+
+ +
+ +
+ + +
+

Site built with pkgdown 1.3.0.

+
+
+
+ + + + + + diff --git a/docs/reference/plot.nafta.html b/docs/reference/plot.nafta.html new file mode 100644 index 00000000..ccc98b23 --- /dev/null +++ b/docs/reference/plot.nafta.html @@ -0,0 +1,190 @@ + + + + + + + + +Plot the results of the three models used in the NAFTA scheme — plot.nafta • mkin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Calls plot.mmkin.

+ +
+ +
# S3 method for nafta
+plot(x, legend = FALSE, main = "auto", …)
+ +

Arguments

+ + + + + + + + + + + + + + + + + + +
x

An object of class nafta.

legend

Should a legend be added?

main

Possibility to override the main title of the plot.

Further arguments passed to plot.mmkin.

+ +

Value

+ +

The function is called for its side effect.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown 1.3.0.

+
+
+
+ + + + + + diff --git a/docs/reference/print.nafta.html b/docs/reference/print.nafta.html new file mode 100644 index 00000000..dc9373f7 --- /dev/null +++ b/docs/reference/print.nafta.html @@ -0,0 +1,178 @@ + + + + + + + + +Print nafta objects — print.nafta • mkin + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + +
+ +
+
+ + +
+ +

Print nafta objects.

+ +
+ +
# S3 method for nafta
+print(x, quiet = TRUE, ...)
+ +

Arguments

+ + + + + + + + + + + + + + +
x

An nafta object.

quiet

Should the evaluation text be shown?

Not used.

+ + +
+ +
+ +
+ + +
+

Site built with pkgdown 1.3.0.

+
+
+
+ + + + + + diff --git a/docs/reference/summary.mkinfit.html b/docs/reference/summary.mkinfit.html index 1543c328..39ef962c 100644 --- a/docs/reference/summary.mkinfit.html +++ b/docs/reference/summary.mkinfit.html @@ -208,15 +208,15 @@

Examples

summary(mkinfit(mkinmod(parent = mkinsub("SFO")), FOCUS_2006_A, quiet = TRUE))
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:51:06 2019 -#> Date of summary: Fri Feb 22 09:51:06 2019 +#> Date of fit: Fri Feb 22 20:48:16 2019 +#> Date of summary: Fri Feb 22 20:48:16 2019 #> #> Equations: #> d_parent/dt = - k_parent_sink * parent #> #> Model predictions using solution type analytical #> -#> Fitted with method Port using 35 model solutions performed in 0.086 s +#> Fitted with method Port using 35 model solutions performed in 0.088 s #> #> Weighting: none #> diff --git a/docs/reference/transform_odeparms.html b/docs/reference/transform_odeparms.html index 65a6b4ee..9d18fbb2 100644 --- a/docs/reference/transform_odeparms.html +++ b/docs/reference/transform_odeparms.html @@ -202,8 +202,8 @@ The transformation of sets of formation fractions is fragile, as it supposes fit <- mkinfit(SFO_SFO, FOCUS_2006_D, quiet = TRUE) summary(fit, data=FALSE) # See transformed and backtransformed parameters
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:51:14 2019 -#> Date of summary: Fri Feb 22 09:51:14 2019 +#> Date of fit: Fri Feb 22 20:48:24 2019 +#> Date of summary: Fri Feb 22 20:48:24 2019 #> #> Equations: #> d_parent/dt = - k_parent_sink * parent - k_parent_m1 * parent @@ -211,7 +211,7 @@ The transformation of sets of formation fractions is fragile, as it supposes #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 153 model solutions performed in 0.775 s +#> Fitted with method Port using 153 model solutions performed in 0.717 s #> #> Weighting: none #> @@ -278,8 +278,8 @@ The transformation of sets of formation fractions is fragile, as it supposes
fit.2 <- mkinfit(SFO_SFO, FOCUS_2006_D, transform_rates = FALSE, quiet = TRUE) summary(fit.2, data=FALSE)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:51:16 2019 -#> Date of summary: Fri Feb 22 09:51:16 2019 +#> Date of fit: Fri Feb 22 20:48:26 2019 +#> Date of summary: Fri Feb 22 20:48:26 2019 #> #> Equations: #> d_parent/dt = - k_parent_sink * parent - k_parent_m1 * parent @@ -287,7 +287,7 @@ The transformation of sets of formation fractions is fragile, as it supposes #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 350 model solutions performed in 1.584 s +#> Fitted with method Port using 350 model solutions performed in 1.661 s #> #> Weighting: none #> @@ -366,8 +366,8 @@ The transformation of sets of formation fractions is fragile, as it supposes fit.ff <- mkinfit(SFO_SFO.ff, FOCUS_2006_D, quiet = TRUE) summary(fit.ff, data = FALSE)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:51:17 2019 -#> Date of summary: Fri Feb 22 09:51:17 2019 +#> Date of fit: Fri Feb 22 20:48:27 2019 +#> Date of summary: Fri Feb 22 20:48:27 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -375,7 +375,7 @@ The transformation of sets of formation fractions is fragile, as it supposes #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 186 model solutions performed in 0.858 s +#> Fitted with method Port using 186 model solutions performed in 0.871 s #> #> Weighting: none #> @@ -450,8 +450,8 @@ The transformation of sets of formation fractions is fragile, as it supposes fit.ff.2 <- mkinfit(SFO_SFO.ff.2, FOCUS_2006_D, quiet = TRUE) summary(fit.ff.2, data = FALSE)
#> mkin version used for fitting: 0.9.48.1 #> R version used for fitting: 3.5.2 -#> Date of fit: Fri Feb 22 09:51:18 2019 -#> Date of summary: Fri Feb 22 09:51:18 2019 +#> Date of fit: Fri Feb 22 20:48:28 2019 +#> Date of summary: Fri Feb 22 20:48:28 2019 #> #> Equations: #> d_parent/dt = - k_parent * parent @@ -459,7 +459,7 @@ The transformation of sets of formation fractions is fragile, as it supposes #> #> Model predictions using solution type deSolve #> -#> Fitted with method Port using 104 model solutions performed in 0.47 s +#> Fitted with method Port using 104 model solutions performed in 0.484 s #> #> Weighting: none #> diff --git a/man/NAFTA_2015_datasets.Rd b/man/NAFTA_2015_datasets.Rd new file mode 100644 index 00000000..4ca494ee --- /dev/null +++ b/man/NAFTA_2015_datasets.Rd @@ -0,0 +1,35 @@ +\name{NAFTA_2015_datasets} +\alias{MRID_555555} +\docType{data} +\title{ +Example datasets from the NAFTA guidance published 2015 +} +\description{ +Data taken from US EPA (2015), p. 23. +} +\usage{NAFTA_2015_datasets} +\format{ + 1 dataset with observations on the following variables. + \describe{ + \item{\code{name}}{a factor containing the name of the observed variable} + \item{\code{time}}{a numeric vector containing time points} + \item{\code{value}}{a numeric vector containing concentrations} + } +} +\source{ + NAFTA (2011) Guidance for evaluating and calculating degradation kinetics + in environmental media. NAFTA Technical Working Group on Pesticides + \url{https://www.epa.gov/pesticide-science-and-assessing-pesticide-risks/guidance-evaluating-and-calculating-degradation} + accessed 2019-02-22 + + US EPA (2015) Standard Operating Procedure for Using the NAFTA Guidance to + Calculate Representative Half-life Values and Characterizing Pesticide + Degradation + \url{https://www.epa.gov/pesticide-science-and-assessing-pesticide-risks/standard-operating-procedure-using-nafta-guidance} +} +\examples{ + nafta_evaluation <- nafta(MRID_555555) + print(nafta_evaluation) + plot(nafta_evaluation) +} +\keyword{datasets} diff --git a/man/nafta.Rd b/man/nafta.Rd new file mode 100644 index 00000000..cd06e02b --- /dev/null +++ b/man/nafta.Rd @@ -0,0 +1,48 @@ +\name{nafta} +\alias{nafta} +\title{ +Evaluate parent kinetics using the NAFTA guidance +} +\usage{ +nafta(ds, title = NA, quiet = FALSE) +} +\description{ + The function fits the SFO, IORE and DFOP models using + \code{\link{mmkin}} and returns an object of class + \code{nafta} that has methods for printing and plotting. +} +\arguments{ + \item{ds}{ + A dataframe that must contain one variable called "time" with the time + values specified by the \code{time} argument, one column called "name" with + the grouping of the observed values, and finally one column of observed + values called "value". + } + \item{title}{ Optional title of the dataset } + \item{quiet}{ Should the evaluation text be shown? } +} +\value{ + An list of class \code{nafta}. The list element named "mmkin" is the + \code{\link{mmkin}} object containing the fits of the three models. + The list element named "title" contains the title of the dataset used. + The list element "data" contains the dataset used in the fits. +} +\source{ + NAFTA (2011) Guidance for evaluating and calculating degradation kinetics + in environmental media. NAFTA Technical Working Group on Pesticides + \url{https://www.epa.gov/pesticide-science-and-assessing-pesticide-risks/guidance-evaluating-and-calculating-degradation} + accessed 2019-02-22 + + US EPA (2015) Standard Operating Procedure for Using the NAFTA Guidance to + Calculate Representative Half-life Values and Characterizing Pesticide + Degradation + \url{https://www.epa.gov/pesticide-science-and-assessing-pesticide-risks/standard-operating-procedure-using-nafta-guidance} +} +\examples{ + nafta_evaluation <- nafta(MRID_555555) + print(nafta_evaluation) + plot(nafta_evaluation) +} +\author{ + Johannes Ranke +} diff --git a/man/plot.nafta.Rd b/man/plot.nafta.Rd new file mode 100644 index 00000000..a3dfdbae --- /dev/null +++ b/man/plot.nafta.Rd @@ -0,0 +1,31 @@ +\name{plot.nafta} +\alias{plot.nafta} +\title{ + Plot the results of the three models used in the NAFTA scheme +} +\description{ + Calls \code{\link{plot.mmkin}}. +} +\usage{ +\method{plot}{nafta}(x, legend = FALSE, main = "auto", \dots) +} +\arguments{ + \item{x}{ + An object of class \code{\link{nafta}}. + } + \item{legend}{ + Should a legend be added? + } + \item{main}{ + Possibility to override the main title of the plot. + } + \item{\dots}{ + Further arguments passed to \code{\link{plot.mmkin}}. + } +} +\value{ + The function is called for its side effect. +} +\author{ + Johannes Ranke +} diff --git a/man/print.nafta.Rd b/man/print.nafta.Rd new file mode 100644 index 00000000..4ae4c8b2 --- /dev/null +++ b/man/print.nafta.Rd @@ -0,0 +1,22 @@ +\name{print.nafta} +\alias{print.nafta} +\title{ + Print nafta objects +} +\description{ + Print nafta objects. +} +\usage{ + \method{print}{nafta}(x, quiet = TRUE, ...) +} +\arguments{ + \item{x}{ + An \code{\link{nafta}} object. + } + \item{quiet}{ + Should the evaluation text be shown? + } + \item{\dots}{ + Not used. + } +} diff --git a/tests/testthat/test_nafta.R b/tests/testthat/test_nafta.R new file mode 100644 index 00000000..7d650ad8 --- /dev/null +++ b/tests/testthat/test_nafta.R @@ -0,0 +1,41 @@ +# Copyright (C) 2019 Johannes Ranke +# Contact: jranke@uni-bremen.de + +# This file is part of the R package mkin + +# mkin is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. + +# You should have received a copy of the GNU General Public License along with +# this program. If not, see + +library(testthat) +library(mkin) + +context("Evaluations according to the NAFTA guidance from 2015") + +test_that("Data for more than one compound are rejected", + expect_error(nafta(FOCUS_2006_D))) + +test_that("Test data from Appendix D are correctly evaluated", { + expect_message(res <- nafta(MRID_555555, "MRID 555555")) + + # From Figure D.1 + dtx_sop <- matrix(c(407, 541, 429, 1352, 5192066, 2383), nrow = 3, ncol = 2) + expect_equivalent(res$distimes[, 1:2], dtx_sop, tolerance = 1, + scale = 1) + C0_sop <- c(SFO = 83.8, IORE = 96.9, DFOP = 97.6) + C0_mkin <- sapply(res$parameters, function(x) x["parent_0", "Estimate"]) + expect_equivalent(C0_mkin, C0_sop, scale = 1, tolerance = 0.1) + + expect_equal(round(res$S_c), 717) + expect_equal(signif(res$S[["SFO"]], 3), 1.38e+3) + expect_equal(round(res$t_rep), 841) +}) -- cgit v1.2.1