From e09f726134ee273b6b191c1ec6465e6f701b082b Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Mon, 21 Oct 2019 18:52:24 +0200 Subject: Improve some plotting routines, more tests Static documentation rebuilt by pkgdown --- .../plot-errmod-with-sfo-lin-a.svg | 237 +++++++++++++++++++++ .../mkinfit-plot-for-focus-c-with-sep-true.svg | 44 ++-- tests/figs/plotting/plot-err-for-focus-d.svg | 200 +++++++++++++++++ tests/figs/plotting/plot-res-for-focus-d.svg | 196 +++++++++++++++++ tests/testthat/test_error_models.R | 3 + tests/testthat/test_plots_summary_twa.R | 8 +- 6 files changed, 664 insertions(+), 24 deletions(-) create mode 100644 tests/figs/error-model-fitting/plot-errmod-with-sfo-lin-a.svg create mode 100644 tests/figs/plotting/plot-err-for-focus-d.svg create mode 100644 tests/figs/plotting/plot-res-for-focus-d.svg (limited to 'tests') diff --git a/tests/figs/error-model-fitting/plot-errmod-with-sfo-lin-a.svg b/tests/figs/error-model-fitting/plot-errmod-with-sfo-lin-a.svg new file mode 100644 index 00000000..88e7aaee --- /dev/null +++ b/tests/figs/error-model-fitting/plot-errmod-with-sfo-lin-a.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/mkinfit-plot-for-focus-c-with-sep-true.svg b/tests/figs/plotting/mkinfit-plot-for-focus-c-with-sep-true.svg index 2beb762c..327161da 100644 --- a/tests/figs/plotting/mkinfit-plot-for-focus-c-with-sep-true.svg +++ b/tests/figs/plotting/mkinfit-plot-for-focus-c-with-sep-true.svg @@ -86,21 +86,21 @@ - + - - - - - - + + + + + + 0 -20 -40 -60 -80 -100 -120 +20 +40 +60 +80 +100 +120 @@ -119,21 +119,21 @@ Time -Residuals +Residual - - - - - - - - + + + + + + + + diff --git a/tests/figs/plotting/plot-err-for-focus-d.svg b/tests/figs/plotting/plot-err-for-focus-d.svg new file mode 100644 index 00000000..6c5cab19 --- /dev/null +++ b/tests/figs/plotting/plot-err-for-focus-d.svg @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + +Time +Observed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +parent +m1 + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 +140 + + + + + + +Predicted +Squared residual + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/figs/plotting/plot-res-for-focus-d.svg b/tests/figs/plotting/plot-res-for-focus-d.svg new file mode 100644 index 00000000..f8bab71f --- /dev/null +++ b/tests/figs/plotting/plot-res-for-focus-d.svg @@ -0,0 +1,196 @@ + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + + +0 +20 +40 +60 +80 +100 + + + + + + +Time +Observed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +parent +m1 + + + + + + + + + + + + + + + + + + +0 +20 +40 +60 +80 +100 +120 + + + + + + +-10 +-5 +0 +5 +10 + + + + + + +Time +Residual + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R index ba40bae6..40c1e6e8 100644 --- a/tests/testthat/test_error_models.R +++ b/tests/testthat/test_error_models.R @@ -23,6 +23,9 @@ test_that("Error model 'obs' works", { 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) + + vdiffr::expect_doppelganger("plot_errmod with SFO_lin_a", plot_errmod_fit_obs_1) }) test_that("Error model 'tc' works", { diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R index 1dcf49ac..68ac7dcd 100644 --- a/tests/testthat/test_plots_summary_twa.R +++ b/tests/testthat/test_plots_summary_twa.R @@ -59,7 +59,7 @@ test_that("Summaries are reproducible", { test_summary$Corr <- signif(test_summary$Corr, 1) expect_known_output(print(test_summary), "summary_DFOP_FOCUS_C.txt") - test_summary_2 <- summary(f_sfo_sfo,) + test_summary_2 <- summary(f_sfo_sfo) test_summary_2$fit_version <- "Dummy 0.0 for testing" test_summary_2$fit_Rversion <- "Dummy R version for testing" test_summary_2$date.fit <- "Dummy date for testing" @@ -75,19 +75,23 @@ test_that("Summaries are reproducible", { context("Plotting") -test_that("Plotting mmkin objects is reproducible", { +test_that("Plotting mkinfit and mmkin objects is reproducible", { skip_on_cran() plot_sep_FOCUS_C_SFO <- function() plot_sep(fits[["SFO", "FOCUS_C"]]) mkinparplot_FOCUS_C_SFO <- function() mkinparplot(fits[["SFO", "FOCUS_C"]]) mkinerrplot_FOCUS_C_SFO <- function() mkinerrplot(fits[["SFO", "FOCUS_C"]]) mmkin_FOCUS_C <- function() plot(fits[, "FOCUS_C"]) mmkin_SFO <- function() plot(fits["SFO",]) + plot_res_sfo_sfo <- function() plot_res(f_sfo_sfo) + plot_err_sfo_sfo <- function() plot_err(f_sfo_sfo) 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) vdiffr::expect_doppelganger("mkinerrplot for FOCUS C SFO", mkinerrplot_FOCUS_C_SFO) vdiffr::expect_doppelganger("mmkin plot for FOCUS C", mmkin_FOCUS_C) 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) }) context("AIC calculation") -- cgit v1.2.1