aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/print_mmkin_biphasic_mixed.txt6
-rw-r--r--tests/testthat/print_nlme_biphasic.txt10
-rw-r--r--tests/testthat/print_sfo_saem_1.txt16
-rw-r--r--tests/testthat/setup_script.R33
-rw-r--r--tests/testthat/summary_nlme_biphasic_s.txt46
-rw-r--r--tests/testthat/summary_saem_biphasic_s.txt77
-rw-r--r--tests/testthat/test_mixed.R145
-rw-r--r--tests/testthat/test_nlme.R2
-rw-r--r--tests/testthat/test_plot.R11
9 files changed, 305 insertions, 41 deletions
diff --git a/tests/testthat/print_mmkin_biphasic_mixed.txt b/tests/testthat/print_mmkin_biphasic_mixed.txt
index 11e11bfc..0b23fe58 100644
--- a/tests/testthat/print_mmkin_biphasic_mixed.txt
+++ b/tests/testthat/print_mmkin_biphasic_mixed.txt
@@ -8,7 +8,7 @@ d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g)
exp(-k2 * time))) * parent - k_m1 * m1
Data:
-509 observations of 2 variable(s) grouped in 15 datasets
+507 observations of 2 variable(s) grouped in 15 datasets
<mmkin> object
Status of individual fits:
@@ -21,6 +21,6 @@ OK: No warnings
Mean fitted parameters:
parent_0 log_k_m1 f_parent_qlogis log_k1 log_k2
- 100.702 -5.347 -0.078 -2.681 -4.366
+ 100.667 -5.378 -0.095 -2.743 -4.510
g_qlogis
- -0.335
+ -0.180
diff --git a/tests/testthat/print_nlme_biphasic.txt b/tests/testthat/print_nlme_biphasic.txt
index f86bda76..f40d438d 100644
--- a/tests/testthat/print_nlme_biphasic.txt
+++ b/tests/testthat/print_nlme_biphasic.txt
@@ -9,21 +9,21 @@ d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g)
exp(-k2 * time))) * parent - k_m1 * m1
Data:
-509 observations of 2 variable(s) grouped in 15 datasets
+507 observations of 2 variable(s) grouped in 15 datasets
-Log-likelihood: -1329
+Log-likelihood: -1326
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.43 -5.34 -0.08 -2.90 -4.34
+ 100.7 -5.4 -0.1 -2.8 -4.5
g_qlogis
- -0.19
+ -0.1
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 0.1 0.3 0.6 0.5 0.3 3
+StdDev: 1 0.03 0.3 0.3 0.2 0.3 3
diff --git a/tests/testthat/print_sfo_saem_1.txt b/tests/testthat/print_sfo_saem_1.txt
index d341e9e7..0c0e32ce 100644
--- a/tests/testthat/print_sfo_saem_1.txt
+++ b/tests/testthat/print_sfo_saem_1.txt
@@ -3,19 +3,19 @@ Structural model:
d_parent/dt = - k_parent * parent
Data:
-264 observations of 1 variable(s) grouped in 15 datasets
+262 observations of 1 variable(s) grouped in 15 datasets
Likelihood computed by importance sampling
AIC BIC logLik
- 1320 1324 -654
+ 1310 1315 -649
Fitted parameters:
estimate lower upper
-parent_0 1e+02 98.78 1e+02
+parent_0 1e+02 98.87 1e+02
k_parent 4e-02 0.03 4e-02
-Var.parent_0 8e-01 -1.76 3e+00
-Var.k_parent 9e-02 0.03 2e-01
-a.1 9e-01 0.70 1e+00
-b.1 4e-02 0.03 4e-02
-SD.parent_0 9e-01 -0.57 2e+00
+Var.parent_0 1e+00 -1.72 5e+00
+Var.k_parent 1e-01 0.03 2e-01
+a.1 9e-01 0.75 1e+00
+b.1 5e-02 0.04 5e-02
+SD.parent_0 1e+00 -0.12 3e+00
SD.k_parent 3e-01 0.20 4e-01
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
index 547b2d6c..96e865d4 100644
--- a/tests/testthat/setup_script.R
+++ b/tests/testthat/setup_script.R
@@ -106,6 +106,7 @@ const <- function(value) 2
set.seed(123456)
SFO <- mkinmod(parent = mkinsub("SFO"))
k_parent = rlnorm(n, log(0.03), log_sd)
+set.seed(123456)
ds_sfo <- lapply(1:n, function(i) {
ds_mean <- mkinpredict(SFO, c(k_parent = k_parent[i]),
c(parent = 100), sampling_times)
@@ -118,6 +119,7 @@ fomc_pop <- list(parent_0 = 100, alpha = 2, beta = 8)
fomc_parms <- as.matrix(data.frame(
alpha = rlnorm(n, log(fomc_pop$alpha), 0.4),
beta = rlnorm(n, log(fomc_pop$beta), 0.2)))
+set.seed(123456)
ds_fomc <- lapply(1:3, function(i) {
ds_mean <- mkinpredict(FOMC, fomc_parms[i, ],
c(parent = 100), sampling_times)
@@ -131,6 +133,7 @@ dfop_parms <- as.matrix(data.frame(
k1 = rlnorm(n, log(dfop_pop$k1), log_sd),
k2 = rlnorm(n, log(dfop_pop$k2), log_sd),
g = plogis(rnorm(n, qlogis(dfop_pop$g), log_sd))))
+set.seed(123456)
ds_dfop <- lapply(1:n, function(i) {
ds_mean <- mkinpredict(DFOP, dfop_parms[i, ],
c(parent = dfop_pop$parent_0), sampling_times)
@@ -144,6 +147,7 @@ hs_parms <- as.matrix(data.frame(
k1 = rlnorm(n, log(hs_pop$k1), log_sd),
k2 = rlnorm(n, log(hs_pop$k2), log_sd),
tb = rlnorm(n, log(hs_pop$tb), 0.1)))
+set.seed(123456)
ds_hs <- lapply(1:10, function(i) {
ds_mean <- mkinpredict(HS, hs_parms[i, ],
c(parent = hs_pop$parent_0), sampling_times)
@@ -171,6 +175,7 @@ ds_biphasic_mean <- lapply(1:n_biphasic,
c(parent = 100, m1 = 0), sampling_times)
}
)
+set.seed(123456)
ds_biphasic <- lapply(ds_biphasic_mean, function(ds) {
add_err(ds,
sdfunc = function(value) sqrt(err_1$const^2 + value^2 * err_1$prop^2),
@@ -178,6 +183,10 @@ ds_biphasic <- lapply(ds_biphasic_mean, function(ds) {
})
# Mixed model fits
+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)
@@ -186,6 +195,26 @@ mmkin_biphasic_mixed <- mixed(mmkin_biphasic)
dfop_nlme_1 <- nlme(mmkin_dfop_1)
nlme_biphasic <- nlme(mmkin_biphasic)
+if (saemix_available) {
+ sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix")
+
+ # With default control parameters, we do not get good results with mkin
+ # transformations here
+ dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin",
+ control = list(
+ displayProgress = FALSE, print = FALSE, save = FALSE, save.graphs = FALSE,
+ rw.init = 1, nbiter.saemix = c(600, 100))
+ )
+ dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix",
+ control = list(
+ displayProgress = FALSE, print = FALSE, save = FALSE, save.graphs = FALSE,
+ rw.init = 0.5, nbiter.saemix = c(600, 100))
+ )
+
+ 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")]))
names(ds_uba) <- paste("Dataset", 6:10)
@@ -197,3 +226,7 @@ f_uba_mmkin <- mmkin(list("SFO-SFO" = sfo_sfo_uba, "DFOP-SFO" = dfop_sfo_uba),
ds_uba, quiet = TRUE, cores = n_cores)
f_uba_dfop_sfo_mixed <- mixed(f_uba_mmkin[2, ])
+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 65aead62..86049775 100644
--- a/tests/testthat/summary_nlme_biphasic_s.txt
+++ b/tests/testthat/summary_nlme_biphasic_s.txt
@@ -13,19 +13,19 @@ d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g)
exp(-k2 * time))) * parent - k_m1 * m1
Data:
-509 observations of 2 variable(s) grouped in 15 datasets
+507 observations of 2 variable(s) grouped in 15 datasets
Model predictions using solution type analytical
-Fitted in test time 0 s using 3 iterations
+Fitted in test time 0 s using 4 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 -5.35 -0.08 -2.68 -4.37
+ 100.67 -5.38 -0.09 -2.74 -4.51
g_qlogis
- -0.33
+ -0.18
Fixed degradation parameter values:
value type
@@ -34,40 +34,40 @@ m1_0 0 state
Results:
AIC BIC logLik
- 2683 2738 -1329
+ 2678 2733 -1326
Optimised, transformed parameters with symmetric confidence intervals:
- lower est. upper
-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
+ lower est. upper
+parent_0 99.8 100.7 101.62
+log_k_m1 -5.6 -5.4 -5.25
+f_parent_qlogis -0.3 -0.1 0.06
+log_k1 -3.0 -2.8 -2.57
+log_k2 -4.7 -4.5 -4.35
+g_qlogis -0.4 -0.1 0.17
Correlation:
prnt_0 lg_k_1 f_prn_ log_k1 log_k2
-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
+log_k_m1 -0.167
+f_parent_qlogis -0.145 0.380
+log_k1 0.170 0.005 -0.026
+log_k2 0.083 0.168 0.032 0.365
+g_qlogis -0.088 -0.170 -0.044 -0.472 -0.631
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 0.1 0.3 0.6 0.5 0.3 3
+StdDev: 1 0.03 0.3 0.3 0.2 0.3 3
Backtransformed parameters with asymmetric confidence intervals:
lower est. upper
parent_0 1e+02 1e+02 1e+02
-k_m1 4e-03 5e-03 6e-03
+k_m1 4e-03 4e-03 5e-03
f_parent_to_m1 4e-01 5e-01 5e-01
-k1 4e-02 6e-02 7e-02
-k2 1e-02 1e-02 2e-02
+k1 5e-02 6e-02 8e-02
+k2 9e-03 1e-02 1e-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 26 131 39 13 53
-m1 144 479 NA NA NA
+parent 25 150 45 11 63
+m1 154 512 NA NA NA
diff --git a/tests/testthat/summary_saem_biphasic_s.txt b/tests/testthat/summary_saem_biphasic_s.txt
new file mode 100644
index 00000000..8dfae367
--- /dev/null
+++ b/tests/testthat/summary_saem_biphasic_s.txt
@@ -0,0 +1,77 @@
+saemix version used for fitting: Dummy 0.0 for testing
+mkin version used for pre-fitting: Dummy 0.0 for testing
+R version used for fitting: Dummy R version for testing
+Date of fit: Dummy date for testing
+Date of summary: Dummy date for testing
+
+Equations:
+d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 *
+ time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time)))
+ * parent
+d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g)
+ * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) *
+ exp(-k2 * time))) * parent - k_m1 * m1
+
+Data:
+507 observations of 2 variable(s) grouped in 15 datasets
+
+Model predictions using solution type analytical
+
+Fitted in test time 0 s using 300, 100 iterations
+
+Variance model: Constant variance
+
+Mean of starting values for individual parameters:
+ parent_0 k_m1 f_parent_to_m1 k1 k2
+ 1.0e+02 4.6e-03 4.8e-01 6.4e-02 1.1e-02
+ g
+ 4.6e-01
+
+Fixed degradation parameter values:
+None
+
+Results:
+
+Likelihood computed by importance sampling
+ AIC BIC logLik
+ 2702 2711 -1338
+
+Optimised parameters:
+ est. lower upper
+parent_0 1.0e+02 1.0e+02 1.0e+02
+k_m1 4.7e-03 3.9e-03 5.6e-03
+f_parent_to_m1 4.8e-01 4.3e-01 5.2e-01
+k1 4.8e-02 3.1e-02 6.5e-02
+k2 1.3e-02 8.7e-03 1.7e-02
+g 5.0e-01 4.1e-01 5.8e-01
+
+Correlation:
+ prnt_0 k_m1 f_p__1 k1 k2
+k_m1 -0.152
+f_parent_to_m1 -0.143 0.366
+k1 0.097 -0.014 -0.021
+k2 0.022 0.083 0.023 0.101
+g -0.084 -0.144 -0.044 -0.303 -0.364
+
+Random effects:
+ est. lower upper
+SD.parent_0 1.22 0.316 2.12
+SD.k_m1 0.15 -0.079 0.38
+SD.f_parent_to_m1 0.32 0.191 0.44
+SD.k1 0.66 0.416 0.90
+SD.k2 0.59 0.368 0.80
+SD.g 0.16 -0.373 0.70
+
+Variance model:
+ est. lower upper
+a.1 2.9 2.7 3
+
+Resulting formation fractions:
+ ff
+parent_m1 0.48
+parent_sink 0.52
+
+Estimated disappearance times:
+ DT50 DT90 DT50back DT50_k1 DT50_k2
+parent 26 127 38 14 54
+m1 146 485 NA NA NA
diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R
index 6f28d0c3..5d15530b 100644
--- a/tests/testthat/test_mixed.R
+++ b/tests/testthat/test_mixed.R
@@ -1,9 +1,104 @@
context("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))
+ expect_error(update(mmkin_sfo_1, models = c("SFOOO")), "Please supply models.*")
+
+ sfo_saem_2 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "mkin")
+ sfo_saem_3 <- expect_error(saem(mmkin_sfo_2, quiet = TRUE), "at least two parameters")
+ s_sfo_s1 <- summary(sfo_saem_1)
+ s_sfo_s2 <- summary(sfo_saem_2)
+
+ sfo_nlme_1 <- expect_warning(nlme(mmkin_sfo_1), "not converge")
+ s_sfo_n <- summary(sfo_nlme_1)
+
+ # Compare with input
+ expect_equal(round(s_sfo_s2$confint_ranef["SD.log_k_parent", "est."], 1), 0.3)
+ # k_parent is a bit different from input 0.03 here
+ expect_equal(round(s_sfo_s1$confint_back["k_parent", "est."], 3), 0.035)
+ expect_equal(round(s_sfo_s2$confint_back["k_parent", "est."], 3), 0.035)
+
+ # But the result is pretty unanimous between methods
+ expect_equal(round(s_sfo_s1$confint_back["k_parent", "est."], 3),
+ round(s_sfo_s2$confint_back["k_parent", "est."], 3))
+ 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", cores = n_cores)
+ fomc_saem_1 <- saem(mmkin_fomc_1, quiet = TRUE)
+ ci_fomc_s1 <- summary(fomc_saem_1)$confint_back
+
+ fomc_pop <- as.numeric(fomc_pop)
+ expect_true(all(ci_fomc_s1[, "lower"] < fomc_pop))
+ expect_true(all(ci_fomc_s1[, "upper"] > fomc_pop))
+
+ mmkin_fomc_2 <- update(mmkin_fomc_1, state.ini = 100, fixed_initials = "parent")
+ fomc_saem_2 <- saem(mmkin_fomc_2, quiet = TRUE, transformations = "mkin")
+ ci_fomc_s2 <- summary(fomc_saem_2)$confint_back
+
+ expect_true(all(ci_fomc_s2[, "lower"] < fomc_pop[2:3]))
+ expect_true(all(ci_fomc_s2[, "upper"] > fomc_pop[2:3]))
+
+ s_dfop_s1 <- summary(dfop_saemix_1)
+ s_dfop_s2 <- summary(dfop_saemix_2)
+ s_dfop_n <- summary(dfop_nlme_1)
+
+ dfop_pop <- as.numeric(dfop_pop)
+ expect_true(all(s_dfop_s1$confint_back[, "lower"] < dfop_pop))
+ expect_true(all(s_dfop_s1$confint_back[, "upper"] > dfop_pop))
+ expect_true(all(s_dfop_s2$confint_back[, "lower"] < dfop_pop))
+ expect_true(all(s_dfop_s2$confint_back[, "upper"] > dfop_pop))
+
+ dfop_mmkin_means_trans_tested <- mean_degparms(mmkin_dfop_1, test_log_parms = TRUE)
+ dfop_mmkin_means_trans <- apply(parms(mmkin_dfop_1, transformed = TRUE), 1, mean)
+
+ dfop_mmkin_means_tested <- backtransform_odeparms(dfop_mmkin_means_trans_tested, mmkin_dfop_1$mkinmod)
+ dfop_mmkin_means <- backtransform_odeparms(dfop_mmkin_means_trans, mmkin_dfop_1$mkinmod)
+
+ # We get < 20% deviations for parent_0 and k1 by averaging the transformed parameters
+ # If we average only parameters passing the t-test, the deviation for k2 is also < 20%
+ rel_diff_mmkin <- (dfop_mmkin_means - dfop_pop) / dfop_pop
+ rel_diff_mmkin_tested <- (dfop_mmkin_means_tested - dfop_pop) / dfop_pop
+ expect_true(all(rel_diff_mmkin[c("parent_0", "k1")] < 0.20))
+ expect_true(all(rel_diff_mmkin_tested[c("parent_0", "k1", "k2")] < 0.20))
+
+ # We get < 30% deviations with transformations made in mkin
+ rel_diff_1 <- (s_dfop_s1$confint_back[, "est."] - dfop_pop) / dfop_pop
+ expect_true(all(rel_diff_1 < 0.5))
+
+ # We get < 20% deviations with transformations made in saemix
+ rel_diff_2 <- (s_dfop_s2$confint_back[, "est."] - dfop_pop) / dfop_pop
+ expect_true(all(rel_diff_2 < 0.2))
+
+ 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
+
+ hs_pop <- as.numeric(hs_pop)
+ # expect_true(all(ci_hs_s1[, "lower"] < hs_pop)) # k1 is overestimated
+ expect_true(all(ci_hs_s1[, "upper"] > hs_pop))
+
+ mmkin_hs_2 <- update(mmkin_hs_1, state.ini = 100, fixed_initials = "parent")
+ hs_saem_2 <- saem(mmkin_hs_2, quiet = TRUE)
+ ci_hs_s2 <- summary(hs_saem_2)$confint_back
+
+ #expect_true(all(ci_hs_s2[, "lower"] < hs_pop[2:4])) # k1 again overestimated
+ expect_true(all(ci_hs_s2[, "upper"] > hs_pop[2:4]))
+
+ # HS would likely benefit from implemenation of transformations = "saemix"
+})
+
test_that("Print methods work", {
expect_known_output(print(fits[, 2:3], 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 to some degree", {
@@ -18,8 +113,56 @@ test_that("nlme results are reproducible to some degree", {
expect_known_output(print(test_summary, digits = 1), "summary_nlme_biphasic_s.txt")
+ # k1 just fails the first test (lower bound of the ci), so we need to excluded it
+ dfop_no_k1 <- c("parent_0", "k_m1", "f_parent_to_m1", "k2", "g")
+ dfop_sfo_pop_no_k1 <- as.numeric(dfop_sfo_pop[dfop_no_k1])
dfop_sfo_pop <- as.numeric(dfop_sfo_pop)
+
ci_dfop_sfo_n <- summary(nlme_biphasic)$confint_back
- # expect_true(all(ci_dfop_sfo_n[, "lower"] < dfop_sfo_pop)) # k2 is overestimated
+
+ expect_true(all(ci_dfop_sfo_n[dfop_no_k1, "lower"] < dfop_sfo_pop_no_k1))
expect_true(all(ci_dfop_sfo_n[, "upper"] > dfop_sfo_pop))
})
+
+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"
+ test_summary$Rversion <- "Dummy R version for testing"
+ test_summary$date.fit <- "Dummy date for testing"
+ test_summary$date.summary <- "Dummy date for testing"
+ test_summary$time <- c(elapsed = "test time 0")
+
+ expect_known_output(print(test_summary, digits = 2), "summary_saem_biphasic_s.txt")
+
+ dfop_sfo_pop <- as.numeric(dfop_sfo_pop)
+ no_k1 <- c(1, 2, 3, 5, 6)
+ no_k2 <- c(1, 2, 3, 4, 6)
+ no_k1_k2 <- c(1, 2, 3, 6)
+
+ ci_dfop_sfo_s_s <- summary(saem_biphasic_s)$confint_back
+ # k1 and k2 are overestimated
+ expect_true(all(ci_dfop_sfo_s_s[no_k1_k2, "lower"] < dfop_sfo_pop[no_k1_k2]))
+ expect_true(all(ci_dfop_sfo_s_s[, "upper"] > dfop_sfo_pop))
+
+ # k1 and k2 are not fitted well
+ ci_dfop_sfo_s_m <- summary(saem_biphasic_m)$confint_back
+ expect_true(all(ci_dfop_sfo_s_m[no_k2, "lower"] < dfop_sfo_pop[no_k2]))
+ expect_true(all(ci_dfop_sfo_s_m[no_k1, "upper"] > dfop_sfo_pop[no_k1]))
+
+ # I tried to only do few iterations in routine tests as this is so slow
+ # but then deSolve fails at some point (presumably at the switch between
+ # the two types of iterations)
+ #saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve",
+ # control = list(nbiter.saemix = c(10, 5), nbiter.burn = 5), quiet = TRUE)
+
+ skip("Fitting with saemix takes around 10 minutes when using deSolve")
+ saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve", quiet = TRUE)
+
+ # As with the analytical solution, k1 and k2 are not fitted well
+ ci_dfop_sfo_s_d <- summary(saem_biphasic_2)$confint_back
+ expect_true(all(ci_dfop_sfo_s_d[no_k2, "lower"] < dfop_sfo_pop[no_k2]))
+ expect_true(all(ci_dfop_sfo_s_d[no_k1, "upper"] > dfop_sfo_pop[no_k1]))
+})
diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R
index 989914da..a3bc9413 100644
--- a/tests/testthat/test_nlme.R
+++ b/tests/testthat/test_nlme.R
@@ -1,4 +1,4 @@
-context("Nonlinear mixed-effects models")
+context("Nonlinear mixed-effects models with nlme")
library(nlme)
diff --git a/tests/testthat/test_plot.R b/tests/testthat/test_plot.R
index 0bf3ee66..1c95d069 100644
--- a/tests/testthat/test_plot.R
+++ b/tests/testthat/test_plot.R
@@ -35,6 +35,11 @@ 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)
+ 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()
plot_biphasic_nlme <- function() plot(dfop_nlme_1)
@@ -43,6 +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)
+ 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)
+ }
# different results when working with eigenvalues
plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE)

Contact - Imprint