aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-10-26 14:13:09 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2022-10-26 14:13:09 +0200
commit0e9220c6b9132602a3d69e4be582a02da8b07822 (patch)
tree327aed436a0bfc4df33e42f55fb2d56b04785a85 /tests/testthat
parentc615bd685d6a109306e68ea7b0516ba3d6805114 (diff)
Really test anova output, test covariates
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/anova_sfo_saem.txt7
-rw-r--r--tests/testthat/test_saemix_parent.R20
2 files changed, 22 insertions, 5 deletions
diff --git a/tests/testthat/anova_sfo_saem.txt b/tests/testthat/anova_sfo_saem.txt
index e69de29b..4a21e81f 100644
--- a/tests/testthat/anova_sfo_saem.txt
+++ b/tests/testthat/anova_sfo_saem.txt
@@ -0,0 +1,7 @@
+Data: 262 observations of 1 variable(s) grouped in 15 datasets
+
+ npar AIC BIC Lik Chisq Df Pr(>Chisq)
+sfo_saem_1_reduced 5 1310 1313 -650
+sfo_saem_1_reduced_mkin 5 1310 1313 -650 0 0
+sfo_saem_1 6 1312 1316 -650 0 1 1
+sfo_saem_1_mkin 6 1310 1315 -649 1 0
diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R
index 193dcdcd..39efa18f 100644
--- a/tests/testthat/test_saemix_parent.R
+++ b/tests/testthat/test_saemix_parent.R
@@ -53,11 +53,21 @@ test_that("Parent fits using saemix are correctly implemented", {
expect_equal(round(s_sfo_nlme_1$confint_back["k_parent", "est."], 3),
round(s_sfo_saem_1$confint_back["k_parent", "est."], 3))
- # Compare fits
- expect_known_output(anova(sfo_saem_1, sfo_saem_1_reduced,
- sfo_saem_1_mkin, sfo_saem_1_reduced_mkin, test = TRUE),
- file = "anova_sfo_saem.txt"
- )
+ # Compare fits with heavy rounding to avoid platform dependent results
+ anova_sfo <- anova(
+ sfo_saem_1, sfo_saem_1_reduced,
+ sfo_saem_1_mkin, sfo_saem_1_reduced_mkin,
+ test = TRUE)
+ anova_sfo_rounded <- round(anova_sfo, 0)
+ expect_known_output(print(anova_sfo_rounded), file = "anova_sfo_saem.txt")
+
+ # Check the influence of an invented covariate
+ set.seed(123456) # In my first attempt I hit a false positive by chance...
+ pH <- data.frame(pH = runif(15, 5, 8), row.names = as.character(1:15))
+ sfo_saem_pH <- update(sfo_saem_1_reduced_mkin, covariates = pH,
+ covariate_models = list(log_k_parent ~ pH))
+ # We expect that this is not significantly better, as the covariate values were completely random
+ expect_true(anova(sfo_saem_1_reduced_mkin, sfo_saem_pH, test = TRUE)[2, "Pr(>Chisq)"] > 0.05)
# FOMC
mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc", cores = n_cores)

Contact - Imprint