aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-04-09 10:35:59 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-04-09 10:35:59 +0200
commite4e54169ab3961c354f580bc489d150299038367 (patch)
tree293790e7db06d0d808ceabc69ee4711294d928b6 /tests/testthat
parent23461dddcc6a1858f1c9c9052512f22485d08842 (diff)
Improve test coverage and fix nlme test
No idea why I had to do more assignments all of a sudden in test_nlme.R
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/FOCUS_2006_D.csf2
-rw-r--r--tests/testthat/test_nlme.R9
-rw-r--r--tests/testthat/test_plots_summary_twa.R10
-rw-r--r--tests/testthat/test_residuals.R9
4 files changed, 25 insertions, 5 deletions
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index 118f61f4..de5ee0a4 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: 2020-04-08
+Date: 2020-04-09
Optimiser: IRLS
[Data]
diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R
index 0d1fcd6d..efbc231a 100644
--- a/tests/testthat/test_nlme.R
+++ b/tests/testthat/test_nlme.R
@@ -31,6 +31,7 @@ test_that("nlme_function works correctly", {
# The following assignment was introduced for nlme as evaluated by testthat
# to find the function
assign("nlme_f", nlme_f, pos = globalenv())
+ assign("sampling_times", sampling_times, pos = globalenv())
m_nlme_raw <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink),
data = grouped_data,
@@ -68,7 +69,6 @@ test_that("nlme_function works correctly", {
test_that("nlme_function works correctly in other cases", {
dt50_in <- c(400, 800, 1200, 1600, 2000)
- dt50_in_geomean <- geomean(dt50_in)
k_in <- log(2) / dt50_in
SFO <- mkinmod(parent = mkinsub("SFO"))
pred_sfo <- function(k) {
@@ -85,15 +85,16 @@ test_that("nlme_function works correctly in other cases", {
names(ds_me_sfo_5) <- paste("Dataset", 1:15)
dimnames(ds_me_sfo_5) <- list(Subset = 1:3, DT50 = dt50_in)
- f_me_sfo_5 <- mmkin("SFO", ds_me_sfo_5)
+ f_me_sfo_5 <- mmkin("SFO", ds_me_sfo_5, quiet = TRUE)
ds_me_sfo_5_grouped_mkin <- nlme_data(f_me_sfo_5)
ds_me_sfo_5_mean_dp <- mean_degparms(f_me_sfo_5)
me_sfo_function <- nlme_function(f_me_sfo_5)
+ assign("me_sfo_function", me_sfo_function, pos = globalenv())
f_nlme_sfo_5_all_mkin <- nlme(value ~ me_sfo_function(name, time,
parent_0, log_k_parent_sink),
- data = ds_me_sfo_5_grouped,
+ data = ds_me_sfo_5_grouped_mkin,
fixed = parent_0 + log_k_parent_sink ~ 1,
random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
start = ds_me_sfo_5_mean_dp)
@@ -109,7 +110,7 @@ test_that("nlme_function works correctly in other cases", {
# With less ideal starting values we get fits with lower AIC (not shown)
f_nlme_sfo_5_all_mkin_nostart <- nlme(value ~ me_sfo_function(name, time,
parent_0, log_k_parent_sink),
- data = ds_me_sfo_5_grouped,
+ data = ds_me_sfo_5_grouped_mkin,
fixed = parent_0 + log_k_parent_sink ~ 1,
random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
start = c(parent_0 = 100, log_k_parent_sink = log(0.1)))
diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R
index 77144665..c04192c1 100644
--- a/tests/testthat/test_plots_summary_twa.R
+++ b/tests/testthat/test_plots_summary_twa.R
@@ -99,6 +99,12 @@ test_that("Plotting mkinfit and mmkin objects is reproducible", {
mkinerrplot_FOCUS_C_SFO <- function() mkinerrplot(fits[["SFO", "FOCUS_C"]])
mmkin_FOCUS_C <- function() plot(fits[, "FOCUS_C"])
mmkin_SFO <- function() plot(fits["SFO",])
+ fit_D_obs_eigen <- suppressWarnings(mkinfit(SFO_SFO, FOCUS_2006_D, error_model = "obs", quiet = TRUE))
+ fit_C_tc <- mkinfit("SFO", FOCUS_2006_C, error_model = "tc", quiet = TRUE)
+
+ plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE)
+ plot_errmod_fit_C_tc <- function() plot_err(fit_C_tc)
+
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)
@@ -111,6 +117,10 @@ test_that("Plotting mkinfit and mmkin objects is reproducible", {
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_errmod with FOCUS D obs eigen", plot_errmod_fit_D_obs_eigen)
+ vdiffr::expect_doppelganger("plot_errmod with FOCUS C tc", plot_errmod_fit_C_tc)
+ skip_on_travis() # Still not working on Travis, presumably because of deSolve producing
+ # different results when not working with a compiled model
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_tc", plot_errmod_fit_tc_1)
diff --git a/tests/testthat/test_residuals.R b/tests/testthat/test_residuals.R
index 35a143f6..e6e54dd5 100644
--- a/tests/testthat/test_residuals.R
+++ b/tests/testthat/test_residuals.R
@@ -7,4 +7,13 @@ test_that("Residuals are correctly returned", {
expect_equivalent(
residuals(f, standardized = TRUE)[1:3],
c(-0.4171812, 1.4584875, -1.0472450), tolerance = 0.0001)
+
+ expect_equivalent(
+ residuals(fit_obs_1, standardized = TRUE)[1:3],
+ c(-0.21771169, -0.33576060, 2.02836138))
+
+ expect_equivalent(
+ residuals(fit_tc_1, standardized = TRUE)[1:3],
+ c(-0.2474499, -0.3794267, 2.2749216),
+ tolerance = 1e-7)
})

Contact - Imprint