aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/test_nlme.R59
-rw-r--r--tests/testthat/test_plots_summary_twa.R1
2 files changed, 59 insertions, 1 deletions
diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R
index 31db92e1..0d1fcd6d 100644
--- a/tests/testthat/test_nlme.R
+++ b/tests/testthat/test_nlme.R
@@ -64,3 +64,62 @@ test_that("nlme_function works correctly", {
expect_silent(tmp <- update(m_nlme_mkin))
})
+
+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) {
+ mkinpredict(SFO,
+ c(k_parent_sink = k),
+ c(parent = 100),
+ sampling_times)
+ }
+ ds_me_sfo <- mapply(pred_sfo, k_in, SIMPLIFY = FALSE)
+ add_err_5 <- function(i) {
+ add_err(ds_me_sfo[[i]], sdfunc = function(value) 5, n = 3, seed = i + 1)
+ }
+ ds_me_sfo_5 <- sapply(1:5, add_err_5)
+ 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)
+
+ 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)
+
+ 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,
+ fixed = parent_0 + log_k_parent_sink ~ 1,
+ random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
+ start = ds_me_sfo_5_mean_dp)
+
+ f_nlme_sfo_5 <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink),
+ 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)
+
+ expect_equal(f_nlme_sfo_5_all_mkin$coefficients, f_nlme_sfo_5$coefficients)
+
+ # 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,
+ 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)))
+
+ f_nlme_sfo_5_nostart <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink),
+ 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)))
+
+ expect_equal(f_nlme_sfo_5_all_mkin_nostart$coefficients, f_nlme_sfo_5_nostart$coefficients)
+
+})
diff --git a/tests/testthat/test_plots_summary_twa.R b/tests/testthat/test_plots_summary_twa.R
index 5917dd6e..77144665 100644
--- a/tests/testthat/test_plots_summary_twa.R
+++ b/tests/testthat/test_plots_summary_twa.R
@@ -111,7 +111,6 @@ 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)
- skip_on_travis() # No idea why the following are different on Travis
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)

Contact - Imprint