From f8d45402477a588f773f6fd300f3d4e914648773 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 22 Oct 2019 10:13:16 +0200 Subject: Improved visual testing --- GNUmakefile | 4 +- man/plot.mkinfit.Rd | 3 - test.log | 10 +- .../plotting/plot-errmod-with-sfo-lin-a-obs.svg | 237 +++++++++++++++++++++ .../plotting/plot-errmod-with-sfo-lin-a-tc.svg | 235 ++++++++++++++++++++ tests/testthat/FOCUS_2006_D.csf | 2 +- tests/testthat/setup_script.R | 2 + tests/testthat/test_error_models.R | 6 - tests/testthat/test_plots_summary_twa.R | 4 + 9 files changed, 487 insertions(+), 16 deletions(-) create mode 100644 tests/figs/plotting/plot-errmod-with-sfo-lin-a-obs.svg create mode 100644 tests/figs/plotting/plot-errmod-with-sfo-lin-a-tc.svg diff --git a/GNUmakefile b/GNUmakefile index 0141b54c..231273c1 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -76,6 +76,9 @@ slowtests: install NOT_CRAN=true "$(RBIN)/Rscript" -e 'library(mkin); testthat::test_dir("tests/testthat/slow")' 2>&1 | tee tests_slow.log sed -i -e "s/\r.*\r//" tests_slow.log +vdiffr: + "$(RBIN)/Rscript" -e 'vdiffr::manage_cases(filter = "plots|nafta")' + testcheck: test check README.html: README.md @@ -123,7 +126,6 @@ winbin: $(WINBIN) dratwin: winbin "$(RBIN)/Rscript" -e "drat::insertPackage('$(WINBIN)', '~/git/drat/', commit = TRUE)" - submit: @echo "\nHow about make test, make check, make pd, make winbuilder" @echo "\nIs the DESCRIPTION file up to date?" diff --git a/man/plot.mkinfit.Rd b/man/plot.mkinfit.Rd index e7b456a1..fac5663a 100644 --- a/man/plot.mkinfit.Rd +++ b/man/plot.mkinfit.Rd @@ -135,9 +135,6 @@ plot(fit) plot_res(fit) plot_err(fit) -# 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) diff --git a/test.log b/test.log index 901091a1..230fbd3b 100644 --- a/test.log +++ b/test.log @@ -3,9 +3,9 @@ Testing mkin ✔ | OK F W S | Context ✔ | 2 | Export dataset for reading into CAKE ✔ | 3 | Confidence intervals and p-values -✔ | 11 | Error model fitting [51.0 s] +✔ | 10 | Error model fitting [37.0 s] ✔ | 5 | Calculation of FOCUS chi2 error levels [3.5 s] -✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.5 s] +✔ | 13 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [3.4 s] ✔ | 6 | Test fitting the decline of metabolites from their maximum [0.9 s] ✔ | 1 | Fitting the logistic model [0.9 s] ✔ | 1 | Test dataset class mkinds used in gmkin @@ -15,7 +15,7 @@ Testing mkin ✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.0 s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2 s] ✔ | 3 | Summary -✔ | 7 | Plotting [0.4 s] +✔ | 9 | Plotting [0.5 s] ✔ | 3 | AIC calculation ✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.3 s] ✔ | 4 | Fitting the SFORB model [1.7 s] @@ -23,9 +23,9 @@ Testing mkin ✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.1 s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 83.9 s +Duration: 69.9 s -OK: 110 +OK: 111 Failed: 0 Warnings: 0 Skipped: 0 diff --git a/tests/figs/plotting/plot-errmod-with-sfo-lin-a-obs.svg b/tests/figs/plotting/plot-errmod-with-sfo-lin-a-obs.svg new file mode 100644 index 00000000..88e7aaee --- /dev/null +++ b/tests/figs/plotting/plot-errmod-with-sfo-lin-a-obs.svg @@ -0,0 +1,237 @@ + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + +Time +Observed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +parent +M1 +M2 + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + + + +0 +5 +10 +15 +20 +25 +30 + + + + + + +Predicted +Squared residual + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/figs/plotting/plot-errmod-with-sfo-lin-a-tc.svg b/tests/figs/plotting/plot-errmod-with-sfo-lin-a-tc.svg new file mode 100644 index 00000000..af7429a0 --- /dev/null +++ b/tests/figs/plotting/plot-errmod-with-sfo-lin-a-tc.svg @@ -0,0 +1,235 @@ + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + +Time +Observed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +parent +M1 +M2 + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + + + +0 +5 +10 +15 +20 +25 +30 + + + + + + +Predicted +Squared residual + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf index 171abbb0..638acd88 100644 --- a/tests/testthat/FOCUS_2006_D.csf +++ b/tests/testthat/FOCUS_2006_D.csf @@ -5,7 +5,7 @@ Description: MeasurementUnits: % AR TimeUnits: days Comments: Created using mkin::CAKE_export -Date: 2019-10-21 +Date: 2019-10-22 Optimiser: IRLS [Data] diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index d8d94d4b..51fea4f6 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -76,3 +76,5 @@ f_SFO_lin_mkin_OLS <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE) f_SFO_lin_mkin_ML <- mkinfit(m_synth_SFO_lin, SFO_lin_a, quiet = TRUE, error_model = "const", error_model_algorithm = "direct") +fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TRUE) +fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE) diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R index d8263c95..12a8b7e5 100644 --- a/tests/testthat/test_error_models.R +++ b/tests/testthat/test_error_models.R @@ -20,18 +20,12 @@ context("Error model fitting") test_that("Error model 'obs' works", { skip_on_cran() - fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TRUE) parms_2 <- round(fit_obs_1$bparms.optim, c(1, 4, 4, 4, 4, 4)) expect_equivalent(parms_2, c(102.1, 0.7389, 0.2982, 0.0203, 0.7677, 0.7246)) - plot_errmod_fit_obs_1 <- function() plot_err(fit_obs_1, sep_obs = FALSE) - - skip_on_travis() # This fails on Travis for an unknown reason - vdiffr::expect_doppelganger("plot_errmod with SFO_lin_a", plot_errmod_fit_obs_1) }) test_that("Error model 'tc' works", { skip_on_cran() - fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE) parms_3 <- round(fit_tc_1$bparms.optim, c(1, 4, 4, 4, 4, 4)) expect_equivalent(parms_3, c(102.1, 0.7393, 0.2992, 0.0202, 0.7687, 0.7229)) }) diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R index 089290f6..e3ecbbc4 100644 --- a/tests/testthat/test_plots_summary_twa.R +++ b/tests/testthat/test_plots_summary_twa.R @@ -99,6 +99,8 @@ test_that("Plotting mkinfit and mmkin objects is reproducible", { mmkin_SFO <- function() plot(fits["SFO",]) plot_res_sfo_sfo <- function() plot_res(f_sfo_sfo_desolve) plot_err_sfo_sfo <- function() plot_err(f_sfo_sfo_desolve) + plot_errmod_fit_obs_1 <- function() plot_err(fit_obs_1, sep_obs = FALSE) + plot_errmod_fit_tc_1 <- function() plot_err(fit_tc_1, sep_obs = FALSE) vdiffr::expect_doppelganger("mkinfit plot for FOCUS C with sep = TRUE", plot_sep_FOCUS_C_SFO) vdiffr::expect_doppelganger("mkinparplot for FOCUS C SFO", mkinparplot_FOCUS_C_SFO) @@ -107,6 +109,8 @@ test_that("Plotting mkinfit and mmkin objects is reproducible", { vdiffr::expect_doppelganger("mmkin plot for SFO (FOCUS C and D)", mmkin_SFO) vdiffr::expect_doppelganger("plot_res for FOCUS D", plot_res_sfo_sfo) vdiffr::expect_doppelganger("plot_err for FOCUS D", plot_err_sfo_sfo) + vdiffr::expect_doppelganger("plot_errmod with SFO_lin_a_obs", plot_errmod_fit_obs_1) + vdiffr::expect_doppelganger("plot_errmod with SFO_lin_a_tc", plot_errmod_fit_tc_1) }) context("AIC calculation") -- cgit v1.2.1