aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat/setup_script.R
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-02-08 17:17:29 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-02-08 17:17:29 +0100
commit0fa8a770812775d697717ad723f7f61fb04b7fef (patch)
tree17473ddf787541745d47dab063bc643ec59a9557 /tests/testthat/setup_script.R
parentd081384ddcb75a9f92fad33e4e3f6d6796f98e67 (diff)
parentc0638c84568d475b3b059e2c6e593e6f03b846bc (diff)
Merge branch 'nlmixr'
Diffstat (limited to 'tests/testthat/setup_script.R')
-rw-r--r--tests/testthat/setup_script.R33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R
index 547b2d6c..cb3713aa 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.0") 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")
+}

Contact - Imprint