diff options
| -rw-r--r-- | R/saem.R | 5 | ||||
| -rw-r--r-- | log/test.log | 22 | ||||
| -rw-r--r-- | tests/testthat/anova_sfo_saem.txt | 7 | ||||
| -rw-r--r-- | tests/testthat/test_saemix_parent.R | 20 | ||||
| -rw-r--r-- | vignettes/web_only/multistart.R | 36 | 
5 files changed, 38 insertions, 52 deletions
| @@ -738,6 +738,11 @@ update.saem.mmkin <- function(object, ..., evaluate = TRUE) {    # so we need to fix this so we do not have to export saem.mmkin in    # addition to the S3 method    call[[1]] <- saem + +  # We also need to provide the mmkin object in the call, so it +  # will also be found when called by testthat or pkgdown +  call[[2]] <- object$mmkin +    update_arguments <- match.call(expand.dots = FALSE)$...    if (length(update_arguments) > 0) { diff --git a/log/test.log b/log/test.log index d9dcffb9..6f6d0f23 100644 --- a/log/test.log +++ b/log/test.log @@ -1,11 +1,11 @@  ℹ Testing mkin  ✔ | F W S  OK | Context  ✔ |         5 | AIC calculation -✔ |         5 | Analytical solutions for coupled models [3.3s] +✔ |         5 | Analytical solutions for coupled models [3.2s]  ✔ |         5 | Calculation of Akaike weights  ✔ |         3 | Export dataset for reading into CAKE  ✔ |        12 | Confidence intervals and p-values [1.0s] -✔ |     1  12 | Dimethenamid data from 2018 [32.1s] +✔ |     1  12 | Dimethenamid data from 2018 [31.8s]  ────────────────────────────────────────────────────────────────────────────────  Skip (test_dmta.R:98:3): Different backends get consistent results for SFO-SFO3+, dimethenamid data  Reason: Fitting this ODE model with saemix takes about 15 minutes on my system @@ -16,7 +16,7 @@ Reason: Fitting this ODE model with saemix takes about 15 minutes on my system  ✔ |        14 | Results for FOCUS D established in expertise for UBA (Ranke 2014) [0.8s]  ✔ |         4 | Test fitting the decline of metabolites from their maximum [0.3s]  ✔ |         1 | Fitting the logistic model [0.2s] -✔ |         7 | Batch fitting and diagnosing hierarchical kinetic models [14.2s] +✔ |         7 | Batch fitting and diagnosing hierarchical kinetic models [14.6s]  ✔ |     1  12 | Nonlinear mixed-effects models [0.3s]  ────────────────────────────────────────────────────────────────────────────────  Skip (test_mixed.R:74:3): saemix results are reproducible for biphasic fits @@ -26,18 +26,18 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve  ✔ |        10 | Special cases of mkinfit calls [0.4s]  ✔ |         3 | mkinfit features [0.7s]  ✔ |         8 | mkinmod model generation and printing [0.2s] -✔ |         3 | Model predictions with mkinpredict [0.3s] -✔ |         5 | Multistart method for saem.mmkin models [34.8s] +✔ |         3 | Model predictions with mkinpredict [0.4s] +✔ |         7 | Multistart method for saem.mmkin models [36.0s]  ✔ |        16 | Evaluations according to 2015 NAFTA guidance [2.3s] -✔ |         9 | Nonlinear mixed-effects models with nlme [8.5s] +✔ |         9 | Nonlinear mixed-effects models with nlme [8.6s]  ✔ |        16 | Plotting [10.0s]  ✔ |         4 | Residuals extracted from mkinfit models -✔ |     1  35 | saemix parent models [65.3s] +✔ |     1  36 | saemix parent models [71.5s]  ──────────────────────────────────────────────────────────────────────────────── -Skip (test_saemix_parent.R:142:3): We can also use mkin solution methods for saem +Skip (test_saemix_parent.R:152:3): We can also use mkin solution methods for saem  Reason: This still takes almost 2.5 minutes although we do not solve ODEs  ──────────────────────────────────────────────────────────────────────────────── -✔ |         2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.5s] +✔ |         2 | Complex test case from Schaefer et al. (2007) Piacenza paper [1.4s]  ✔ |        11 | Processing of residue series  ✔ |         7 | Fitting the SFORB model [3.7s]  ✔ |         1 | Summaries of old mkinfit objects @@ -47,11 +47,11 @@ Reason: This still takes almost 2.5 minutes although we do not solve ODEs  ✔ |         4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s]  ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 198.3 s +Duration: 206.0 s  ── Skipped tests  ──────────────────────────────────────────────────────────────  • Fitting this ODE model with saemix takes about 15 minutes on my system (1)  • Fitting with saemix takes around 10 minutes when using deSolve (1)  • This still takes almost 2.5 minutes although we do not solve ODEs (1) -[ FAIL 0 | WARN 0 | SKIP 3 | PASS 258 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 261 ] 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) diff --git a/vignettes/web_only/multistart.R b/vignettes/web_only/multistart.R deleted file mode 100644 index 36612443..00000000 --- a/vignettes/web_only/multistart.R +++ /dev/null @@ -1,36 +0,0 @@ -## ----------------------------------------------------------------------------- -library(mkin) -dmta_ds <- lapply(1:7, function(i) { -  ds_i <- dimethenamid_2018$ds[[i]]$data -  ds_i[ds_i$name == "DMTAP", "name"] <-  "DMTA" -  ds_i$time <- ds_i$time * dimethenamid_2018$f_time_norm[i] -  ds_i -}) -names(dmta_ds) <- sapply(dimethenamid_2018$ds, function(ds) ds$title) -dmta_ds[["Elliot"]] <- rbind(dmta_ds[["Elliot 1"]], dmta_ds[["Elliot 2"]]) -dmta_ds[["Elliot 1"]] <- dmta_ds[["Elliot 2"]] <- NULL - -## ----------------------------------------------------------------------------- -f_mmkin <- mmkin("DFOP", dmta_ds, error_model = "tc", cores = 7, quiet = TRUE) -f_saem_full <- saem(f_mmkin) -illparms(f_saem_full) - -## ----------------------------------------------------------------------------- -f_saem_full_multi <- multistart(f_saem_full, n = 16, cores = 16) -parhist(f_saem_full_multi) - -## ----------------------------------------------------------------------------- -f_saem_reduced <- update(f_saem_full, no_random_effect = "log_k2") -illparms(f_saem_reduced) -f_saem_reduced_multi <- multistart(f_saem_reduced, n = 16, cores = 16) -parhist(f_saem_reduced_multi, lpos = "topright") - -## ----------------------------------------------------------------------------- -llhist(f_saem_reduced_multi) - -## ----------------------------------------------------------------------------- -parhist(f_saem_reduced_multi, lpos = "topright", llmin = -326, ylim = c(0.5, 2)) - -## ----------------------------------------------------------------------------- -anova(f_saem_full, best(f_saem_reduced_multi), test = TRUE) - | 
