aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/test_mixed.R
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat/test_mixed.R')
-rw-r--r--tests/testthat/test_mixed.R55
1 files changed, 47 insertions, 8 deletions
diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R
index 644cccc1..6fc6c2f0 100644
--- a/tests/testthat/test_mixed.R
+++ b/tests/testthat/test_mixed.R
@@ -1,14 +1,15 @@
context("Nonlinear mixed effects models")
test_that("Parent only models can be fitted using nonlinear mixed effects models", {
+ 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_saemix_2 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "mkin")
- sfo_saemix_3 <- expect_error(saem(mmkin_sfo_2, quiet = TRUE), "at least two parameters")
- s_sfo_s1 <- summary(sfo_saemix_1)
- s_sfo_s2 <- summary(sfo_saemix_2)
+ 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)
@@ -25,6 +26,21 @@ 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")
+ 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)
@@ -35,14 +51,37 @@ test_that("Parent only models can be fitted using nonlinear mixed effects models
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 <- apply(parms(mmkin_dfop_1, transformed = TRUE), 1, mean)
+ dfop_mmkin_means <- backtransform_odeparms(dfop_mmkin_means_trans, mmkin_dfop_1$mkinmod)
+
+ # We get < 22% deviations by averaging the transformed parameters
+ rel_diff_mmkin <- (dfop_mmkin_means - dfop_pop) / dfop_pop
+ expect_true(all(rel_diff_mmkin < 0.22))
- # We get < 20% deviations with transformations made in mkin
+ # We get < 50% 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.2))
+ expect_true(all(rel_diff_1 < 0.5))
- # We get < 8% deviations with transformations made in saemix
+ # We get < 12% 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.08))
+ expect_true(all(rel_diff_2 < 0.12))
+
+ mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const")
+ 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", {

Contact - Imprint