diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2022-11-18 19:14:47 +0100 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2022-11-18 19:14:47 +0100 |
commit | 5364f037a72863ef5ba81e14ba4417f68fd389f9 (patch) | |
tree | fac84908a74553009b0ab03d7a8c21cdf3a7f086 | |
parent | a14237fc1580b09f8772cd3330b0a445785e48ac (diff) |
Make mixed model test data permanent to ensure reproducibility
To ensure that tests on different platforms work on the same data, the
mixed modelling test data previosly generated in
tests/testthat/setup_script.R were generated once using the script in
inst/dataset/generation/ds_mixed.R, and are now distributed with the
package.
24 files changed, 324 insertions, 262 deletions
diff --git a/R/ds_mixed.R b/R/ds_mixed.R new file mode 100644 index 00000000..c5055712 --- /dev/null +++ b/R/ds_mixed.R @@ -0,0 +1,17 @@ +#' Synthetic data for hierarchical kinetic degradation models +#' +#' The R code used to create this data object is installed with this package in +#' the 'dataset_generation' directory. +#' +#' @name ds_mixed +#' @aliases ds_sfo ds_fomc ds_dfop ds_hs ds_dfop_sfo +#' @examples +#' \dontrun{ +#' sfo_mmkin <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = 15) +#' sfo_saem <- saem(sfo_mmkin, no_random_effect = "parent_0") +#' plot(sfo_saem) +#' } +#' +#' # This is the code used to generate the datasets +#' cat(readLines(system.file("dataset_generation/ds_mixed.R", package = "mkin")), sep = "\n") +NULL diff --git a/_pkgdown.yml b/_pkgdown.yml index 8aa44ed4..98ed84f2 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -67,7 +67,7 @@ reference: - parplot - title: Datasets and known results contents: - - focus_soil_moisture + - ds_mixed - D24_2014 - dimethenamid_2018 - FOCUS_2006_A @@ -82,6 +82,7 @@ reference: - synthetic_data_for_UBA_2014 - experimental_data_for_UBA_2019 - test_data_from_UBA_2014 + - focus_soil_moisture - mkinds - mkindsg - title: NAFTA guidance diff --git a/data/ds_mixed.rda b/data/ds_mixed.rda Binary files differnew file mode 100644 index 00000000..cf9f6463 --- /dev/null +++ b/data/ds_mixed.rda diff --git a/inst/dataset_generation/ds_mixed.R b/inst/dataset_generation/ds_mixed.R new file mode 100644 index 00000000..f2ae6e7e --- /dev/null +++ b/inst/dataset_generation/ds_mixed.R @@ -0,0 +1,105 @@ +# Synthetic data for hierarchical kinetic models +# Refactored version of the code previously in tests/testthat/setup_script.R +# The number of datasets was 3 for FOMC, and 10 for HS in that script, now it +# is always 15 for consistency + +library(mkin) # We use mkinmod and mkinpredict +sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) +n <- 15 +log_sd <- 0.3 +err_1 = list(const = 1, prop = 0.05) +tc <- function(value) sigma_twocomp(value, err_1$const, err_1$prop) +const <- function(value) 2 + +set.seed(123456) +SFO <- mkinmod(parent = mkinsub("SFO")) +sfo_pop <- list(parent_0 = 100, k_parent = 0.03) +sfo_parms <- as.matrix(data.frame( + k_parent = rlnorm(n, log(sfo_pop$k_parent), log_sd))) +set.seed(123456) +ds_sfo <- lapply(1:n, function(i) { + ds_mean <- mkinpredict(SFO, sfo_parms[i, ], + c(parent = sfo_pop$parent_0), sampling_times) + add_err(ds_mean, tc, n = 1)[[1]] +}) +attr(ds_sfo, "pop") <- sfo_pop +attr(ds_sfo, "parms") <- sfo_parms + +set.seed(123456) +FOMC <- mkinmod(parent = mkinsub("FOMC")) +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:n, function(i) { + ds_mean <- mkinpredict(FOMC, fomc_parms[i, ], + c(parent = fomc_pop$parent_0), sampling_times) + add_err(ds_mean, tc, n = 1)[[1]] +}) +attr(ds_fomc, "pop") <- fomc_pop +attr(ds_fomc, "parms") <- fomc_parms + +set.seed(123456) +DFOP <- mkinmod(parent = mkinsub("DFOP")) +dfop_pop <- list(parent_0 = 100, k1 = 0.06, k2 = 0.015, g = 0.4) +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) + add_err(ds_mean, tc, n = 1)[[1]] +}) +attr(ds_dfop, "pop") <- dfop_pop +attr(ds_dfop, "parms") <- dfop_parms + +set.seed(123456) +HS <- mkinmod(parent = mkinsub("HS")) +hs_pop <- list(parent_0 = 100, k1 = 0.08, k2 = 0.01, tb = 15) +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:n, function(i) { + ds_mean <- mkinpredict(HS, hs_parms[i, ], + c(parent = hs_pop$parent_0), sampling_times) + add_err(ds_mean, const, n = 1)[[1]] +}) +attr(ds_hs, "pop") <- hs_pop +attr(ds_hs, "parms") <- hs_parms + +set.seed(123456) +DFOP_SFO <- mkinmod( + parent = mkinsub("DFOP", "m1"), + m1 = mkinsub("SFO"), + quiet = TRUE) +dfop_sfo_pop <- list(parent_0 = 100, + k_m1 = 0.007, f_parent_to_m1 = 0.5, + k1 = 0.1, k2 = 0.02, g = 0.5) +dfop_sfo_parms <- as.matrix(data.frame( + k1 = rlnorm(n, log(dfop_sfo_pop$k1), log_sd), + k2 = rlnorm(n, log(dfop_sfo_pop$k2), log_sd), + g = plogis(rnorm(n, qlogis(dfop_sfo_pop$g), log_sd)), + f_parent_to_m1 = plogis(rnorm(n, + qlogis(dfop_sfo_pop$f_parent_to_m1), log_sd)), + k_m1 = rlnorm(n, log(dfop_sfo_pop$k_m1), log_sd))) +ds_dfop_sfo_mean <- lapply(1:n, + function(i) { + mkinpredict(DFOP_SFO, dfop_sfo_parms[i, ], + c(parent = dfop_sfo_pop$parent_0, m1 = 0), sampling_times) + } +) +set.seed(123456) +ds_dfop_sfo <- lapply(ds_dfop_sfo_mean, function(ds) { + add_err(ds, + sdfunc = function(value) sqrt(err_1$const^2 + value^2 * err_1$prop^2), + n = 1, secondary = "m1")[[1]] +}) +attr(ds_dfop_sfo, "pop") <- dfop_sfo_pop +attr(ds_dfop_sfo, "parms") <- dfop_sfo_parms + +#save(ds_sfo, ds_fomc, ds_dfop, ds_hs, ds_dfop_sfo, file = "data/ds_mixed.rda", version = 2) diff --git a/log/check.log b/log/check.log index 7aa4610c..31fc31eb 100644 --- a/log/check.log +++ b/log/check.log @@ -5,7 +5,7 @@ * using options ‘--no-tests --as-cran’ * checking for file ‘mkin/DESCRIPTION’ ... OK * checking extension type ... Package -* this is package ‘mkin’ version ‘1.2.0’ +* this is package ‘mkin’ version ‘1.2.1’ * package encoding: UTF-8 * checking CRAN incoming feasibility ... Note_to_CRAN_maintainers Maintainer: ‘Johannes Ranke <johannes.ranke@jrwb.de>’ @@ -41,7 +41,7 @@ Maintainer: ‘Johannes Ranke <johannes.ranke@jrwb.de>’ * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK -* checking R code for possible problems ... [18s/18s] OK +* checking R code for possible problems ... [17s/17s] OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd line widths ... OK diff --git a/log/test.log b/log/test.log index 87d24690..d1de270e 100644 --- a/log/test.log +++ b/log/test.log @@ -5,19 +5,19 @@ ✔ | 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 [31.5s] +✔ | 1 12 | Dimethenamid data from 2018 [32.6s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_dmta.R:98'): Different backends get consistent results for SFO-SFO3+, dimethenamid data Reason: Fitting this ODE model with saemix takes about 15 minutes on my system ──────────────────────────────────────────────────────────────────────────────── -✔ | 14 | Error model fitting [5.0s] +✔ | 14 | Error model fitting [5.1s] ✔ | 5 | Time step normalisation ✔ | 4 | Calculation of FOCUS chi2 error levels [0.6s] ✔ | 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.4s] ✔ | 1 | Fitting the logistic model [0.2s] -✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.4s] -✔ | 1 12 | Nonlinear mixed-effects models [0.3s] +✔ | 10 | Batch fitting and diagnosing hierarchical kinetic models [24.6s] +✔ | 1 13 | Nonlinear mixed-effects models [0.4s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_mixed.R:79'): saemix results are reproducible for biphasic fits Reason: Fitting with saemix takes around 10 minutes when using deSolve @@ -26,32 +26,32 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve ✔ | 10 | Special cases of mkinfit calls [0.5s] ✔ | 3 | mkinfit features [0.7s] ✔ | 8 | mkinmod model generation and printing [0.2s] -✔ | 3 | Model predictions with mkinpredict [0.3s] -✔ | 9 | Multistart method for saem.mmkin models [36.2s] +✔ | 3 | Model predictions with mkinpredict [0.4s] +✔ | 9 | Multistart method for saem.mmkin models [37.3s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.5s] -✔ | 9 | Nonlinear mixed-effects models with nlme [8.8s] -✔ | 16 | Plotting [10.0s] +✔ | 9 | Nonlinear mixed-effects models with nlme [9.2s] +✔ | 16 | Plotting [10.1s] ✔ | 4 | Residuals extracted from mkinfit models -✔ | 1 36 | saemix parent models [65.8s] +✔ | 1 36 | saemix parent models [71.4s] ──────────────────────────────────────────────────────────────────────────────── Skip ('test_saemix_parent.R:143'): 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.4s] ✔ | 11 | Processing of residue series -✔ | 10 | Fitting the SFORB model [3.7s] +✔ | 10 | Fitting the SFORB model [3.9s] ✔ | 1 | Summaries of old mkinfit objects ✔ | 5 | Summary [0.2s] -✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.2s] -✔ | 9 | Hypothesis tests [8.0s] +✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.3s] +✔ | 9 | Hypothesis tests [8.3s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s] ══ Results ═════════════════════════════════════════════════════════════════════ -Duration: 210.4 s +Duration: 220.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 269 ] +[ FAIL 0 | WARN 0 | SKIP 3 | PASS 270 ] diff --git a/man/ds_mixed.Rd b/man/ds_mixed.Rd new file mode 100644 index 00000000..227b8e7f --- /dev/null +++ b/man/ds_mixed.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ds_mixed.R +\name{ds_mixed} +\alias{ds_mixed} +\alias{ds_sfo} +\alias{ds_fomc} +\alias{ds_dfop} +\alias{ds_hs} +\alias{ds_dfop_sfo} +\title{Synthetic data for hierarchical kinetic degradation models} +\description{ +The R code used to create this data object is installed with this package in +the 'dataset_generation' directory. +} +\examples{ +\dontrun{ + sfo_mmkin <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = 15) + sfo_saem <- saem(sfo_mmkin, no_random_effect = "parent_0") + plot(sfo_saem) +} + +# This is the code used to generate the datasets +cat(readLines(system.file("dataset_generation/ds_mixed.R", package = "mkin")), sep = "\n") +} diff --git a/tests/testthat/_snaps/multistart/llhist-for-biphasic-saemix-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg index 6015aed8..6015aed8 100644 --- a/tests/testthat/_snaps/multistart/llhist-for-biphasic-saemix-fit.svg +++ b/tests/testthat/_snaps/multistart/llhist-for-dfop-sfo-fit.svg diff --git a/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg index 98513d06..028c69de 100644 --- a/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/llhist-for-sfo-fit.svg @@ -25,20 +25,22 @@ <line x1='374.40' y1='502.56' x2='374.40' y2='509.76' style='stroke-width: 0.75;' /> <line x1='520.40' y1='502.56' x2='520.40' y2='509.76' style='stroke-width: 0.75;' /> <line x1='666.40' y1='502.56' x2='666.40' y2='509.76' style='stroke-width: 0.75;' /> -<text x='82.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-649.836</text> -<text x='228.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-649.834</text> -<text x='374.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-649.832</text> -<text x='520.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-649.830</text> -<text x='666.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-649.828</text> +<text x='82.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-646.124</text> +<text x='228.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-646.123</text> +<text x='374.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-646.122</text> +<text x='520.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-646.121</text> +<text x='666.40' y='528.48' text-anchor='middle' style='font-size: 12.00px; font-family: sans;' textLength='47.38px' lengthAdjust='spacingAndGlyphs'>-646.120</text> <line x1='59.04' y1='486.13' x2='59.04' y2='75.47' style='stroke-width: 0.75;' /> <line x1='59.04' y1='486.13' x2='51.84' y2='486.13' style='stroke-width: 0.75;' /> -<line x1='59.04' y1='349.24' x2='51.84' y2='349.24' style='stroke-width: 0.75;' /> -<line x1='59.04' y1='212.36' x2='51.84' y2='212.36' style='stroke-width: 0.75;' /> +<line x1='59.04' y1='383.47' x2='51.84' y2='383.47' style='stroke-width: 0.75;' /> +<line x1='59.04' y1='280.80' x2='51.84' y2='280.80' style='stroke-width: 0.75;' /> +<line x1='59.04' y1='178.13' x2='51.84' y2='178.13' style='stroke-width: 0.75;' /> <line x1='59.04' y1='75.47' x2='51.84' y2='75.47' style='stroke-width: 0.75;' /> <text x='44.64' y='490.26' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>0</text> -<text x='44.64' y='353.37' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>1</text> -<text x='44.64' y='216.48' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>2</text> -<text x='44.64' y='79.60' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>3</text> +<text x='44.64' y='387.60' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>1</text> +<text x='44.64' y='284.93' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>2</text> +<text x='44.64' y='182.26' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>3</text> +<text x='44.64' y='79.60' text-anchor='end' style='font-size: 12.00px; font-family: sans;' textLength='6.67px' lengthAdjust='spacingAndGlyphs'>4</text> </g> <defs> <clipPath id='cpNTkuMDR8Njg5Ljc2fDU5LjA0fDUwMi41Ng=='> @@ -46,11 +48,11 @@ </clipPath> </defs> <g clip-path='url(#cpNTkuMDR8Njg5Ljc2fDU5LjA0fDUwMi41Ng==)'> -<rect x='82.40' y='349.24' width='146.00' height='136.89' style='stroke-width: 0.75; fill: #D3D3D3;' /> +<rect x='82.40' y='280.80' width='146.00' height='205.33' style='stroke-width: 0.75; fill: #D3D3D3;' /> <rect x='228.40' y='75.47' width='146.00' height='410.67' style='stroke-width: 0.75; fill: #D3D3D3;' /> -<rect x='374.40' y='75.47' width='146.00' height='410.67' style='stroke-width: 0.75; fill: #D3D3D3;' /> -<rect x='520.40' y='349.24' width='146.00' height='136.89' style='stroke-width: 0.75; fill: #D3D3D3;' /> -<line x1='232.06' y1='502.56' x2='232.06' y2='59.04' style='stroke-width: 0.75; stroke: #DF536B;' /> +<rect x='374.40' y='383.47' width='146.00' height='102.67' style='stroke-width: 0.75; fill: #D3D3D3;' /> +<rect x='520.40' y='383.47' width='146.00' height='102.67' style='stroke-width: 0.75; fill: #D3D3D3;' /> +<line x1='110.97' y1='502.56' x2='110.97' y2='59.04' style='stroke-width: 0.75; stroke: #DF536B;' /> <line x1='101.38' y1='95.62' x2='122.98' y2='95.62' style='stroke-width: 0.75; stroke: #DF536B;' /> <text x='133.78' y='99.75' style='font-size: 12.00px; font-family: sans;' textLength='51.35px' lengthAdjust='spacingAndGlyphs'>original fit</text> </g> diff --git a/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg index 7017908e..7017908e 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-biphasic-saemix-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-dfop-sfo-fit.svg diff --git a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg index 18eb7fcc..a47a585a 100644 --- a/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg +++ b/tests/testthat/_snaps/multistart/parplot-for-sfo-fit.svg @@ -25,42 +25,44 @@ </clipPath> </defs> <g clip-path='url(#cpNTkuMDR8Njg5Ljc2fDU5LjA0fDUwMi41Ng==)'> -<polygon points='94.08,280.80 187.52,280.80 187.52,280.77 94.08,280.77 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> +<polygon points='94.08,280.80 187.52,280.80 187.52,280.79 94.08,280.79 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> <line x1='94.08' y1='280.79' x2='187.52' y2='280.79' style='stroke-width: 2.25; stroke-linecap: butt;' /> -<line x1='140.80' y1='280.81' x2='140.80' y2='280.80' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='140.80' y1='280.74' x2='140.80' y2='280.77' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='117.44' y1='280.81' x2='164.16' y2='280.81' style='stroke-width: 0.75;' /> -<line x1='117.44' y1='280.74' x2='164.16' y2='280.74' style='stroke-width: 0.75;' /> -<polygon points='94.08,280.80 187.52,280.80 187.52,280.77 94.08,280.77 ' style='stroke-width: 0.75; fill: none;' /> -<polygon points='210.88,280.81 304.32,280.81 304.32,280.73 210.88,280.73 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> -<line x1='210.88' y1='280.78' x2='304.32' y2='280.78' style='stroke-width: 2.25; stroke-linecap: butt;' /> -<line x1='257.60' y1='280.82' x2='257.60' y2='280.81' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='257.60' y1='280.65' x2='257.60' y2='280.73' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='234.24' y1='280.82' x2='280.96' y2='280.82' style='stroke-width: 0.75;' /> -<line x1='234.24' y1='280.65' x2='280.96' y2='280.65' style='stroke-width: 0.75;' /> -<polygon points='210.88,280.81 304.32,280.81 304.32,280.73 210.88,280.73 ' style='stroke-width: 0.75; fill: none;' /> -<polygon points='327.68,280.90 421.12,280.90 421.12,280.70 327.68,280.70 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> -<line x1='327.68' y1='280.84' x2='421.12' y2='280.84' style='stroke-width: 2.25; stroke-linecap: butt;' /> -<line x1='374.40' y1='280.92' x2='374.40' y2='280.90' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='374.40' y1='280.67' x2='374.40' y2='280.70' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='351.04' y1='280.92' x2='397.76' y2='280.92' style='stroke-width: 0.75;' /> -<line x1='351.04' y1='280.67' x2='397.76' y2='280.67' style='stroke-width: 0.75;' /> -<polygon points='327.68,280.90 421.12,280.90 421.12,280.70 327.68,280.70 ' style='stroke-width: 0.75; fill: none;' /> -<circle cx='374.40' cy='280.36' r='2.70' style='stroke-width: 0.75;' /> -<polygon points='444.48,280.85 537.92,280.85 537.92,280.79 444.48,280.79 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> -<line x1='444.48' y1='280.82' x2='537.92' y2='280.82' style='stroke-width: 2.25; stroke-linecap: butt;' /> -<line x1='491.20' y1='280.88' x2='491.20' y2='280.85' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='491.20' y1='280.74' x2='491.20' y2='280.79' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='467.84' y1='280.88' x2='514.56' y2='280.88' style='stroke-width: 0.75;' /> -<line x1='467.84' y1='280.74' x2='514.56' y2='280.74' style='stroke-width: 0.75;' /> -<polygon points='444.48,280.85 537.92,280.85 537.92,280.79 444.48,280.79 ' style='stroke-width: 0.75; fill: none;' /> -<polygon points='561.28,280.75 654.72,280.75 654.72,280.57 561.28,280.57 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> -<line x1='561.28' y1='280.65' x2='654.72' y2='280.65' style='stroke-width: 2.25; stroke-linecap: butt;' /> -<line x1='608.00' y1='280.80' x2='608.00' y2='280.75' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='608.00' y1='280.45' x2='608.00' y2='280.57' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> -<line x1='584.64' y1='280.80' x2='631.36' y2='280.80' style='stroke-width: 0.75;' /> -<line x1='584.64' y1='280.45' x2='631.36' y2='280.45' style='stroke-width: 0.75;' /> -<polygon points='561.28,280.75 654.72,280.75 654.72,280.57 561.28,280.57 ' style='stroke-width: 0.75; fill: none;' /> +<line x1='140.80' y1='280.80' x2='140.80' y2='280.80' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='140.80' y1='280.79' x2='140.80' y2='280.79' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='117.44' y1='280.80' x2='164.16' y2='280.80' style='stroke-width: 0.75;' /> +<line x1='117.44' y1='280.79' x2='164.16' y2='280.79' style='stroke-width: 0.75;' /> +<polygon points='94.08,280.80 187.52,280.80 187.52,280.79 94.08,280.79 ' style='stroke-width: 0.75; fill: none;' /> +<polygon points='210.88,280.80 304.32,280.80 304.32,280.77 210.88,280.77 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> +<line x1='210.88' y1='280.79' x2='304.32' y2='280.79' style='stroke-width: 2.25; stroke-linecap: butt;' /> +<line x1='257.60' y1='280.81' x2='257.60' y2='280.80' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='257.60' y1='280.77' x2='257.60' y2='280.77' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='234.24' y1='280.81' x2='280.96' y2='280.81' style='stroke-width: 0.75;' /> +<line x1='234.24' y1='280.77' x2='280.96' y2='280.77' style='stroke-width: 0.75;' /> +<polygon points='210.88,280.80 304.32,280.80 304.32,280.77 210.88,280.77 ' style='stroke-width: 0.75; fill: none;' /> +<polygon points='327.68,280.94 421.12,280.94 421.12,280.80 327.68,280.80 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> +<line x1='327.68' y1='280.82' x2='421.12' y2='280.82' style='stroke-width: 2.25; stroke-linecap: butt;' /> +<line x1='374.40' y1='280.98' x2='374.40' y2='280.94' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='374.40' y1='280.80' x2='374.40' y2='280.80' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='351.04' y1='280.98' x2='397.76' y2='280.98' style='stroke-width: 0.75;' /> +<line x1='351.04' y1='280.80' x2='397.76' y2='280.80' style='stroke-width: 0.75;' /> +<polygon points='327.68,280.94 421.12,280.94 421.12,280.80 327.68,280.80 ' style='stroke-width: 0.75; fill: none;' /> +<circle cx='374.40' cy='280.60' r='2.70' style='stroke-width: 0.75;' /> +<polygon points='444.48,280.81 537.92,280.81 537.92,280.78 444.48,280.78 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> +<line x1='444.48' y1='280.80' x2='537.92' y2='280.80' style='stroke-width: 2.25; stroke-linecap: butt;' /> +<line x1='491.20' y1='280.82' x2='491.20' y2='280.81' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='491.20' y1='280.77' x2='491.20' y2='280.78' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='467.84' y1='280.82' x2='514.56' y2='280.82' style='stroke-width: 0.75;' /> +<line x1='467.84' y1='280.77' x2='514.56' y2='280.77' style='stroke-width: 0.75;' /> +<polygon points='444.48,280.81 537.92,280.81 537.92,280.78 444.48,280.78 ' style='stroke-width: 0.75; fill: none;' /> +<circle cx='491.20' cy='280.87' r='2.70' style='stroke-width: 0.75;' /> +<polygon points='561.28,280.89 654.72,280.89 654.72,280.79 561.28,280.79 ' style='stroke-width: 0.75; stroke: none; fill: #D3D3D3;' /> +<line x1='561.28' y1='280.84' x2='654.72' y2='280.84' style='stroke-width: 2.25; stroke-linecap: butt;' /> +<line x1='608.00' y1='280.92' x2='608.00' y2='280.89' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='608.00' y1='280.70' x2='608.00' y2='280.79' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> +<line x1='584.64' y1='280.92' x2='631.36' y2='280.92' style='stroke-width: 0.75;' /> +<line x1='584.64' y1='280.70' x2='631.36' y2='280.70' style='stroke-width: 0.75;' /> +<polygon points='561.28,280.89 654.72,280.89 654.72,280.79 561.28,280.79 ' style='stroke-width: 0.75; fill: none;' /> +<circle cx='608.00' cy='281.12' r='2.70' style='stroke-width: 0.75;' /> </g> <g clip-path='url(#cpMC4wMHw3MjAuMDB8MC4wMHw1NzYuMDA=)'> <line x1='140.80' y1='502.56' x2='608.00' y2='502.56' style='stroke-width: 0.75;' /> @@ -87,15 +89,15 @@ <polygon points='59.04,502.56 689.76,502.56 689.76,59.04 59.04,59.04 ' style='stroke-width: 0.75; fill: none;' /> </g> <g clip-path='url(#cpNTkuMDR8Njg5Ljc2fDU5LjA0fDUwMi41Ng==)'> -<circle cx='140.80' cy='280.97' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> -<circle cx='257.60' cy='281.05' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> -<circle cx='374.40' cy='257.89' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> -<circle cx='491.20' cy='-615.24' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> -<circle cx='140.80' cy='280.75' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> -<circle cx='257.60' cy='280.67' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> -<circle cx='374.40' cy='280.50' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> -<circle cx='491.20' cy='280.92' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> -<circle cx='608.00' cy='280.49' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> +<circle cx='140.80' cy='280.66' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> +<circle cx='257.60' cy='280.66' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> +<circle cx='374.40' cy='243.83' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> +<circle cx='491.20' cy='-614.23' r='8.10' style='stroke-width: 0.75; stroke: #61D04F;' /> +<circle cx='140.80' cy='280.82' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> +<circle cx='257.60' cy='280.85' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> +<circle cx='374.40' cy='280.96' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> +<circle cx='491.20' cy='280.75' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> +<circle cx='608.00' cy='280.97' r='5.40' style='stroke-width: 0.75; stroke: #DF536B;' /> <line x1='59.04' y1='280.80' x2='689.76' y2='280.80' style='stroke-width: 0.75; stroke-dasharray: 4.00,4.00;' /> <line x1='93.82' y1='465.98' x2='115.42' y2='465.98' style='stroke-width: 0.75;' /> <circle cx='104.62' cy='437.18' r='2.70' style='stroke-width: 0.75; stroke: #61D04F;' /> diff --git a/tests/testthat/anova_sfo_saem.txt b/tests/testthat/anova_sfo_saem.txt index 9e4bf71f..0ccd6d5c 100644 --- a/tests/testthat/anova_sfo_saem.txt +++ b/tests/testthat/anova_sfo_saem.txt @@ -1,7 +1,7 @@ -Data: 262 observations of 1 variable(s) grouped in 15 datasets +Data: 263 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 1312 1316 -650 0 0 +sfo_saem_1_reduced 5 1302 1306 -646 +sfo_saem_1_reduced_mkin 5 1302 1306 -646 0 0 +sfo_saem_1 6 1304 1308 -646 0 1 1 +sfo_saem_1_mkin 6 1303 1308 -646 1 0 diff --git a/tests/testthat/print_dfop_saemix_1.txt b/tests/testthat/print_dfop_saem_1.txt index 1d399a52..bdc40065 100644 --- a/tests/testthat/print_dfop_saemix_1.txt +++ b/tests/testthat/print_dfop_saem_1.txt @@ -13,11 +13,11 @@ Likelihood computed by importance sampling Fitted parameters: estimate lower upper -parent_0 100.00 99.00 100.00 -log_k1 -2.70 -3.00 -2.50 -log_k2 -4.10 -4.30 -4.00 +parent_0 99.92 98.77 101.06 +log_k1 -2.72 -2.95 -2.50 +log_k2 -4.14 -4.27 -4.01 g_qlogis -0.35 -0.53 -0.16 -a.1 0.92 0.68 1.20 +a.1 0.92 0.68 1.16 b.1 0.05 0.04 0.06 SD.log_k1 0.37 0.23 0.51 SD.log_k2 0.23 0.14 0.31 diff --git a/tests/testthat/print_fits_synth_const.txt b/tests/testthat/print_fits_synth_const.txt index 2ea1f133..b4bbe6ca 100644 --- a/tests/testthat/print_fits_synth_const.txt +++ b/tests/testthat/print_fits_synth_const.txt @@ -4,7 +4,7 @@ Status of individual fits: dataset model 1 2 3 4 5 6 SFO OK OK OK OK OK OK - FOMC C C OK OK OK OK + FOMC C OK OK OK OK C C: Optimisation did not converge: false convergence (8) diff --git a/tests/testthat/print_mmkin_sfo_1_mixed.txt b/tests/testthat/print_mmkin_sfo_1_mixed.txt index 33e5bf5c..c12cfe2b 100644 --- a/tests/testthat/print_mmkin_sfo_1_mixed.txt +++ b/tests/testthat/print_mmkin_sfo_1_mixed.txt @@ -3,7 +3,7 @@ Structural model: d_parent/dt = - k_parent * parent Data: -262 observations of 1 variable(s) grouped in 15 datasets +263 observations of 1 variable(s) grouped in 15 datasets <mmkin> object Status of individual fits: @@ -16,4 +16,4 @@ OK: No warnings Mean fitted parameters: parent_0 log_k_parent - 99.9 -3.3 + 100.0 -3.4 diff --git a/tests/testthat/print_multistart_biphasic.txt b/tests/testthat/print_multistart_dfop_sfo.txt index b4344f22..b4344f22 100644 --- a/tests/testthat/print_multistart_biphasic.txt +++ b/tests/testthat/print_multistart_dfop_sfo.txt diff --git a/tests/testthat/print_sfo_saem_1_reduced.txt b/tests/testthat/print_sfo_saem_1_reduced.txt index bac8848e..1c7fb588 100644 --- a/tests/testthat/print_sfo_saem_1_reduced.txt +++ b/tests/testthat/print_sfo_saem_1_reduced.txt @@ -3,16 +3,16 @@ Structural model: d_parent/dt = - k_parent * parent Data: -262 observations of 1 variable(s) grouped in 15 datasets +263 observations of 1 variable(s) grouped in 15 datasets Likelihood computed by importance sampling AIC BIC logLik - 1310 1313 -650 + 1302 1306 -646 Fitted parameters: estimate lower upper -parent_0 1e+02 99.08 1e+02 -k_parent 4e-02 0.03 4e-02 -a.1 9e-01 0.75 1e+00 +parent_0 1e+02 99.03 1e+02 +k_parent 3e-02 0.03 4e-02 +a.1 9e-01 0.71 1e+00 b.1 5e-02 0.04 5e-02 -SD.k_parent 3e-01 0.20 4e-01 +SD.k_parent 2e-01 0.14 3e-01 diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index 362038c3..c554800d 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -81,112 +81,27 @@ fit_obs_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "obs", quiet = TR fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE, error_model_algorithm = "threestep") -# Mixed models data and fits -sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) -n <- n_biphasic <- 15 -log_sd <- 0.3 -err_1 = list(const = 1, prop = 0.05) -tc <- function(value) sigma_twocomp(value, err_1$const, err_1$prop) -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) - add_err(ds_mean, tc, n = 1)[[1]] -}) - -set.seed(123456) -FOMC <- mkinmod(parent = mkinsub("FOMC")) -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) - add_err(ds_mean, tc, n = 1)[[1]] -}) - -set.seed(123456) -DFOP <- mkinmod(parent = mkinsub("DFOP")) -dfop_pop <- list(parent_0 = 100, k1 = 0.06, k2 = 0.015, g = 0.4) -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) - add_err(ds_mean, tc, n = 1)[[1]] -}) - -set.seed(123456) -HS <- mkinmod(parent = mkinsub("HS")) -hs_pop <- list(parent_0 = 100, k1 = 0.08, k2 = 0.01, tb = 15) -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) - add_err(ds_mean, const, n = 1)[[1]] -}) - -set.seed(123456) -DFOP_SFO <- mkinmod( - parent = mkinsub("DFOP", "m1"), - m1 = mkinsub("SFO"), - quiet = TRUE) -dfop_sfo_pop <- list(parent_0 = 100, - k_m1 = 0.007, f_parent_to_m1 = 0.5, - k1 = 0.1, k2 = 0.02, g = 0.5) -syn_biphasic_parms <- as.matrix(data.frame( - k1 = rlnorm(n_biphasic, log(dfop_sfo_pop$k1), log_sd), - k2 = rlnorm(n_biphasic, log(dfop_sfo_pop$k2), log_sd), - g = plogis(rnorm(n_biphasic, qlogis(dfop_sfo_pop$g), log_sd)), - f_parent_to_m1 = plogis(rnorm(n_biphasic, - qlogis(dfop_sfo_pop$f_parent_to_m1), log_sd)), - k_m1 = rlnorm(n_biphasic, log(dfop_sfo_pop$k_m1), log_sd))) -ds_biphasic_mean <- lapply(1:n_biphasic, - function(i) { - mkinpredict(DFOP_SFO, syn_biphasic_parms[i, ], - 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), - n = 1, secondary = "m1")[[1]] -}) - # Mixed model fits 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, error_model = "tc") -mmkin_biphasic <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_biphasic, quiet = TRUE, cores = n_cores, +DFOP_SFO <- mkinmod(parent = mkinsub("DFOP", "m1"), + m1 = mkinsub("SFO"), quiet = TRUE) +mmkin_dfop_sfo <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_dfop_sfo, quiet = TRUE, cores = n_cores, control = list(eval.max = 500, iter.max = 400), error_model = "tc") # nlme dfop_nlme_1 <- suppressWarnings(nlme(mmkin_dfop_1)) -nlme_biphasic <- suppressWarnings(nlme(mmkin_biphasic)) +nlme_dfop_sfo <- suppressWarnings(nlme(mmkin_dfop_sfo)) # saemix sfo_saem_1 <- saem(mmkin_sfo_1, quiet = TRUE, transformations = "saemix") sfo_saem_1_reduced <- update(sfo_saem_1, no_random_effect = "parent_0") -dfop_saemix_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", +dfop_saem_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", no_random_effect = c("parent_0", "g_qlogis")) -saem_biphasic_m <- saem(mmkin_biphasic, transformations = "mkin", quiet = TRUE) -saem_biphasic_s <- saem(mmkin_biphasic, transformations = "saemix", quiet = TRUE) +saem_dfop_sfo_m <- saem(mmkin_dfop_sfo, transformations = "mkin", quiet = TRUE) +saem_dfop_sfo_s <- saem(mmkin_dfop_sfo, transformations = "saemix", quiet = TRUE) diff --git a/tests/testthat/summary_hfit_sfo_tc.txt b/tests/testthat/summary_hfit_sfo_tc.txt index 41743091..bb5bf6fb 100644 --- a/tests/testthat/summary_hfit_sfo_tc.txt +++ b/tests/testthat/summary_hfit_sfo_tc.txt @@ -8,7 +8,7 @@ Equations: d_parent/dt = - k_parent * parent Data: -106 observations of 1 variable(s) grouped in 6 datasets +104 observations of 1 variable(s) grouped in 6 datasets Model predictions using solution type analytical @@ -28,15 +28,15 @@ Results: Likelihood computed by importance sampling AIC BIC logLik - 533 531 -261 + 524 523 -257 Optimised parameters: - est. lower upper -parent_0 101.02 99.58 102.46 -log_k_parent -3.32 -3.53 -3.11 -a.1 0.91 0.64 1.17 -b.1 0.05 0.04 0.06 -SD.log_k_parent 0.27 0.11 0.42 + est. lower upper +parent_0 100.68 99.27 102.08 +log_k_parent -3.38 -3.55 -3.21 +a.1 0.87 0.59 1.14 +b.1 0.05 0.04 0.06 +SD.log_k_parent 0.21 0.09 0.33 Correlation: pr_0 @@ -44,18 +44,18 @@ log_k_parent 0.1 Random effects: est. lower upper -SD.log_k_parent 0.3 0.1 0.4 +SD.log_k_parent 0.2 0.09 0.3 Variance model: est. lower upper -a.1 0.91 0.64 1.17 +a.1 0.87 0.59 1.14 b.1 0.05 0.04 0.06 Backtransformed parameters: est. lower upper -parent_0 1e+02 1e+02 1e+02 -k_parent 4e-02 3e-02 4e-02 +parent_0 1e+02 99.27 1e+02 +k_parent 3e-02 0.03 4e-02 Estimated disappearance times: DT50 DT90 -parent 19 64 +parent 20 68 diff --git a/tests/testthat/summary_saem_biphasic_s.txt b/tests/testthat/summary_saem_dfop_sfo_s.txt index 7c337843..7c337843 100644 --- a/tests/testthat/summary_saem_biphasic_s.txt +++ b/tests/testthat/summary_saem_dfop_sfo_s.txt diff --git a/tests/testthat/test_mixed.R b/tests/testthat/test_mixed.R index 2d53c6dd..ab8dfc27 100644 --- a/tests/testthat/test_mixed.R +++ b/tests/testthat/test_mixed.R @@ -1,22 +1,23 @@ context("Nonlinear mixed-effects models") + # Round error model parameters as they are not rounded in print methods dfop_nlme_1$modelStruct$varStruct$const <- signif(dfop_nlme_1$modelStruct$varStruct$const, 3) dfop_nlme_1$modelStruct$varStruct$prop <- signif(dfop_nlme_1$modelStruct$varStruct$prop, 4) +dfop_sfo_pop <- attr(ds_dfop_sfo, "pop") + test_that("Print methods work", { expect_known_output(print(fits[, 2:3], digits = 2), "print_mmkin_parent.txt") expect_known_output(print(mixed(mmkin_sfo_1), digits = 2), "print_mmkin_sfo_1_mixed.txt") expect_known_output(print(dfop_nlme_1, digits = 1), "print_dfop_nlme_1.txt") + expect_known_output(print(sfo_saem_1_reduced, digits = 1), "print_sfo_saem_1_reduced.txt") - # In order to address the platform dependence of the results, we round to two - # significant digits before printing - dfop_saemix_1_print <- dfop_saemix_1 - dfop_saemix_1_print$so@results@conf.int[c("estimate", "lower", "upper")] <- - signif(dfop_saemix_1_print$so@results@conf.int[c("estimate", "lower", "upper")], 2) - expect_known_output(print(dfop_saemix_1_print, digits = 1), "print_dfop_saemix_1.txt") + skip_on_cran() # The following test is platform dependent and fails on + # win-builder with current (18 Nov 2022) R-devel and on the Fedora CRAN check systems + expect_known_output(print(dfop_saem_1, digits = 1), "print_dfop_saem_1.txt") }) test_that("nlme results are reproducible to some degree", { @@ -36,17 +37,16 @@ test_that("nlme results are reproducible to some degree", { # k1 and k2 just fail the first test (lower bound of the ci), so we need to exclude it dfop_no_k1_k2 <- c("parent_0", "k_m1", "f_parent_to_m1", "g") dfop_sfo_pop_no_k1_k2 <- as.numeric(dfop_sfo_pop[dfop_no_k1_k2]) - dfop_sfo_pop <- as.numeric(dfop_sfo_pop) # to remove names - ci_dfop_sfo_n <- summary(nlme_biphasic)$confint_back + ci_dfop_sfo_n <- summary(nlme_dfop_sfo)$confint_back expect_true(all(ci_dfop_sfo_n[dfop_no_k1_k2, "lower"] < dfop_sfo_pop_no_k1_k2)) - expect_true(all(ci_dfop_sfo_n[, "upper"] > dfop_sfo_pop)) + expect_true(all(ci_dfop_sfo_n[, "upper"] > as.numeric(dfop_sfo_pop))) }) test_that("saemix results are reproducible for biphasic fits", { - test_summary <- summary(saem_biphasic_s) + test_summary <- summary(saem_dfop_sfo_s) test_summary$saemixversion <- "Dummy 0.0 for testing" test_summary$mkinversion <- "Dummy 0.0 for testing" test_summary$Rversion <- "Dummy R version for testing" @@ -54,33 +54,33 @@ test_that("saemix results are reproducible for biphasic fits", { test_summary$date.summary <- "Dummy date for testing" test_summary$time <- c(elapsed = "test time 0") - expect_known_output(print(test_summary, digits = 1), "summary_saem_biphasic_s.txt") + expect_known_output(print(test_summary, digits = 1), "summary_saem_dfop_sfo_s.txt") dfop_sfo_pop <- as.numeric(dfop_sfo_pop) no_k1 <- c(1, 2, 3, 5, 6) no_k2 <- c(1, 2, 3, 4, 6) no_k1_k2 <- c(1, 2, 3, 6) - ci_dfop_sfo_s_s <- summary(saem_biphasic_s)$confint_back + ci_dfop_sfo_s_s <- summary(saem_dfop_sfo_s)$confint_back expect_true(all(ci_dfop_sfo_s_s[, "lower"] < dfop_sfo_pop)) expect_true(all(ci_dfop_sfo_s_s[, "upper"] > dfop_sfo_pop)) # k2 is not fitted well - ci_dfop_sfo_s_m <- summary(saem_biphasic_m)$confint_back + ci_dfop_sfo_s_m <- summary(saem_dfop_sfo_m)$confint_back expect_true(all(ci_dfop_sfo_s_m[no_k2, "lower"] < dfop_sfo_pop[no_k2])) expect_true(all(ci_dfop_sfo_s_m[no_k1, "upper"] > dfop_sfo_pop[no_k1])) # I tried to only do few iterations in routine tests as this is so slow # but then deSolve fails at some point (presumably at the switch between # the two types of iterations) - #saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve", + #saem_dfop_sfo_2 <- saem(mmkin_biphasic, solution_type = "deSolve", # control = list(nbiter.saemix = c(10, 5), nbiter.burn = 5), quiet = TRUE) skip("Fitting with saemix takes around 10 minutes when using deSolve") - saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve", quiet = TRUE) + saem_dfop_sfo_2 <- saem(mmkin_dfop_sfo, solution_type = "deSolve", quiet = TRUE) # As with the analytical solution, k1 and k2 are not fitted well - ci_dfop_sfo_s_d <- summary(saem_biphasic_2)$confint_back + ci_dfop_sfo_s_d <- summary(saem_dfop_sfo_2)$confint_back expect_true(all(ci_dfop_sfo_s_d[no_k2, "lower"] < dfop_sfo_pop[no_k2])) expect_true(all(ci_dfop_sfo_s_d[no_k1, "upper"] > dfop_sfo_pop[no_k1])) }) diff --git a/tests/testthat/test_multistart.R b/tests/testthat/test_multistart.R index 502cee98..3a511e06 100644 --- a/tests/testthat/test_multistart.R +++ b/tests/testthat/test_multistart.R @@ -9,26 +9,22 @@ test_that("multistart works for saem.mmkin models", { best(saem_sfo_s_multi), test = TRUE ) - # On winbuilder, sfo_saem_1 gives an AIC of 1310.8, while we get 1311.7 - # locally (using saemix 3.2, which likely makes the difference due to the - # error parameter patch) on Linux and Windows. The other, well-determined - # fits both give 1309.7. - expect_equal(round(anova_sfo, 1)["sfo_saem_1_reduced", "AIC"], 1309.7) - expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1309.7) - expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, CRAN: 0.4 + expect_equal(round(anova_sfo, 1)["sfo_saem_1_reduced", "AIC"], 1302.2) + expect_equal(round(anova_sfo, 1)["best(saem_sfo_s_multi)", "AIC"], 1302.2) + expect_true(anova_sfo[3, "Pr(>Chisq)"] > 0.2) # Local: 1, win-builder: 0.4 set.seed(123456) - saem_biphasic_m_multi <- multistart(saem_biphasic_m, n = 8, + saem_dfop_sfo_m_multi <- multistart(saem_dfop_sfo_m, n = 8, cores = n_cores) - expect_known_output(print(saem_biphasic_m_multi), - file = "print_multistart_biphasic.txt") + expect_known_output(print(saem_dfop_sfo_m_multi), + file = "print_multistart_dfop_sfo.txt") - anova_biphasic <- anova(saem_biphasic_m, - best(saem_biphasic_m_multi)) + anova_dfop_sfo <- anova(saem_dfop_sfo_m, + best(saem_dfop_sfo_m_multi)) # With the new starting parameters we do not improve # with multistart any more - expect_equal(anova_biphasic[2, "AIC"], anova_biphasic[1, "AIC"], + expect_equal(anova_dfop_sfo[2, "AIC"], anova_dfop_sfo[1, "AIC"], tolerance = 1e-4) skip_on_travis() # Plots are platform dependent @@ -37,10 +33,10 @@ test_that("multistart works for saem.mmkin models", { vdiffr::expect_doppelganger("llhist for sfo fit", llhist_sfo) vdiffr::expect_doppelganger("parplot for sfo fit", parplot_sfo) - llhist_biphasic <- function() llhist(saem_biphasic_m_multi) - parplot_biphasic <- function() parplot(saem_biphasic_m_multi, + llhist_dfop_sfo <- function() llhist(saem_dfop_sfo_m_multi) + parplot_dfop_sfo <- function() parplot(saem_dfop_sfo_m_multi, ylim = c(0.5, 2)) - vdiffr::expect_doppelganger("llhist for biphasic saemix fit", llhist_biphasic) - vdiffr::expect_doppelganger("parplot for biphasic saemix fit", parplot_biphasic) + vdiffr::expect_doppelganger("llhist for dfop sfo fit", llhist_dfop_sfo) + vdiffr::expect_doppelganger("parplot for dfop sfo fit", parplot_dfop_sfo) }) diff --git a/tests/testthat/test_plot.R b/tests/testthat/test_plot.R index 13058c00..01b0c1ee 100644 --- a/tests/testthat/test_plot.R +++ b/tests/testthat/test_plot.R @@ -44,24 +44,24 @@ test_that("Plotting mkinfit, mmkin and mixed model objects is reproducible", { f_uba_dfop_sfo_saem <- saem(f_uba_mmkin["DFOP-SFO", ], quiet = TRUE, transformations = "saemix") - plot_biphasic_mmkin <- function() plot(f_uba_dfop_sfo_mixed, pop_curve = TRUE) - vdiffr::expect_doppelganger("mixed model fit for mmkin object", plot_biphasic_mmkin) + plot_dfop_sfo_mmkin <- function() plot(f_uba_dfop_sfo_mixed, pop_curve = TRUE) + vdiffr::expect_doppelganger("mixed model fit for mmkin object", plot_dfop_sfo_mmkin) - plot_biphasic_saem_s <- function() plot(f_uba_dfop_sfo_saem) - vdiffr::expect_doppelganger("mixed model fit for saem object with saemix transformations", plot_biphasic_saem_s) + plot_dfop_sfo_saem_s <- function() plot(f_uba_dfop_sfo_saem) + vdiffr::expect_doppelganger("mixed model fit for saem object with saemix transformations", plot_dfop_sfo_saem_s) skip_on_travis() - plot_biphasic_nlme <- function() plot(dfop_nlme_1) - vdiffr::expect_doppelganger("mixed model fit for nlme object", plot_biphasic_nlme) + plot_dfop_sfo_nlme <- function() plot(dfop_nlme_1) + vdiffr::expect_doppelganger("mixed model fit for nlme object", plot_dfop_sfo_nlme) - #plot_biphasic_mmkin <- function() plot(mixed(mmkin_biphasic)) + #plot_dfop_sfo_mmkin <- function() plot(mixed(mmkin_dfop_sfo)) # Biphasic fits with lots of data and fits have lots of potential for differences - plot_biphasic_nlme <- function() plot(nlme_biphasic) - #plot_biphasic_saem_s <- function() plot(saem_biphasic_s) - plot_biphasic_saem_m <- function() plot(saem_biphasic_m) + plot_dfop_sfo_nlme <- function() plot(nlme_dfop_sfo) + #plot_dfop_sfo_saem_s <- function() plot(saem_dfop_sfo_s) + plot_dfop_sfo_saem_m <- function() plot(saem_dfop_sfo_m) - vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_biphasic_saem_m) + vdiffr::expect_doppelganger("mixed model fit for saem object with mkin transformations", plot_dfop_sfo_saem_m) # different results when working with eigenvalues plot_errmod_fit_D_obs_eigen <- function() plot_err(fit_D_obs_eigen, sep_obs = FALSE) diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index 20889c6c..31605931 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -38,11 +38,11 @@ test_that("Parent fits using saemix are correctly implemented", { s_sfo_nlme_1 <- summary(sfo_nlme_1) # Compare with input - expect_equal(round(s_sfo_saem_1$confint_ranef["SD.k_parent", "est."], 1), 0.3) - expect_equal(round(s_sfo_saem_1_mkin$confint_ranef["SD.log_k_parent", "est."], 1), 0.3) + expect_equal(round(s_sfo_saem_1$confint_ranef["SD.k_parent", "est."], 1), 0.3, tol = 0.1) + expect_equal(round(s_sfo_saem_1_mkin$confint_ranef["SD.log_k_parent", "est."], 1), 0.3, tol = 0.1) # k_parent is a bit different from input 0.03 here - expect_equal(round(s_sfo_saem_1$confint_back["k_parent", "est."], 3), 0.035) - expect_equal(round(s_sfo_saem_1_mkin$confint_back["k_parent", "est."], 3), 0.035) + expect_equal(round(s_sfo_saem_1$confint_back["k_parent", "est."], 3), 0.033) + expect_equal(round(s_sfo_saem_1_mkin$confint_back["k_parent", "est."], 3), 0.033) # But the result is pretty unanimous between methods expect_equal(round(s_sfo_saem_1_reduced$confint_back["k_parent", "est."], 3), @@ -74,7 +74,7 @@ test_that("Parent fits using saemix are correctly implemented", { mmkin_fomc_1 <- mmkin("FOMC", ds_fomc, quiet = TRUE, error_model = "tc", cores = n_cores) fomc_saem_1 <- saem(mmkin_fomc_1, quiet = TRUE, transformations = "saemix", no_random_effect = "parent_0") - fomc_pop <- as.numeric(fomc_pop) + fomc_pop <- as.numeric(attr(ds_fomc, "pop")) ci_fomc_s1 <- summary(fomc_saem_1)$confint_back expect_true(all(ci_fomc_s1[, "lower"] < fomc_pop)) expect_true(all(ci_fomc_s1[, "upper"] > fomc_pop)) @@ -87,14 +87,14 @@ test_that("Parent fits using saemix are correctly implemented", { expect_equal(endpoints(fomc_saem_1), endpoints(fomc_saem_2), tol = 0.01) # DFOP - dfop_saemix_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix", + dfop_saem_2 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "saemix", no_random_effect = "parent_0") - s_dfop_s1 <- summary(dfop_saemix_1) # mkin transformations - s_dfop_s2 <- summary(dfop_saemix_2) # saemix transformations + s_dfop_s1 <- summary(dfop_saem_1) # mkin transformations + s_dfop_s2 <- summary(dfop_saem_2) # saemix transformations s_dfop_n <- summary(dfop_nlme_1) - dfop_pop <- as.numeric(dfop_pop) + dfop_pop <- as.numeric(attr(ds_dfop, "pop")) expect_true(all(s_dfop_s1$confint_back[, "lower"] < dfop_pop)) expect_true(all(s_dfop_s1$confint_back[, "upper"] > dfop_pop)) @@ -111,18 +111,18 @@ test_that("Parent fits using saemix are correctly implemented", { # SFORB mmkin_sforb_1 <- mmkin("SFORB", ds_dfop, quiet = TRUE, cores = n_cores) - sforb_saemix_1 <- saem(mmkin_sforb_1, quiet = TRUE, + sforb_saem_1 <- saem(mmkin_sforb_1, quiet = TRUE, no_random_effect = c("parent_free_0"), transformations = "mkin") - sforb_saemix_2 <- saem(mmkin_sforb_1, quiet = TRUE, + sforb_saem_2 <- saem(mmkin_sforb_1, quiet = TRUE, no_random_effect = c("parent_free_0"), transformations = "saemix") expect_equal( - log(endpoints(dfop_saemix_1)$distimes[1:2]), - log(endpoints(sforb_saemix_1)$distimes[1:2]), tolerance = 0.01) + log(endpoints(dfop_saem_1)$distimes[1:2]), + log(endpoints(sforb_saem_1)$distimes[1:2]), tolerance = 0.01) expect_equal( - log(endpoints(sforb_saemix_1)$distimes[1:2]), - log(endpoints(sforb_saemix_2)$distimes[1:2]), tolerance = 0.01) + log(endpoints(sforb_saem_1)$distimes[1:2]), + log(endpoints(sforb_saem_2)$distimes[1:2]), tolerance = 0.01) mmkin_hs_1 <- mmkin("HS", ds_hs, quiet = TRUE, error_model = "const", cores = n_cores) hs_saem_1 <- saem(mmkin_hs_1, quiet = TRUE, no_random_effect = "parent_0") @@ -131,7 +131,7 @@ test_that("Parent fits using saemix are correctly implemented", { expect_equal(endpoints(hs_saem_1), endpoints(hs_saem_2), tol = 0.01) ci_hs_s1 <- summary(hs_saem_1)$confint_back - hs_pop <- as.numeric(hs_pop) + hs_pop <- as.numeric(attr(ds_hs, "pop")) #expect_true(all(ci_hs_s1[, "lower"] < hs_pop)) # k1 is overestimated expect_true(all(ci_hs_s1[, "upper"] > hs_pop)) }) @@ -141,10 +141,10 @@ test_that("We can also use mkin solution methods for saem", { "saemix transformations is only supported if an analytical solution is implemented" ) skip("This still takes almost 2.5 minutes although we do not solve ODEs") - dfop_saemix_3 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", - solution_type = "analytical", no_random_effect = "parent_0") - distimes_dfop <- endpoints(dfop_saemix_1)$distimes - distimes_dfop_analytical <- endpoints(dfop_saemix_3)$distimes + dfop_saem_3 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", + solution_type = "analytical", no_random_effect = c("parent_0", "g_qlogis")) + distimes_dfop <- endpoints(dfop_saem_1)$distimes + distimes_dfop_analytical <- endpoints(dfop_saem_3)$distimes rel_diff <- abs(distimes_dfop_analytical - distimes_dfop) / distimes_dfop expect_true(all(rel_diff < 0.01)) }) |