aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/test_FOCUS_D_UBA_expertise.R2
-rw-r--r--tests/testthat/test_deSolve.R19
-rw-r--r--tests/testthat/test_mixed.R20
-rw-r--r--tests/testthat/test_mkinpredict_SFO_SFO.R14
4 files changed, 54 insertions, 1 deletions
diff --git a/tests/testthat/test_FOCUS_D_UBA_expertise.R b/tests/testthat/test_FOCUS_D_UBA_expertise.R
index faf473c4..323fb7b3 100644
--- a/tests/testthat/test_FOCUS_D_UBA_expertise.R
+++ b/tests/testthat/test_FOCUS_D_UBA_expertise.R
@@ -40,7 +40,7 @@ test_that("Fits without internal transformations are correct for FOCUS D", {
fit.ff.notrans <- mkinfit(SFO_SFO.ff, FOCUS_2006_D,
transform_fractions = FALSE, transform_rates = FALSE,
quiet = TRUE, solution_type = "deSolve"),
- "sum of formation fractions")
+ "The sum of formation fractions may exceed one")
expect_equivalent(round(fit.ff.notrans$bparms.optim, c(2, 4, 4, 4)),
c(99.60, 0.0987, 0.0053, 0.5145))
diff --git a/tests/testthat/test_deSolve.R b/tests/testthat/test_deSolve.R
new file mode 100644
index 00000000..3d15de35
--- /dev/null
+++ b/tests/testthat/test_deSolve.R
@@ -0,0 +1,19 @@
+context("Solutions with deSolve")
+
+test_that("Solutions with deSolve work if we have no observations at time zero", {
+ skip_on_cran()
+
+ # For testing purposes, we replace 0 values in the time column with 0.1
+ # This confused mkinfit with solution_type "deSolve" up to version 0.1.3.0
+ FOCUS_D_nozero <- FOCUS_D
+ FOCUS_D_nozero[FOCUS_D$time == 0, "time"] <- c(0.1, 0.1)
+
+ f_sfo_sfo_nozero <- mkinfit(SFO_SFO, FOCUS_D_nozero, quiet = TRUE)
+ f_sfo_sfo_nozero_deSolve <- mkinfit(SFO_SFO, FOCUS_D_nozero,
+ solution_type = "deSolve", quiet = TRUE)
+ expect_equal(
+ parms(f_sfo_sfo_nozero),
+ parms(f_sfo_sfo_nozero_deSolve)
+ )
+})
+
diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R
index b9715096..99a5fd3a 100644
--- a/tests/testthat/test_mixed.R
+++ b/tests/testthat/test_mixed.R
@@ -102,15 +102,35 @@ test_that("Reading spreadsheets, finding ill-defined parameters and covariate mo
error_model = "const")
lambda_sforb_saem_pH <- saem(lambda_sforb, covariates = covariates,
covariate_models = list(log_k_lambda_bound_free ~ pH))
+
expect_equal(
as.character(illparms(lambda_sforb_saem_pH)),
c("sd(lambda_free_0)", "sd(log_k_lambda_free_bound)"))
lambda_endpoints <- endpoints(lambda_sforb_saem_pH)
+
expect_equal(lambda_endpoints$covariates$pH, 6.45)
expect_equal(
round(as.numeric(lambda_endpoints$distimes), 0),
c(47, 422, 127, 7, 162))
+
+ # We should get the same endpoints when the covariates are centered
+ lambda_sforb_saem_pH_centered <- saem(lambda_sforb, covariates = covariates,
+ covariate_models = list(log_k_lambda_bound_free ~ pH), center_covariates = "median")
+ lambda_endpoints_centered <- endpoints(lambda_sforb_saem_pH_centered)
+
+ expect_equal(lambda_endpoints_centered$covariates$pH, 6.45)
+ expect_equal(
+ round(as.numeric(lambda_endpoints_centered$distimes), 0),
+ c(47, 422, 127, 7, 162))
+
+ # Also check endpoints obtained for a different pH
+ lambda_endpoints_centered_7 <- endpoints(lambda_sforb_saem_pH_centered, covariates = c(pH = 7))
+ expect_equal(lambda_endpoints_centered_7$covariates$pH, 7)
+ expect_equal(
+ round(as.numeric(lambda_endpoints_centered_7$distimes), 0),
+ c(39, 283, 85, 7, 106))
+
})
test_that("SFO-SFO saemix specific analytical solution work", {
diff --git a/tests/testthat/test_mkinpredict_SFO_SFO.R b/tests/testthat/test_mkinpredict_SFO_SFO.R
index d0dc7cdb..bf1043a3 100644
--- a/tests/testthat/test_mkinpredict_SFO_SFO.R
+++ b/tests/testthat/test_mkinpredict_SFO_SFO.R
@@ -11,6 +11,10 @@ test_that("Variants of model predictions for SFO_SFO model give equivalent resul
m1 = mkinsub("SFO"), use_of_ff = "max", quiet = TRUE)
ot = seq(0, 100, by = 1)
+ r.1.a <- subset(as.data.frame(mkinpredict(SFO_SFO.1,
+ c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "analytical")),
+ time %in% c(1, 10, 50, 100))
r.1.e <- subset(as.data.frame(mkinpredict(SFO_SFO.1,
c(k_parent_m1 = 0.1, k_parent_sink = 0.1, k_m1_sink = 0.1),
c(parent = 100, m1 = 0), ot, solution_type = "eigen")),
@@ -20,6 +24,10 @@ test_that("Variants of model predictions for SFO_SFO model give equivalent resul
c(parent = 100, m1 = 0), ot, solution_type = "deSolve")),
time %in% c(1, 10, 50, 100))
+ r.2.a <- subset(as.data.frame(mkinpredict(SFO_SFO.2,
+ c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
+ c(parent = 100, m1 = 0), ot, solution_type = "analytical")),
+ time %in% c(1, 10, 50, 100))
r.2.e <- subset(as.data.frame(mkinpredict(SFO_SFO.2,
c(k_parent = 0.2, f_parent_to_m1 = 0.5, k_m1 = 0.1),
c(parent = 100, m1 = 0), ot, solution_type = "eigen")),
@@ -29,6 +37,12 @@ test_that("Variants of model predictions for SFO_SFO model give equivalent resul
c(parent = 100, m1 = 0), ot, solution_type = "deSolve")),
time %in% c(1, 10, 50, 100))
+ # Compare analytical and deSolve for minimum use of formation fractions
+ dev.1.a_d.percent = 100 * (r.1.a[-1] - r.1.d[-1])/r.1.a[-1]
+ dev.1.a_d.percent = as.numeric(unlist((dev.1.a_d.percent)))
+ dev.1.a_d.percent = ifelse(is.na(dev.1.a_d.percent), 0, dev.1.a_d.percent)
+ expect_equivalent(dev.1.a_d.percent < tol, rep(TRUE, length(dev.1.a_d.percent)))
+
# Compare eigen and deSolve for minimum use of formation fractions
dev.1.e_d.percent = 100 * (r.1.e[-1] - r.1.d[-1])/r.1.e[-1]
dev.1.e_d.percent = as.numeric(unlist((dev.1.e_d.percent)))

Contact - Imprint