aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/print_mmkin_biphasic_mixed.txt4
-rw-r--r--tests/testthat/print_nlme_biphasic.txt8
-rw-r--r--tests/testthat/setup_script.R39
-rw-r--r--tests/testthat/summary_nlme_biphasic_s.txt42
-rw-r--r--tests/testthat/test_error_models.R1
-rw-r--r--tests/testthat/test_mixed.R13
-rw-r--r--tests/testthat/test_plot.R14
7 files changed, 71 insertions, 50 deletions
diff --git a/tests/testthat/print_mmkin_biphasic_mixed.txt b/tests/testthat/print_mmkin_biphasic_mixed.txt
index 3d92b120..11e11bfc 100644
--- a/tests/testthat/print_mmkin_biphasic_mixed.txt
+++ b/tests/testthat/print_mmkin_biphasic_mixed.txt
@@ -21,6 +21,6 @@ OK: No warnings
Mean fitted parameters:
parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2
- 100.700 -6.299 -0.078 -3.094 -3.954
+ 100.702 -5.347 -0.078 -2.681 -4.366
g_qlogis
- 0.027
+ -0.335
diff --git a/tests/testthat/print_nlme_biphasic.txt b/tests/testthat/print_nlme_biphasic.txt
index 98895d3a..f86bda76 100644
--- a/tests/testthat/print_nlme_biphasic.txt
+++ b/tests/testthat/print_nlme_biphasic.txt
@@ -11,19 +11,19 @@ d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g)
Data:
509 observations of 2 variable(s) grouped in 15 datasets
-Log-likelihood: -1343
+Log-likelihood: -1329
Fixed effects:
list(parent_0 ~ 1, log_k_m1 ~ 1, f_parent_qlogis ~ 1, log_k1 ~ 1, log_k2 ~ 1, g_qlogis ~ 1)
parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2
- 100.37 -6.23 -0.08 -3.22 -4.10
+ 100.43 -5.34 -0.08 -2.90 -4.34
g_qlogis
- -0.10
+ -0.19
Random effects:
Formula: list(parent_0 ~ 1, log_k_m1 ~ 1, f_parent_qlogis ~ 1, log_k1 ~ 1, log_k2 ~ 1, g_qlogis ~ 1)
Level: ds
Structure: Diagonal
parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2 g_qlogis Residual
-StdDev: 1 2e-04 0.3 0.7 0.8 0.3 3
+StdDev: 1 0.1 0.3 0.6 0.5 0.3 3
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
index fd9635d1..2071e05c 100644
--- a/tests/testthat/setup_script.R
+++ b/tests/testthat/setup_script.R
@@ -156,7 +156,7 @@ DFOP_SFO <- mkinmod(
m1 = mkinsub("SFO"),
quiet = TRUE)
dfop_sfo_pop <- list(parent_0 = 100,
- k_m1 = 0.002, f_parent_to_m1 = 0.5,
+ k_m1 = 0.005, f_parent_to_m1 = 0.5,
k1 = 0.05, k2 = 0.01, g = 0.5)
syn_biphasic_parms <- as.matrix(data.frame(
k1 = rlnorm(n_biphasic, log(dfop_sfo_pop$k1), log_sd),
@@ -178,19 +178,27 @@ ds_biphasic <- lapply(ds_biphasic_mean, function(ds) {
})
# Mixed model fits
-mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc")
-sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix")
+saemix_available <- FALSE
+if (requireNamespace("saemix", quietly = TRUE)) {
+ if(packageVersion("saemix") > "3.1.9000") saemix_available <- TRUE
+}
+mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = n_cores)
+mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE, cores = n_cores)
+mmkin_biphasic <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_biphasic, quiet = TRUE, cores = n_cores)
+mmkin_biphasic_mixed <- mixed(mmkin_biphasic)
-mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE)
-dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin")
-dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix")
dfop_nlme_1 <- nlme(mmkin_dfop_1)
-
-mmkin_biphasic <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_biphasic, quiet = TRUE)
-mmkin_biphasic_mixed <- mixed(mmkin_biphasic)
nlme_biphasic <- nlme(mmkin_biphasic)
-saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE)
-saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE)
+
+if (saemix_available) {
+ sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix")
+
+ dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin")
+ dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix")
+
+ saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE)
+ saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE)
+}
ds_uba <- lapply(experimental_data_for_UBA_2019[6:10],
function(x) subset(x$data[c("name", "time", "value")]))
@@ -200,7 +208,10 @@ sfo_sfo_uba <- mkinmod(parent = mkinsub("SFO", "A1"),
dfop_sfo_uba <- mkinmod(parent = mkinsub("DFOP", "A1"),
A1 = mkinsub("SFO"), quiet = TRUE)
f_uba_mmkin <- mmkin(list("SFO-SFO" = sfo_sfo_uba, "DFOP-SFO" = dfop_sfo_uba),
- ds_uba, quiet = TRUE)
+ ds_uba, quiet = TRUE, cores = n_cores)
f_uba_dfop_sfo_mixed <- mixed(f_uba_mmkin[2, ])
-f_uba_sfo_sfo_saem <- saem(f_uba_mmkin["SFO-SFO", ], quiet = TRUE, transformations = "saemix")
-f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix")
+
+if (saemix_available) {
+ f_uba_sfo_sfo_saem <- saem(f_uba_mmkin["SFO-SFO", ], quiet = TRUE, transformations = "saemix")
+ f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix")
+}
diff --git a/tests/testthat/summary_nlme_biphasic_s.txt b/tests/testthat/summary_nlme_biphasic_s.txt
index f9171748..65aead62 100644
--- a/tests/testthat/summary_nlme_biphasic_s.txt
+++ b/tests/testthat/summary_nlme_biphasic_s.txt
@@ -17,15 +17,15 @@ Data:
Model predictions using solution type analytical
-Fitted in test time 0 s using 2 iterations
+Fitted in test time 0 s using 3 iterations
Variance model: Constant variance
Mean of starting values for individual parameters:
parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2
- 100.70 -6.30 -0.08 -3.09 -3.95
+ 100.70 -5.35 -0.08 -2.68 -4.37
g_qlogis
- 0.03
+ -0.33
Fixed degradation parameter values:
value type
@@ -34,40 +34,40 @@ m1_0 0 state
Results:
AIC BIC logLik
- 2711 2766 -1343
+ 2683 2738 -1329
Optimised, transformed parameters with symmetric confidence intervals:
lower est. upper
-parent_0 99.5 100.37 101.23
-log_k_m1 -6.5 -6.23 -5.94
-f_parent_qlogis -0.2 -0.08 0.08
-log_k1 -3.6 -3.22 -2.84
-log_k2 -4.5 -4.10 -3.68
-g_qlogis -0.4 -0.10 0.17
+parent_0 99.6 100.43 101.26
+log_k_m1 -5.5 -5.34 -5.18
+f_parent_qlogis -0.3 -0.08 0.09
+log_k1 -3.2 -2.90 -2.60
+log_k2 -4.6 -4.34 -4.07
+g_qlogis -0.5 -0.19 0.08
Correlation:
prnt_0 lg_k_1 f_prn_ log_k1 log_k2
-log_k_m1 -0.185
-f_parent_qlogis -0.161 0.405
-log_k1 0.056 -0.014 -0.016
-log_k2 0.025 0.011 -0.004 0.026
-g_qlogis -0.032 -0.046 -0.012 -0.109 -0.103
+log_k_m1 -0.177
+f_parent_qlogis -0.164 0.385
+log_k1 0.108 -0.017 -0.025
+log_k2 0.036 0.054 0.008 0.096
+g_qlogis -0.068 -0.110 -0.030 -0.269 -0.267
Random effects:
Formula: list(parent_0 ~ 1, log_k_m1 ~ 1, f_parent_qlogis ~ 1, log_k1 ~ 1, log_k2 ~ 1, g_qlogis ~ 1)
Level: ds
Structure: Diagonal
parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2 g_qlogis Residual
-StdDev: 1 2e-04 0.3 0.7 0.8 0.3 3
+StdDev: 1 0.1 0.3 0.6 0.5 0.3 3
Backtransformed parameters with asymmetric confidence intervals:
lower est. upper
parent_0 1e+02 1e+02 1e+02
-k_m1 1e-03 2e-03 3e-03
+k_m1 4e-03 5e-03 6e-03
f_parent_to_m1 4e-01 5e-01 5e-01
-k1 3e-02 4e-02 6e-02
-k2 1e-02 2e-02 3e-02
+k1 4e-02 6e-02 7e-02
+k2 1e-02 1e-02 2e-02
g 4e-01 5e-01 5e-01
Resulting formation fractions:
@@ -77,5 +77,5 @@ parent_sink 0.5
Estimated disappearance times:
DT50 DT90 DT50back DT50_k1 DT50_k2
-parent 27 105 31 17 42
-m1 352 1171 NA NA NA
+parent 26 131 39 13 53
+m1 144 479 NA NA NA
diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R
index 2a1ffcc1..c11f6712 100644
--- a/tests/testthat/test_error_models.R
+++ b/tests/testthat/test_error_models.R
@@ -56,6 +56,7 @@ test_that("The default error model algorithm finds the best known AIC values for
f_tc_exp_d_3 <- mmkin(c("SFO", "DFOP", "HS"),
lapply(experimental_data_for_UBA_2019, function(x) x$data),
error_model = "tc",
+ cores = n_cores,
quiet = TRUE)
AIC_exp_d_3 <- lapply(f_tc_exp_d_3, AIC)
diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R
index 1e96c338..e9af10e6 100644
--- a/tests/testthat/test_mixed.R
+++ b/tests/testthat/test_mixed.R
@@ -1,6 +1,8 @@
context("Nonlinear mixed-effects models")
-test_that("Parent only models can be fitted using nonlinear mixed effects models", {
+test_that("Parent fits using saemix are correctly implemented", {
+ skip_if(!saemix_available)
+
expect_error(saem(fits), "Only row objects")
# Some fits were done in the setup script
mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100))
@@ -26,7 +28,7 @@ test_that("Parent only models can be fitted using nonlinear mixed effects models
expect_equal(round(s_sfo_s1$confint_back["k_parent", "est."], 3),
round(s_sfo_n$confint_back["k_parent", "est."], 3))
- mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc")
+ mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc", cores = n_cores)
fomc_saem_1 <- saem(mmkin_fomc_1, quiet = TRUE)
ci_fomc_s1 <- summary(fomc_saem_1)$confint_back
@@ -66,7 +68,7 @@ test_that("Parent only models can be fitted using nonlinear mixed effects models
rel_diff_2 <- (s_dfop_s2$confint_back[, "est."] - dfop_pop) / dfop_pop
expect_true(all(rel_diff_2 < 0.12))
- mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const")
+ mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const", cores = n_cores)
hs_saem_1 <- saem(mmkin_hs_1, quiet = TRUE)
ci_hs_s1 <- summary(hs_saem_1)$confint_back
@@ -88,10 +90,12 @@ test_that("Print methods work", {
expect_known_output(print(fits, digits = 2), "print_mmkin_parent.txt")
expect_known_output(print(mmkin_biphasic_mixed, digits = 2), "print_mmkin_biphasic_mixed.txt")
expect_known_output(print(nlme_biphasic, digits = 1), "print_nlme_biphasic.txt")
+
+ skip_if(!saemix_available)
expect_known_output(print(sfo_saem_1, digits = 1), "print_sfo_saem_1.txt")
})
-test_that("nlme results are reproducible", {
+test_that("nlme results are reproducible to some degree", {
test_summary <- summary(nlme_biphasic)
test_summary$nlmeversion <- "Dummy 0.0 for testing"
@@ -111,6 +115,7 @@ test_that("nlme results are reproducible", {
test_that("saem results are reproducible for biphasic fits", {
+ skip_if(!saemix_available)
test_summary <- summary(saem_biphasic_s)
test_summary$saemixversion <- "Dummy 0.0 for testing"
test_summary$mkinversion <- "Dummy 0.0 for testing"
diff --git a/tests/testthat/test_plot.R b/tests/testthat/test_plot.R
index 75d401a3..1c95d069 100644
--- a/tests/testthat/test_plot.R
+++ b/tests/testthat/test_plot.R
@@ -35,8 +35,10 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", {
plot_biphasic_mmkin <- function() plot(f_uba_dfop_sfo_mixed)
vdiffr::expect_doppelganger("mixed model fit for mmkin object", plot_biphasic_mmkin)
- plot_biphasic_saem_s <- function() plot(f_uba_dfop_sfo_saem)
- vdiffr::expect_doppelganger("mixed model fit for saem object with saemix transformations", plot_biphasic_saem_s)
+ if (saemix_available) {
+ plot_biphasic_saem_s <- function() plot(f_uba_dfop_sfo_saem)
+ vdiffr::expect_doppelganger("mixed model fit for saem object with saemix transformations", plot_biphasic_saem_s)
+ }
skip_on_travis()
@@ -46,10 +48,12 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", {
#plot_biphasic_mmkin <- function() plot(mixed(mmkin_biphasic))
# Biphasic fits with lots of data and fits have lots of potential for differences
plot_biphasic_nlme <- function() plot(nlme_biphasic)
- #plot_biphasic_saem_s <- function() plot(saem_biphasic_s)
- plot_biphasic_saem_m <- function() plot(saem_biphasic_m)
+ if (saemix_available) {
+ #plot_biphasic_saem_s <- function() plot(saem_biphasic_s)
+ plot_biphasic_saem_m <- function() plot(saem_biphasic_m)
- vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_biphasic_saem_m)
+ vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_biphasic_saem_m)
+ }
# different results when working with eigenvalues
plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE)

Contact - Imprint