From 92bd33824bde6b6b21bfc7e30953092a74d3cce5 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 7 May 2020 22:13:33 +0200 Subject: Another overhaul of analytical solutions Still in preparation for analytical solutions of coupled models --- tests/testthat/FOCUS_2006_D.csf | 2 +- tests/testthat/SFO_SFO_printed.txt | 6 +-- tests/testthat/summary_DFOP_FOCUS_C.txt | 5 ++ tests/testthat/summary_DFOP_FOCUS_D_deSolve.txt | 70 +++++++++++++------------ tests/testthat/summary_DFOP_FOCUS_D_eigen.txt | 60 +++++++++++---------- tests/testthat/test_SFORB.R | 8 ++- tests/testthat/test_nlme.R | 12 ++--- 7 files changed, 90 insertions(+), 73 deletions(-) (limited to 'tests') diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf index fa96de74..7c29ab46 100644 --- a/tests/testthat/FOCUS_2006_D.csf +++ b/tests/testthat/FOCUS_2006_D.csf @@ -5,7 +5,7 @@ Description: MeasurementUnits: % AR TimeUnits: days Comments: Created using mkin::CAKE_export -Date: 2020-05-06 +Date: 2020-05-07 Optimiser: IRLS [Data] diff --git a/tests/testthat/SFO_SFO_printed.txt b/tests/testthat/SFO_SFO_printed.txt index d0402fc0..a3a04be2 100644 --- a/tests/testthat/SFO_SFO_printed.txt +++ b/tests/testthat/SFO_SFO_printed.txt @@ -1,5 +1,5 @@ model generated with -Use of formation fractions $use_of_ff: min +Use of formation fractions $use_of_ff: max Specification $spec: $parent $type: SFO; $to: m1; $sink: TRUE @@ -7,5 +7,5 @@ $m1 $type: SFO; $sink: TRUE Coefficient matrix $coefmat available Differential equations: -d_parent/dt = - k_parent_sink * parent - k_parent_m1 * parent -d_m1/dt = + k_parent_m1 * parent - k_m1_sink * m1 +d_parent/dt = - k_parent * parent +d_m1/dt = + f_parent_to_m1 * k_parent * parent - k_m1 * m1 diff --git a/tests/testthat/summary_DFOP_FOCUS_C.txt b/tests/testthat/summary_DFOP_FOCUS_C.txt index 14e00f62..4f96c8d3 100644 --- a/tests/testthat/summary_DFOP_FOCUS_C.txt +++ b/tests/testthat/summary_DFOP_FOCUS_C.txt @@ -33,6 +33,11 @@ g_ilr 0.000000 -Inf Inf Fixed parameter values: None +Results: + + AIC BIC logLik + 29.02372 30.00984 -9.511861 + Optimised, transformed parameters with symmetric confidence intervals: Estimate Std. Error Lower Upper parent_0 85.0000 0.66620 83.1500 86.8500 diff --git a/tests/testthat/summary_DFOP_FOCUS_D_deSolve.txt b/tests/testthat/summary_DFOP_FOCUS_D_deSolve.txt index 66ab9348..fe697794 100644 --- a/tests/testthat/summary_DFOP_FOCUS_D_deSolve.txt +++ b/tests/testthat/summary_DFOP_FOCUS_D_deSolve.txt @@ -4,8 +4,8 @@ Date of fit: Dummy date for testing Date of summary: Dummy date for testing Equations: -d_parent/dt = - k_parent_sink * parent - k_parent_m1 * parent -d_m1/dt = + k_parent_m1 * parent - k_m1_sink * m1 +d_parent/dt = - k_parent * parent +d_m1/dt = + f_parent_to_m1 * k_parent * parent - k_m1 * m1 Model predictions using solution type deSolve @@ -16,30 +16,35 @@ Error model: Constant variance Error model algorithm: OLS Starting values for parameters to be optimised: - value type -parent_0 100.7500 state -k_parent_sink 0.1000 deparm -k_parent_m1 0.1001 deparm -k_m1_sink 0.1002 deparm + value type +parent_0 100.7500 state +k_parent 0.1000 deparm +k_m1 0.1001 deparm +f_parent_to_m1 0.5000 deparm Starting values for the transformed parameters actually optimised: - value lower upper -parent_0 100.750000 -Inf Inf -log_k_parent_sink -2.302585 -Inf Inf -log_k_parent_m1 -2.301586 -Inf Inf -log_k_m1_sink -2.300587 -Inf Inf + value lower upper +parent_0 100.750000 -Inf Inf +log_k_parent -2.302585 -Inf Inf +log_k_m1 -2.301586 -Inf Inf +f_parent_ilr_1 0.000000 -Inf Inf Fixed parameter values: value type m1_0 0 state +Results: + + AIC BIC logLik + 204.4486 212.6365 -97.22429 + Optimised, transformed parameters with symmetric confidence intervals: - Estimate Std. Error Lower Upper -parent_0 99.600 1.57000 96.400 102.800 -log_k_parent_sink -3.038 0.07626 -3.193 -2.883 -log_k_parent_m1 -2.980 0.04033 -3.062 -2.898 -log_k_m1_sink -5.248 0.13320 -5.518 -4.977 -sigma 3.126 0.35850 2.396 3.855 + Estimate Std. Error Lower Upper +parent_0 99.60000 1.57000 96.40000 102.8000 +log_k_parent -2.31600 0.04087 -2.39900 -2.2330 +log_k_m1 -5.24800 0.13320 -5.51800 -4.9770 +f_parent_ilr_1 0.04096 0.06312 -0.08746 0.1694 +sigma 3.12600 0.35850 2.39600 3.8550 Parameter correlation: NULL @@ -48,24 +53,23 @@ Backtransformed parameters: Confidence intervals for internally transformed parameters are asymmetric. t-test (unrealistically) based on the assumption of normal distribution for estimators of untransformed parameters. - Estimate t value Pr(>t) Lower Upper -parent_0 99.600000 63.430 2.298e-36 96.400000 1.028e+02 -k_parent_sink 0.047920 13.110 6.126e-15 0.041030 5.596e-02 -k_parent_m1 0.050780 24.800 3.269e-23 0.046780 5.512e-02 -k_m1_sink 0.005261 7.510 6.165e-09 0.004012 6.898e-03 -sigma 3.126000 8.718 2.235e-10 2.396000 3.855e+00 + Estimate t value Pr(>t) Lower Upper +parent_0 99.600000 63.430 2.298e-36 96.400000 1.028e+02 +k_parent 0.098700 24.470 4.955e-23 0.090820 1.073e-01 +k_m1 0.005261 7.510 6.165e-09 0.004012 6.898e-03 +f_parent_to_m1 0.514500 23.070 3.104e-22 0.469100 5.596e-01 +sigma 3.126000 8.718 2.235e-10 2.396000 3.855e+00 FOCUS Chi2 error levels in percent: err.min n.optim df All data 6.398 4 15 -parent 6.827 3 6 -m1 4.490 1 9 +parent 6.459 2 7 +m1 4.690 2 8 Resulting formation fractions: ff -parent_sink 0.4855 parent_m1 0.5145 -m1_sink 1.0000 +parent_sink 0.4855 Estimated disappearance times: DT50 DT90 @@ -78,10 +82,10 @@ Data: 0 parent 102.04 99.59848 2.442e+00 1 parent 93.50 90.23787 3.262e+00 1 parent 92.50 90.23787 2.262e+00 - 3 parent 63.23 74.07320 -1.084e+01 - 3 parent 68.99 74.07320 -5.083e+00 - 7 parent 52.32 49.91207 2.408e+00 - 7 parent 55.13 49.91207 5.218e+00 + 3 parent 63.23 74.07319 -1.084e+01 + 3 parent 68.99 74.07319 -5.083e+00 + 7 parent 52.32 49.91206 2.408e+00 + 7 parent 55.13 49.91206 5.218e+00 14 parent 27.27 25.01257 2.257e+00 14 parent 26.64 25.01257 1.627e+00 21 parent 11.50 12.53462 -1.035e+00 @@ -91,7 +95,7 @@ Data: 50 parent 0.69 0.71624 -2.624e-02 50 parent 0.63 0.71624 -8.624e-02 75 parent 0.05 0.06074 -1.074e-02 - 75 parent 0.06 0.06074 -7.382e-04 + 75 parent 0.06 0.06074 -7.381e-04 1 m1 4.84 4.80296 3.704e-02 1 m1 5.64 4.80296 8.370e-01 3 m1 12.91 13.02400 -1.140e-01 diff --git a/tests/testthat/summary_DFOP_FOCUS_D_eigen.txt b/tests/testthat/summary_DFOP_FOCUS_D_eigen.txt index 1626c5da..6ddbc1ab 100644 --- a/tests/testthat/summary_DFOP_FOCUS_D_eigen.txt +++ b/tests/testthat/summary_DFOP_FOCUS_D_eigen.txt @@ -4,8 +4,8 @@ Date of fit: Dummy date for testing Date of summary: Dummy date for testing Equations: -d_parent/dt = - k_parent_sink * parent - k_parent_m1 * parent -d_m1/dt = + k_parent_m1 * parent - k_m1_sink * m1 +d_parent/dt = - k_parent * parent +d_m1/dt = + f_parent_to_m1 * k_parent * parent - k_m1 * m1 Model predictions using solution type eigen @@ -16,30 +16,35 @@ Error model: Constant variance Error model algorithm: OLS Starting values for parameters to be optimised: - value type -parent_0 100.7500 state -k_parent_sink 0.1000 deparm -k_parent_m1 0.1001 deparm -k_m1_sink 0.1002 deparm + value type +parent_0 100.7500 state +k_parent 0.1000 deparm +k_m1 0.1001 deparm +f_parent_to_m1 0.5000 deparm Starting values for the transformed parameters actually optimised: - value lower upper -parent_0 100.750000 -Inf Inf -log_k_parent_sink -2.302585 -Inf Inf -log_k_parent_m1 -2.301586 -Inf Inf -log_k_m1_sink -2.300587 -Inf Inf + value lower upper +parent_0 100.750000 -Inf Inf +log_k_parent -2.302585 -Inf Inf +log_k_m1 -2.301586 -Inf Inf +f_parent_ilr_1 0.000000 -Inf Inf Fixed parameter values: value type m1_0 0 state +Results: + + AIC BIC logLik + 204.4486 212.6365 -97.22429 + Optimised, transformed parameters with symmetric confidence intervals: - Estimate Std. Error Lower Upper -parent_0 99.600 1.57000 96.400 102.800 -log_k_parent_sink -3.038 0.07626 -3.193 -2.883 -log_k_parent_m1 -2.980 0.04033 -3.062 -2.898 -log_k_m1_sink -5.248 0.13320 -5.518 -4.977 -sigma 3.126 0.35850 2.396 3.855 + Estimate Std. Error Lower Upper +parent_0 99.60000 1.57000 96.40000 102.8000 +log_k_parent -2.31600 0.04087 -2.39900 -2.2330 +log_k_m1 -5.24800 0.13320 -5.51800 -4.9770 +f_parent_ilr_1 0.04096 0.06312 -0.08746 0.1694 +sigma 3.12600 0.35850 2.39600 3.8550 Parameter correlation: NULL @@ -48,24 +53,23 @@ Backtransformed parameters: Confidence intervals for internally transformed parameters are asymmetric. t-test (unrealistically) based on the assumption of normal distribution for estimators of untransformed parameters. - Estimate t value Pr(>t) Lower Upper -parent_0 99.600000 63.430 2.298e-36 96.400000 1.028e+02 -k_parent_sink 0.047920 13.110 6.126e-15 0.041030 5.596e-02 -k_parent_m1 0.050780 24.800 3.269e-23 0.046780 5.512e-02 -k_m1_sink 0.005261 7.510 6.165e-09 0.004012 6.898e-03 -sigma 3.126000 8.718 2.235e-10 2.396000 3.855e+00 + Estimate t value Pr(>t) Lower Upper +parent_0 99.600000 63.430 2.298e-36 96.400000 1.028e+02 +k_parent 0.098700 24.470 4.955e-23 0.090820 1.073e-01 +k_m1 0.005261 7.510 6.165e-09 0.004012 6.898e-03 +f_parent_to_m1 0.514500 23.070 3.104e-22 0.469100 5.596e-01 +sigma 3.126000 8.718 2.235e-10 2.396000 3.855e+00 FOCUS Chi2 error levels in percent: err.min n.optim df All data 6.398 4 15 -parent 6.827 3 6 -m1 4.490 1 9 +parent 6.459 2 7 +m1 4.690 2 8 Resulting formation fractions: ff -parent_sink 0.4855 parent_m1 0.5145 -m1_sink 1.0000 +parent_sink 0.4855 Estimated disappearance times: DT50 DT90 diff --git a/tests/testthat/test_SFORB.R b/tests/testthat/test_SFORB.R index ad9881a8..4fb736ec 100644 --- a/tests/testthat/test_SFORB.R +++ b/tests/testthat/test_SFORB.R @@ -14,17 +14,21 @@ test_that("Fitting the SFORB model is equivalent to fitting DFOP", { M1 = mkinsub("SFO"), use_of_ff = "max", quiet = TRUE) SFORB_SFO <- mkinmod(parent = mkinsub("SFORB", "M1"), + M1 = mkinsub("SFO"), + use_of_ff = "min", quiet = TRUE) + SFORB_SFO_ff <- mkinmod(parent = mkinsub("SFORB", "M1"), M1 = mkinsub("SFO"), use_of_ff = "max", quiet = TRUE) - SFORB_SFO$coefmat - f_dfop_sfo <- mkinfit(DFOP_SFO, DFOP_par_c, quiet = TRUE) f_sforb_sfo <- mkinfit(SFORB_SFO, DFOP_par_c, quiet = TRUE) + f_sforb_sfo_ff <- mkinfit(SFORB_SFO_ff, DFOP_par_c, quiet = TRUE) f_sforb_sfo_eigen <- mkinfit(SFORB_SFO, DFOP_par_c, solution_type = "eigen", quiet = TRUE) expect_equivalent(endpoints(f_sforb_sfo)$distimes, endpoints(f_dfop_sfo)$distimes, tolerance = 1e-6) + expect_equivalent(endpoints(f_sforb_sfo_ff)$distimes, endpoints(f_dfop_sfo)$distimes, + tolerance = 1e-6) expect_equivalent(endpoints(f_sforb_sfo_eigen)$distimes, endpoints(f_dfop_sfo)$distimes, tolerance = 1e-6) }) diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R index e5e19c60..31fb19de 100644 --- a/tests/testthat/test_nlme.R +++ b/tests/testthat/test_nlme.R @@ -2,20 +2,21 @@ context("Nonlinear mixed-effects models") library(nlme) +sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) + test_that("nlme_function works correctly", { - sampling_times = c(0, 1, 3, 7, 14, 28, 60, 90, 120) m_SFO <- mkinmod(parent = mkinsub("SFO")) d_SFO_1 <- mkinpredict(m_SFO, - c(k_parent_sink = 0.1), + c(k_parent = 0.1), c(parent = 98), sampling_times) d_SFO_1_long <- mkin_wide_to_long(d_SFO_1, time = "time") d_SFO_2 <- mkinpredict(m_SFO, - c(k_parent_sink = 0.05), + c(k_parent = 0.05), c(parent = 102), sampling_times) d_SFO_2_long <- mkin_wide_to_long(d_SFO_2, time = "time") d_SFO_3 <- mkinpredict(m_SFO, - c(k_parent_sink = 0.02), + c(k_parent = 0.02), c(parent = 103), sampling_times) d_SFO_3_long <- mkin_wide_to_long(d_SFO_3, time = "time") @@ -33,7 +34,6 @@ test_that("nlme_function works correctly", { # The following assignment was introduced for nlme as evaluated by testthat # to find the function assign("nlme_f", nlme_f, pos = globalenv()) - assign("sampling_times", sampling_times, pos = globalenv()) m_nlme_raw <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink), data = grouped_data, @@ -101,7 +101,7 @@ test_that("nlme_function works correctly in other cases", { SFO <- mkinmod(parent = mkinsub("SFO")) pred_sfo <- function(k) { mkinpredict(SFO, - c(k_parent_sink = k), + c(k_parent = k), c(parent = 100), sampling_times) } -- cgit v1.2.1