diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2019-02-27 12:04:52 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2019-02-27 12:04:52 +0100 |
commit | 6b4ab746e5474dfeda9237f01bc2dd01f1bb62ee (patch) | |
tree | 7299e1fa4fa9bd0090a5878df985312f528615f4 | |
parent | c446b59e675aeff08ff7205b05f06cd81bf6dc68 (diff) |
Increase test coverage
-rw-r--r-- | R/mkinfit.R | 25 | ||||
-rw-r--r-- | test.log | 30 | ||||
-rw-r--r-- | tests/testthat/DFOP_FOCUS_C_messages.txt | 270 | ||||
-rw-r--r-- | tests/testthat/FOCUS_2006_C_mkinds.txt | 0 | ||||
-rw-r--r-- | tests/testthat/test_from_max_mean.R | 17 | ||||
-rw-r--r-- | tests/testthat/test_mkinds.R | 6 | ||||
-rw-r--r-- | tests/testthat/test_mkinfit_errors.R | 71 | ||||
-rw-r--r-- | tests/testthat/test_plots_summary_twa.R | 33 |
8 files changed, 413 insertions, 39 deletions
diff --git a/R/mkinfit.R b/R/mkinfit.R index 63455300..b5020418 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -526,10 +526,13 @@ mkinfit <- function(mkinmod, observed, }
}
- # Return number of iterations for SANN method
+ # Return number of iterations for SANN method and alert user to check if
+ # the approximation to the optimum is sufficient
if (method.modFit == "SANN") {
fit$iter = maxit.modFit
- if(!quiet) cat("Termination of the SANN algorithm does not imply convergence.\n")
+ fit$warning <- paste0("Termination of the SANN algorithm does not imply convergence.\n",
+ "Make sure the approximation of the optimum is adequate.")
+ warning(fit$warning)
}
# We need to return some more data for summary and plotting
@@ -740,6 +743,16 @@ summary.mkinfit <- function(object, data = TRUE, distimes = TRUE, alpha = 0.05, ans$errmin <- mkinerrmin(object, alpha = 0.05)
+ if (object$calls > 0) {
+ if (!is.null(ans$cov.unscaled)){
+ Corr <- cov2cor(ans$cov.unscaled)
+ rownames(Corr) <- colnames(Corr) <- rownames(ans$par)
+ ans$Corr <- Corr
+ } else {
+ warning("Could not estimate covariance matrix; singular system.")
+ }
+ }
+
ans$bparms.ode <- object$bparms.ode
ep <- endpoints(object)
if (length(ep$ff) != 0)
@@ -811,13 +824,9 @@ print.summary.mkinfit <- function(x, digits = max(3, getOption("digits") - 3), . if (x$calls > 0) {
cat("\nParameter correlation:\n")
if (!is.null(x$cov.unscaled)){
- Corr <- cov2cor(x$cov.unscaled)
- rownames(Corr) <- colnames(Corr) <- rownames(x$par)
- print(Corr, digits = digits, ...)
+ print(x$Corr, digits = digits, ...)
} else {
- msg <- "Could not estimate covariance matrix; singular system:\n"
- warning(msg)
- cat(msg)
+ cat("Could not estimate covariance matrix; singular system.")
}
}
@@ -3,7 +3,8 @@ Testing mkin ✔ | OK F W S | Context
⠏ | 0 | Export dataset for reading into CAKE
⠋ | 1 | Export dataset for reading into CAKE
✔ | 1 | Export dataset for reading into CAKE
⠏ | 0 | Calculation of FOCUS chi2 error levels
⠋ | 1 | Calculation of FOCUS chi2 error levels
⠙ | 2 | Calculation of FOCUS chi2 error levels
✔ | 2 | Calculation of FOCUS chi2 error levels [2.3 s] -
⠏ | 0 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠋ | 1 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠙ | 2 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠹ | 3 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠸ | 4 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠼ | 5 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠴ | 6 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠦ | 7 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠧ | 8 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠇ | 9 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠏ | 10 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠋ | 11 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠙ | 12 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠹ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠸ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
✔ | 14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [8.0 s] +
⠏ | 0 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠋ | 1 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠙ | 2 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠹ | 3 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠸ | 4 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠼ | 5 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠴ | 6 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠦ | 7 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠧ | 8 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠇ | 9 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠏ | 10 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠋ | 11 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠙ | 12 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
⠹ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014)
✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [7.9 s] +
⠏ | 0 | Test fitting the decline of metabolites from their maximum
⠋ | 1 | Test fitting the decline of metabolites from their maximum
⠙ | 2 | Test fitting the decline of metabolites from their maximum
⠹ | 3 | Test fitting the decline of metabolites from their maximum
✔ | 3 | Test fitting the decline of metabolites from their maximum [0.6 s]
⠏ | 0 | Iteratively reweighted least squares (IRLS) fitting
⠋ | 1 | Iteratively reweighted least squares (IRLS) fitting
⠙ | 2 | Iteratively reweighted least squares (IRLS) fitting
⠹ | 2 1 | Iteratively reweighted least squares (IRLS) fitting
✔ | 2 1 | Iteratively reweighted least squares (IRLS) fitting [15.9 s] ──────────────────────────────────────────────────────────────────────────────── test_irls.R:48: skip: Reweighting method 'tc' works @@ -14,25 +15,26 @@ Too much trouble with datasets that are randomly generated test_logistic.R:41: skip: The logistic fit can be done via differential equation Skip slow fit of logistic model using deSolve without compilation ──────────────────────────────────────────────────────────────────────────────── -
⠏ | 0 | Model predictions with mkinpredict
⠋ | 1 | Model predictions with mkinpredict
⠙ | 2 | Model predictions with mkinpredict
⠹ | 3 | Model predictions with mkinpredict
✔ | 3 | Model predictions with mkinpredict [0.3 s] -
⠏ | 0 | Evaluations according to 2015 NAFTA guidance
⠋ | 1 | Evaluations according to 2015 NAFTA guidance
⠙ | 2 | Evaluations according to 2015 NAFTA guidance
⠹ | 3 | Evaluations according to 2015 NAFTA guidance
⠸ | 4 | Evaluations according to 2015 NAFTA guidance
⠼ | 5 | Evaluations according to 2015 NAFTA guidance
⠴ | 6 | Evaluations according to 2015 NAFTA guidance
⠦ | 7 | Evaluations according to 2015 NAFTA guidance
⠧ | 8 | Evaluations according to 2015 NAFTA guidance
⠇ | 9 | Evaluations according to 2015 NAFTA guidance
⠏ | 9 1 | Evaluations according to 2015 NAFTA guidance
⠏ | 10 | Evaluations according to 2015 NAFTA guidance
⠋ | 10 1 | Evaluations according to 2015 NAFTA guidance
⠙ | 11 1 | Evaluations according to 2015 NAFTA guidance
⠹ | 12 1 | Evaluations according to 2015 NAFTA guidance
⠸ | 13 1 | Evaluations according to 2015 NAFTA guidance
⠼ | 14 1 | Evaluations according to 2015 NAFTA guidance
⠴ | 15 1 | Evaluations according to 2015 NAFTA guidance
⠦ | 16 1 | Evaluations according to 2015 NAFTA guidance
✖ | 16 1 | Evaluations according to 2015 NAFTA guidance [1.5 s] +
⠏ | 0 | Test dataset class mkinds used in gmkin
⠋ | 1 | Test dataset class mkinds used in gmkin
✔ | 1 | Test dataset class mkinds used in gmkin +
⠏ | 0 | Special cases of mkinfit calls
⠋ | 1 | Special cases of mkinfit calls
⠙ | 2 | Special cases of mkinfit calls
⠹ | 3 | Special cases of mkinfit calls
⠸ | 4 | Special cases of mkinfit calls
⠼ | 5 | Special cases of mkinfit calls
⠴ | 6 | Special cases of mkinfit calls
⠦ | 7 | Special cases of mkinfit calls
⠧ | 8 | Special cases of mkinfit calls
⠇ | 9 | Special cases of mkinfit calls
⠏ | 10 | Special cases of mkinfit calls
⠋ | 11 | Special cases of mkinfit calls
⠙ | 12 | Special cases of mkinfit calls
⠹ | 12 1 | Special cases of mkinfit calls
⠸ | 13 1 | Special cases of mkinfit calls
⠼ | 14 1 | Special cases of mkinfit calls
⠴ | 15 1 | Special cases of mkinfit calls
⠦ | 16 1 | Special cases of mkinfit calls
✔ | 16 1 | Special cases of mkinfit calls [3.0 s] ──────────────────────────────────────────────────────────────────────────────── -test_nafta.R:50: failure: Test data from Appendix D are correctly evaluated -round(res$distimes[, 1:2]) not equivalent to `dtx_sop`. -1/6 mismatches -[5] 5192060 - 5192066 == -6 +test_mkinfit_errors.R:52: skip: mkinfit warns if the user chooses the SANN method +The SANN algorithm takes very long with the default maximum number of iterations of 10000 ──────────────────────────────────────────────────────────────────────────────── -
⠏ | 0 | Fitting of parent only models
⠋ | 1 | Fitting of parent only models
⠙ | 2 | Fitting of parent only models
⠹ | 3 | Fitting of parent only models
⠸ | 4 | Fitting of parent only models
⠼ | 5 | Fitting of parent only models
⠴ | 6 | Fitting of parent only models
⠦ | 7 | Fitting of parent only models
⠧ | 8 | Fitting of parent only models
⠇ | 9 | Fitting of parent only models
⠏ | 10 | Fitting of parent only models
⠋ | 11 | Fitting of parent only models
⠙ | 12 | Fitting of parent only models
⠹ | 13 | Fitting of parent only models
⠸ | 14 | Fitting of parent only models
⠼ | 15 | Fitting of parent only models
⠴ | 16 | Fitting of parent only models
⠦ | 17 | Fitting of parent only models
⠧ | 18 | Fitting of parent only models
⠇ | 19 | Fitting of parent only models
⠏ | 20 | Fitting of parent only models
⠋ | 21 | Fitting of parent only models
✔ | 21 | Fitting of parent only models [23.9 s] -
⠏ | 0 | Calculation of maximum time weighted average concentrations (TWAs)
⠋ | 1 | Calculation of maximum time weighted average concentrations (TWAs)
⠙ | 2 | Calculation of maximum time weighted average concentrations (TWAs)
⠹ | 3 | Calculation of maximum time weighted average concentrations (TWAs)
⠸ | 4 | Calculation of maximum time weighted average concentrations (TWAs)
⠼ | 5 | Calculation of maximum time weighted average concentrations (TWAs)
⠴ | 6 | Calculation of maximum time weighted average concentrations (TWAs)
⠦ | 7 | Calculation of maximum time weighted average concentrations (TWAs)
⠧ | 8 | Calculation of maximum time weighted average concentrations (TWAs)
✔ | 8 | Calculation of maximum time weighted average concentrations (TWAs) [7.4 s] +
⠏ | 0 | Model predictions with mkinpredict
⠋ | 1 | Model predictions with mkinpredict
⠙ | 2 | Model predictions with mkinpredict
⠹ | 3 | Model predictions with mkinpredict
✔ | 3 | Model predictions with mkinpredict [0.3 s] +
⠏ | 0 | Evaluations according to 2015 NAFTA guidance
⠋ | 1 | Evaluations according to 2015 NAFTA guidance
⠙ | 2 | Evaluations according to 2015 NAFTA guidance
⠹ | 3 | Evaluations according to 2015 NAFTA guidance
⠸ | 4 | Evaluations according to 2015 NAFTA guidance
⠼ | 5 | Evaluations according to 2015 NAFTA guidance
⠴ | 6 | Evaluations according to 2015 NAFTA guidance
⠦ | 7 | Evaluations according to 2015 NAFTA guidance
⠧ | 8 | Evaluations according to 2015 NAFTA guidance
⠇ | 9 | Evaluations according to 2015 NAFTA guidance
⠏ | 9 1 | Evaluations according to 2015 NAFTA guidance
⠏ | 10 | Evaluations according to 2015 NAFTA guidance
⠋ | 11 | Evaluations according to 2015 NAFTA guidance
⠙ | 12 | Evaluations according to 2015 NAFTA guidance
⠹ | 13 | Evaluations according to 2015 NAFTA guidance
⠸ | 14 | Evaluations according to 2015 NAFTA guidance
⠼ | 15 | Evaluations according to 2015 NAFTA guidance
⠴ | 16 | Evaluations according to 2015 NAFTA guidance
⠦ | 17 | Evaluations according to 2015 NAFTA guidance
✔ | 17 | Evaluations according to 2015 NAFTA guidance [1.5 s] +
⠏ | 0 | Fitting of parent only models
⠋ | 1 | Fitting of parent only models
⠙ | 2 | Fitting of parent only models
⠹ | 3 | Fitting of parent only models
⠸ | 4 | Fitting of parent only models
⠼ | 5 | Fitting of parent only models
⠴ | 6 | Fitting of parent only models
⠦ | 7 | Fitting of parent only models
⠧ | 8 | Fitting of parent only models
⠇ | 9 | Fitting of parent only models
⠏ | 10 | Fitting of parent only models
⠋ | 11 | Fitting of parent only models
⠙ | 12 | Fitting of parent only models
⠹ | 13 | Fitting of parent only models
⠸ | 14 | Fitting of parent only models
⠼ | 15 | Fitting of parent only models
⠴ | 16 | Fitting of parent only models
⠦ | 17 | Fitting of parent only models
⠧ | 18 | Fitting of parent only models
⠇ | 19 | Fitting of parent only models
⠏ | 20 | Fitting of parent only models
⠋ | 21 | Fitting of parent only models
✔ | 21 | Fitting of parent only models [23.8 s] +
⠏ | 0 | Calculation of maximum time weighted average concentrations (TWAs)
⠋ | 1 | Calculation of maximum time weighted average concentrations (TWAs)
⠙ | 2 | Calculation of maximum time weighted average concentrations (TWAs)
⠹ | 3 | Calculation of maximum time weighted average concentrations (TWAs)
⠸ | 4 | Calculation of maximum time weighted average concentrations (TWAs)
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [3.7 s]
⠏ | 0 | Summary
⠋ | 1 | Summary
✔ | 1 | Summary
⠏ | 0 | Plotting
⠋ | 1 | Plotting
⠙ | 2 | Plotting
⠹ | 3 | Plotting
⠸ | 4 | Plotting
✔ | 4 | Plotting [0.3 s] -
⠏ | 0 | Complex test case from Schaefer et al. (2007) Piacenza paper
⠋ | 1 | Complex test case from Schaefer et al. (2007) Piacenza paper
⠙ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper
✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.9 s] +
⠏ | 0 | AIC calculation
⠋ | 1 | AIC calculation
⠙ | 2 | AIC calculation
✔ | 2 | AIC calculation +
⠏ | 0 | Complex test case from Schaefer et al. (2007) Piacenza paper
⠋ | 1 | Complex test case from Schaefer et al. (2007) Piacenza paper
⠙ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper
✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.8 s]
⠏ | 0 | Results for synthetic data established in expertise for UBA (Ranke 2014)
⠋ | 1 | Results for synthetic data established in expertise for UBA (Ranke 2014)
⠙ | 2 | Results for synthetic data established in expertise for UBA (Ranke 2014)
⠹ | 3 | Results for synthetic data established in expertise for UBA (Ranke 2014)
⠸ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014)
✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.4 s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 74.6 s +Duration: 74.2 s -OK: 79 -Failed: 1 +OK: 97 +Failed: 0 Warnings: 0 -Skipped: 2 +Skipped: 3 diff --git a/tests/testthat/DFOP_FOCUS_C_messages.txt b/tests/testthat/DFOP_FOCUS_C_messages.txt new file mode 100644 index 00000000..7abde0b6 --- /dev/null +++ b/tests/testthat/DFOP_FOCUS_C_messages.txt @@ -0,0 +1,270 @@ +parent_0 log_k1 log_k2 g_ilr +85.1 -2.302585 -4.60517 0 +Model cost at call 1 : 7391.39 +85.1 -2.302585 -4.60517 0 +85.1 -2.302585 -4.60517 0 +Model cost at call 3 : 7391.389 +85.1 -2.302585 -4.60517 0 +Model cost at call 4 : 7391.389 +85.1 -2.302585 -4.60517 1.490116e-08 +85.06371 -1.77328 -4.250366 0.7698268 +Model cost at call 6 : 2000.127 +85.06375 -1.77328 -4.250366 0.7698268 +85.06371 -1.773322 -4.250366 0.7698268 +85.06371 -1.77328 -4.250408 0.7698268 +85.06371 -1.77328 -4.250366 0.7697847 +85.03542 -0.9608523 -4.11546 1.336361 +Model cost at call 11 : 32.97798 +85.03542 -0.9608523 -4.11546 1.336361 +85.03542 -0.9608526 -4.11546 1.336361 +85.03542 -0.9608523 -4.11546 1.336361 +85.03542 -0.9608523 -4.11546 1.336361 +85.03704 -0.256064 -4.273512 0.6447755 +85.03285 -0.7822828 -4.127513 1.312494 +Model cost at call 17 : 5.348133 +85.03286 -0.7822828 -4.127513 1.312494 +Model cost at call 18 : 5.348132 +85.03285 -0.7822828 -4.127513 1.312494 +Model cost at call 19 : 5.348131 +85.03285 -0.7822828 -4.127513 1.312494 +85.03285 -0.7822828 -4.127513 1.312494 +Model cost at call 21 : 5.348131 +85.02325 -0.74968 -4.059 1.14891 +85.03127 -0.7909068 -4.114802 1.268157 +Model cost at call 23 : 4.704445 +85.03127 -0.7909068 -4.114802 1.268157 +Model cost at call 24 : 4.704444 +85.03127 -0.7909068 -4.114802 1.268157 +85.03127 -0.7909068 -4.1148 1.268157 +Model cost at call 26 : 4.704433 +85.03127 -0.7909068 -4.114802 1.268158 +85.03001 -0.7801506 -4.069435 1.262797 +Model cost at call 28 : 4.421625 +85.03001 -0.7801506 -4.069435 1.262797 +85.03001 -0.7801507 -4.069435 1.262797 +Model cost at call 30 : 4.421624 +85.03001 -0.7801506 -4.069435 1.262797 +85.03001 -0.7801506 -4.069435 1.262797 +85.02878 -0.7900844 -4.023945 1.256918 +85.02964 -0.7857352 -4.054587 1.260236 +Model cost at call 34 : 4.414346 +85.02964 -0.7857352 -4.054587 1.260236 +85.02964 -0.7857351 -4.054587 1.260236 +Model cost at call 36 : 4.414346 +85.02964 -0.7857352 -4.054588 1.260236 +85.02964 -0.7857352 -4.054587 1.260236 +85.02812 -0.7778128 -4.042219 1.25389 +Model cost at call 39 : 4.372463 +85.02812 -0.7778128 -4.042219 1.25389 +85.02812 -0.7778129 -4.042219 1.25389 +Model cost at call 41 : 4.372462 +85.02812 -0.7778128 -4.042219 1.25389 +85.02812 -0.7778128 -4.042219 1.25389 +85.02419 -0.7765144 -4.02942 1.245094 +85.0263 -0.7778419 -4.036021 1.249634 +Model cost at call 45 : 4.369313 +85.0263 -0.7778419 -4.036021 1.249634 +85.0263 -0.7778418 -4.036021 1.249634 +Model cost at call 47 : 4.369313 +85.0263 -0.7778419 -4.036022 1.249634 +85.0263 -0.7778419 -4.036021 1.249634 +Model cost at call 49 : 4.369313 +85.02267 -0.7786811 -4.02967 1.252015 +Model cost at call 50 : 4.365062 +85.02268 -0.7786811 -4.02967 1.252015 +85.02267 -0.7786812 -4.02967 1.252015 +85.02267 -0.7786811 -4.02967 1.252015 +Model cost at call 53 : 4.365062 +85.02267 -0.7786811 -4.02967 1.252015 +85.01633 -0.7763163 -4.027611 1.248897 +Model cost at call 55 : 4.364078 +85.01633 -0.7763163 -4.027611 1.248897 +Model cost at call 56 : 4.364078 +85.01633 -0.7763164 -4.027611 1.248897 +Model cost at call 57 : 4.364077 +85.01633 -0.7763163 -4.027611 1.248897 +85.01633 -0.7763163 -4.027611 1.248897 +85.00894 -0.7777917 -4.026307 1.24772 +Model cost at call 60 : 4.364052 +85.00894 -0.7777917 -4.026307 1.24772 +Model cost at call 61 : 4.364052 +85.00894 -0.7777917 -4.026307 1.24772 +Model cost at call 62 : 4.364052 +85.00894 -0.7777917 -4.026307 1.24772 +85.00894 -0.7777917 -4.026307 1.24772 +Model cost at call 64 : 4.364052 +85.00518 -0.7773082 -4.026004 1.248453 +Model cost at call 65 : 4.362751 +85.00519 -0.7773082 -4.026004 1.248453 +85.00518 -0.7773083 -4.026004 1.248453 +Model cost at call 67 : 4.362751 +85.00518 -0.7773082 -4.026005 1.248453 +85.00518 -0.7773082 -4.026004 1.248453 +85.00134 -0.7776046 -4.025878 1.248775 +Model cost at call 70 : 4.362721 +85.00135 -0.7776046 -4.025878 1.248775 +Model cost at call 71 : 4.362721 +85.00134 -0.7776046 -4.025878 1.248775 +Model cost at call 72 : 4.362721 +85.00134 -0.7776046 -4.025878 1.248775 +85.00134 -0.7776046 -4.025878 1.248775 +85.0032 -0.7774734 -4.0257 1.248643 +Model cost at call 75 : 4.362715 +85.0032 -0.7774734 -4.0257 1.248643 +85.0032 -0.7774734 -4.0257 1.248643 +Model cost at call 77 : 4.362715 +85.0032 -0.7774735 -4.0257 1.248643 +85.0032 -0.7774734 -4.0257 1.248643 +85.0032 -0.7774734 -4.0257 1.248643 +85.0032 -0.7774734 -4.0257 1.248643 +85.00249 -0.7774909 -4.025911 1.248679 +Model cost at call 82 : 4.362715 +85.0025 -0.7774909 -4.025911 1.248679 +Model cost at call 83 : 4.362715 +85.00249 -0.7774909 -4.025911 1.248679 +85.00249 -0.7774905 -4.025911 1.248679 +85.00249 -0.7774914 -4.025911 1.248679 +Model cost at call 86 : 4.362715 +85.00249 -0.7774909 -4.025911 1.248679 +85.00249 -0.7774909 -4.025911 1.248679 +85.00249 -0.7774909 -4.025911 1.248679 +85.00249 -0.7774909 -4.025911 1.248679 +85.00274 -0.7774922 -4.025821 1.248672 +Model cost at call 91 : 4.362714 +85.00274 -0.7774922 -4.025821 1.248672 +85.00274 -0.7774922 -4.025821 1.248672 +Model cost at call 93 : 4.362714 +85.00274 -0.7774921 -4.025821 1.248672 +Model cost at call 94 : 4.362714 +85.00274 -0.7774922 -4.025821 1.248672 +85.00274 -0.7774922 -4.025821 1.248672 +85.00274 -0.7774922 -4.025821 1.248672 +85.00274 -0.7774922 -4.025821 1.248672 +85.00274 -0.7774922 -4.025821 1.248672 +85.00273 -0.7774912 -4.025817 1.24867 +Model cost at call 100 : 4.362714 +85.00275 -0.7774912 -4.025817 1.24867 +85.00271 -0.7774912 -4.025817 1.24867 +85.00273 -0.7774905 -4.025817 1.24867 +85.00273 -0.7774919 -4.025817 1.24867 +85.00273 -0.7774912 -4.025814 1.24867 +85.00273 -0.7774912 -4.025821 1.24867 +85.00273 -0.7774912 -4.025817 1.248671 +85.00273 -0.7774912 -4.025817 1.248669 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 109 : 4.362714 +85.00276 -0.7774913 -4.025819 1.248671 +85.00272 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774904 -4.025819 1.248671 +85.00274 -0.7774922 -4.025819 1.248671 +85.00274 -0.7774913 -4.025815 1.248671 +85.00274 -0.7774913 -4.025822 1.248671 +85.00274 -0.7774913 -4.025819 1.248672 +85.00274 -0.7774913 -4.025819 1.248669 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 123 : 4.362714 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +IRLS based on variance estimates according to the two component error model +Initial variance components are: +sigma_low rsd_high + 1.08984 0.00000 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 129 : 3.673061 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 132 : 3.673061 +85.00274 -0.7774913 -4.025819 1.248671 +85.00273 -0.7775309 -4.025818 1.24866 +85.00274 -0.7774953 -4.025819 1.24867 +85.00274 -0.7774917 -4.025819 1.248671 +85.00274 -0.7774914 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 138 : 3.673061 +85.00277 -0.7774913 -4.025819 1.248671 +85.0027 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774744 -4.025819 1.248671 +85.00274 -0.7775083 -4.025819 1.248671 +85.00274 -0.7774913 -4.025779 1.248671 +85.00274 -0.7774913 -4.025858 1.248671 +85.00274 -0.7774913 -4.025819 1.248702 +85.00274 -0.7774913 -4.025819 1.248639 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 147 : 3.673061 +85.00276 -0.7774913 -4.025819 1.248671 +85.00271 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774906 -4.025819 1.248671 +85.00274 -0.7774921 -4.025819 1.248671 +85.00274 -0.7774913 -4.025812 1.248671 +85.00274 -0.7774913 -4.025825 1.248671 +85.00274 -0.7774913 -4.025819 1.248672 +85.00274 -0.7774913 -4.025819 1.248669 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +Model cost at call 159 : 3.673061 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +Iteration 1 yields variance estimates: +sigma_low rsd_high +0.7434091 0.0000000 +Sum of squared differences to last variance (component) estimates: 0.12 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00273 -0.7775366 -4.025821 1.248652 +85.00274 -0.7774959 -4.025819 1.248669 +85.00274 -0.7774918 -4.025819 1.24867 +85.00274 -0.7774914 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00279 -0.7774913 -4.025819 1.248671 +85.00268 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774621 -4.025819 1.248671 +85.00274 -0.7775206 -4.025819 1.248671 +85.00274 -0.7774913 -4.025761 1.248671 +85.00274 -0.7774913 -4.025876 1.248671 +85.00274 -0.7774913 -4.025819 1.248714 +85.00274 -0.7774913 -4.025819 1.248627 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00273 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774908 -4.025819 1.248671 +85.00274 -0.7774919 -4.025819 1.248671 +85.00274 -0.7774913 -4.025816 1.248671 +85.00274 -0.7774913 -4.025822 1.248671 +85.00274 -0.7774913 -4.025819 1.248672 +85.00274 -0.7774913 -4.025819 1.24867 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +85.00274 -0.7774913 -4.025819 1.248671 +Iteration 2 yields variance estimates: +sigma_low rsd_high +0.7434091 0.0000000 +Sum of squared differences to last variance (component) estimates: 2.9e-16 +Optimisation by method Port successfully terminated. diff --git a/tests/testthat/FOCUS_2006_C_mkinds.txt b/tests/testthat/FOCUS_2006_C_mkinds.txt new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/testthat/FOCUS_2006_C_mkinds.txt diff --git a/tests/testthat/test_from_max_mean.R b/tests/testthat/test_from_max_mean.R new file mode 100644 index 00000000..8e5953b9 --- /dev/null +++ b/tests/testthat/test_from_max_mean.R @@ -0,0 +1,17 @@ +context("Test fitting the decline of metabolites from their maximum") + +test_that("Fitting from maximum mean value works", { + SFO_SFO <- mkinmod(parent = mkinsub("SFO", "m1"), + m1 = mkinsub("SFO")) + expect_error(mkinfit(SFO_SFO, FOCUS_2006_D, from_max_mean = TRUE)) + + # We can either explicitly create a model for m1, or subset the data + SFO_m1 <- mkinmod(m1 = mkinsub("SFO")) + f.1 <- mkinfit(SFO_m1, FOCUS_2006_D, from_max_mean = TRUE, quiet = TRUE) + expect_equivalent(endpoints(f.1)$distimes["m1", ], c(170.8, 567.5), + scale = 1, tolerance = 0.1) + + f.2 <- mkinfit("SFO", subset(FOCUS_2006_D, name == "m1"), from_max_mean = TRUE, quiet = TRUE) + expect_equivalent(endpoints(f.2)$distimes["m1", ], c(170.8, 567.5), + scale = 1, tolerance = 0.1) +}) diff --git a/tests/testthat/test_mkinds.R b/tests/testthat/test_mkinds.R new file mode 100644 index 00000000..e017301c --- /dev/null +++ b/tests/testthat/test_mkinds.R @@ -0,0 +1,6 @@ +context("Test dataset class mkinds used in gmkin") + +test_that("An mkinds object can be created and printed", { + testdata <- mkinds$new("FOCUS C", data = FOCUS_2006_C, time_unit = "days", unit = "%AR") + expect_known_output(testdata, "FOCUS_2006_C_mkinds.txt") +}) diff --git a/tests/testthat/test_mkinfit_errors.R b/tests/testthat/test_mkinfit_errors.R new file mode 100644 index 00000000..50032628 --- /dev/null +++ b/tests/testthat/test_mkinfit_errors.R @@ -0,0 +1,71 @@ +library(mkin) +library(testthat) + +context("Special cases of mkinfit calls") + +SFO_SFO.ff.nosink <- mkinmod( + parent = mkinsub("SFO", "m1", sink = FALSE), + m1 = mkinsub("SFO"), quiet = TRUE, use_of_ff = "max") + +SFO_SFO.ff <- mkinmod( + parent = mkinsub("SFO", "m1"), + m1 = mkinsub("SFO"), quiet = TRUE, use_of_ff = "max") + +test_that("mkinfit stops to prevent and/or explain user errors", { + expect_error(mkinfit("foo", FOCUS_2006_A)) + expect_error(mkinfit(3, FOCUS_2006_A)) + + # We get a warning if we use transform_fractions = FALSE with formation fractions + # and an error if any pathway to sink is turned off as well + expect_warning( + expect_error( + mkinfit(SFO_SFO.ff.nosink, FOCUS_2006_D, transform_fractions = FALSE, quiet = TRUE), + "turn off pathways to sink" + ), + "sum of formation fractions") + + expect_error(mkinfit(SFO_SFO.ff, FOCUS_2006_D, transform_fractions = TRUE, + parms.ini = c(f_parent_to_m1 = 0.5), fixed_parms = "f_parent_to_m1", quiet = TRUE), + "not supported") + + expect_error(mkinfit(SFO_SFO.ff, FOCUS_2006_D, + parms.ini = c(f_parent_to_m1 = 1.1), quiet = TRUE), + "sum up to more than 1") + + expect_error(mkinfit(SFO_SFO.ff, FOCUS_2006_D, solution_type = "analytical"), "not implemented") + + expect_error(mkinfit("FOMC", FOCUS_2006_A, solution_type = "eigen"), "coefficient matrix not present") + + # We suppress a message stemming from the interrupted call to system.time() + expect_error(suppressMessages(mkinfit("SFO", FOCUS_2006_A, reweight.method = + "foo", quiet = TRUE), "implemented")) + +}) + +test_that("mkinfit stops early when a low maximum number of iterations is specified", { + expect_warning(mkinfit("SFO", FOCUS_2006_A, maxit.modFit = 1, quiet = TRUE)) + expect_warning(mkinfit("SFO", FOCUS_2006_A, maxit.modFit = 1, quiet = TRUE, method.modFit = "Marq")) +}) + +test_that("mkinfit warns if the user chooses the SANN method", { + expect_warning(mkinfit("SFO", FOCUS_2006_A, method.modFit = "SANN", maxit.modFit = 10, quiet = TRUE)) + skip("The SANN algorithm takes very long with the default maximum number of iterations of 10000") + expect_warning(mkinfit("SFO", FOCUS_2006_A, method.modFit = "SANN")) +}) + +test_that("mkinfit warns if a specified initial parameter value is not in the model", { + expect_warning(mkinfit("SFO", FOCUS_2006_A, parms.ini = c(k_xy = 0.1), quiet = TRUE)) +}) + +test_that("We get reproducible output if quiet = FALSE", { + # We cannot expect parameter and sum of squares traces to be the same across platforms + skip_on_cran() + skip_on_travis() + expect_known_output(mkinfit("DFOP", FOCUS_2006_C, reweight.method = "tc", trace_parms = TRUE), + file = "DFOP_FOCUS_C_messages.txt") +}) + +test_that("We get warnings in case of overparameterisation", { + expect_warning(f <- mkinfit("FOMC", FOCUS_2006_A, quiet = TRUE), "not converge") + s2 <- expect_warning(summary(mkinfit("DFOP", FOCUS_2006_A, quiet = TRUE)), "singular system") +}) diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R index e13111bb..f58ce764 100644 --- a/tests/testthat/test_plots_summary_twa.R +++ b/tests/testthat/test_plots_summary_twa.R @@ -28,23 +28,22 @@ test_that("Time weighted average concentrations are correct", { outtimes_10 <- seq(0, 10, length.out = 10000) - for (ds in c("FOCUS_C", "FOCUS_D")) { - for (model in models) { - fit <- fits[[model, ds]] - bpar <- summary(fit)$bpar[, "Estimate"] - pred_10 <- mkinpredict(fit$mkinmod, - odeparms = bpar[2:length(bpar)], - odeini = c(parent = bpar[[1]]), - outtimes = outtimes_10) - twa_num <- mean(pred_10$parent) - names(twa_num) <- 10 - twa_ana <- max_twa_parent(fit, 10) - - # Test for absolute difference (scale = 1) - # The tolerance can be reduced if the length of outtimes is increased, - # but this needs more computing time so we stay with lenght.out = 10k - expect_equal(twa_num, twa_ana, tolerance = 0.003, scale = 1) - } + ds <- "FOCUS_C" + for (model in models) { + fit <- fits[[model, ds]] + bpar <- summary(fit)$bpar[, "Estimate"] + pred_10 <- mkinpredict(fit$mkinmod, + odeparms = bpar[2:length(bpar)], + odeini = c(parent = bpar[[1]]), + outtimes = outtimes_10) + twa_num <- mean(pred_10$parent) + names(twa_num) <- 10 + twa_ana <- max_twa_parent(fit, 10) + + # Test for absolute difference (scale = 1) + # The tolerance can be reduced if the length of outtimes is increased, + # but this needs more computing time so we stay with lenght.out = 10k + expect_equal(twa_num, twa_ana, tolerance = 0.003, scale = 1) } }) |