diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testthat/print_saem_biphasic_s.txt | 37 | ||||
-rw-r--r-- | tests/testthat/summary_DFOP_FOCUS_C.txt | 125 | ||||
-rw-r--r-- | tests/testthat/summary_saem_biphasic_s.txt | 77 | ||||
-rw-r--r-- | tests/testthat/test_f_time_norm.R | 6 | ||||
-rw-r--r-- | tests/testthat/test_saem.R | 16 |
5 files changed, 194 insertions, 67 deletions
diff --git a/tests/testthat/print_saem_biphasic_s.txt b/tests/testthat/print_saem_biphasic_s.txt new file mode 100644 index 00000000..4d20117e --- /dev/null +++ b/tests/testthat/print_saem_biphasic_s.txt @@ -0,0 +1,37 @@ +Kinetic nonlinear mixed-effects model fit by SAEM +Structural model: +d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * + time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time))) + * parent +d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g) + * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * + exp(-k2 * time))) * parent - k_m1 * m1 + +Data: +509 observations of 2 variable(s) grouped in 15 datasets + +Likelihood computed by importance sampling + AIC BIC logLik + 2692 2702 -1333 + +Fitted parameters: + estimate lower upper +parent_0 1.002e+02 99.302986 1.011e+02 +k_m1 2.182e-03 0.001576 2.788e-03 +f_parent_to_m1 4.883e-01 0.447687 5.289e-01 +k1 4.014e-02 0.023941 5.634e-02 +k2 1.517e-02 0.008507 2.184e-02 +g 5.007e-01 0.380534 6.208e-01 +Var.parent_0 1.511e+00 -0.551247 3.574e+00 +Var.k_m1 1.912e-02 -0.151313 1.896e-01 +Var.f_parent_to_m1 8.082e-02 0.018430 1.432e-01 +Var.k1 5.037e-01 0.095343 9.121e-01 +Var.k2 6.129e-01 0.124868 1.101e+00 +Var.g 7.107e-02 -0.244901 3.870e-01 +a.1 2.749e+00 2.568674 2.929e+00 +SD.parent_0 1.229e+00 0.390443 2.068e+00 +SD.k_m1 1.383e-01 -0.477984 7.545e-01 +SD.f_parent_to_m1 2.843e-01 0.174562 3.940e-01 +SD.k1 7.097e-01 0.422037 9.974e-01 +SD.k2 7.829e-01 0.471184 1.095e+00 +SD.g 2.666e-01 -0.326044 8.592e-01 diff --git a/tests/testthat/summary_DFOP_FOCUS_C.txt b/tests/testthat/summary_DFOP_FOCUS_C.txt index 2b0210c0..da3276e1 100644 --- a/tests/testthat/summary_DFOP_FOCUS_C.txt +++ b/tests/testthat/summary_DFOP_FOCUS_C.txt @@ -1,82 +1,77 @@ -mkin version used for fitting: Dummy 0.0 for testing -R version used for fitting: Dummy R version for testing -Date of fit: Dummy date for testing -Date of summary: Dummy date for testing +saemix version used for fitting: 3.1.9000 +mkin version used for pre-fitting: 0.9.50.4 +R version used for fitting: 4.0.3 +Date of fit: Wed Dec 9 08:16:28 2020 +Date of summary: Wed Dec 9 08:23:19 2020 Equations: d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time))) * parent +d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g) + * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * + exp(-k2 * time))) * parent - k_m1 * m1 -Model predictions using solution type analytical - -Fitted using test 0 model solutions performed in test time 0 s +Data: +509 observations of 2 variable(s) grouped in 15 datasets -Error model: Constant variance +Model predictions using solution type analytical -Error model algorithm: OLS +Fitted in 10.222 s using 300, 100 iterations -Starting values for parameters to be optimised: - value type -parent_0 85.10 state -k1 0.10 deparm -k2 0.01 deparm -g 0.50 deparm +Variance model: Constant variance -Starting values for the transformed parameters actually optimised: - value lower upper -parent_0 85.100000 -Inf Inf -log_k1 -2.302585 -Inf Inf -log_k2 -4.605170 -Inf Inf -g_qlogis 0.000000 -Inf Inf +Mean of starting values for individual parameters: + parent_0 k_m1 f_parent_to_m1 k1 k2 + 1.007005e+02 1.837381e-03 4.803953e-01 4.534096e-02 1.918378e-02 + g + 5.068235e-01 -Fixed parameter values: +Fixed degradation 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 -log_k1 -0.7775 0.03380 -0.8713 -0.6836 -log_k2 -4.0260 0.13100 -4.3890 -3.6620 -g_qlogis 1.7660 0.08218 1.5380 1.9940 -sigma 0.6962 0.16410 0.2406 1.1520 - -Parameter correlation: -[1] "Correlation matrix is platform dependent, not tested" - -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 85.00000 127.600 1.131e-08 83.15000 86.85000 -k1 0.45960 29.580 3.887e-06 0.41840 0.50480 -k2 0.01785 7.636 7.901e-04 0.01241 0.02568 -g 0.85390 83.310 6.221e-08 0.82310 0.88020 -sigma 0.69620 4.243 6.618e-03 0.24060 1.15200 - -FOCUS Chi2 error levels in percent: - err.min n.optim df -All data 2.661 4 5 -parent 2.661 4 5 +Likelihood computed by importance sampling + AIC BIC logLik + 2692 2702 -1333 + +Optimised parameters: + est. lower upper +parent_0 1.002e+02 99.302986 1.011e+02 +k_m1 2.182e-03 0.001576 2.788e-03 +f_parent_to_m1 4.883e-01 0.447687 5.289e-01 +k1 4.014e-02 0.023941 5.634e-02 +k2 1.517e-02 0.008507 2.184e-02 +g 5.007e-01 0.380534 6.208e-01 + +Correlation: + prnt_0 k_m1 f_p__1 k1 k2 +k_m1 -0.152 +f_parent_to_m1 -0.138 0.396 +k1 0.085 -0.036 -0.026 +k2 0.005 0.067 0.018 -0.043 +g -0.075 -0.113 -0.029 -0.248 -0.263 + +Random effects: + est. lower upper +SD.parent_0 1.2293 0.3904 2.0682 +SD.k_m1 0.1383 -0.4780 0.7545 +SD.f_parent_to_m1 0.2843 0.1746 0.3940 +SD.k1 0.7097 0.4220 0.9974 +SD.k2 0.7829 0.4712 1.0946 +SD.g 0.2666 -0.3260 0.8592 + +Variance model: + est. lower upper +a.1 2.749 2.569 2.929 + +Resulting formation fractions: + ff +parent_m1 0.4883 +parent_sink 0.5117 Estimated disappearance times: - DT50 DT90 DT50back DT50_k1 DT50_k2 -parent 1.887 21.25 6.397 1.508 38.83 - -Data: - time variable observed predicted residual - 0 parent 85.1 85.003 0.09726 - 1 parent 57.9 58.039 -0.13912 - 3 parent 29.9 30.054 -0.15351 - 7 parent 14.6 13.866 0.73388 - 14 parent 9.7 9.787 -0.08657 - 28 parent 6.6 7.532 -0.93205 - 63 parent 4.0 4.033 -0.03269 - 91 parent 3.9 2.447 1.45348 - 119 parent 0.6 1.484 -0.88424 + DT50 DT90 DT50back DT50_k1 DT50_k2 +parent 27.07 110.1 33.14 17.27 45.68 +m1 317.69 1055.4 NA NA NA diff --git a/tests/testthat/summary_saem_biphasic_s.txt b/tests/testthat/summary_saem_biphasic_s.txt new file mode 100644 index 00000000..b5777ce1 --- /dev/null +++ b/tests/testthat/summary_saem_biphasic_s.txt @@ -0,0 +1,77 @@ +saemix version used for fitting: Dummy 0.0 for testing +mkin version used for pre-fitting: Dummy 0.0 for testing +R version used for fitting: Dummy R version for testing +Date of fit: Dummy date for testing +Date of summary: Dummy date for testing + +Equations: +d_parent/dt = - ((k1 * g * exp(-k1 * time) + k2 * (1 - g) * exp(-k2 * + time)) / (g * exp(-k1 * time) + (1 - g) * exp(-k2 * time))) + * parent +d_m1/dt = + f_parent_to_m1 * ((k1 * g * exp(-k1 * time) + k2 * (1 - g) + * exp(-k2 * time)) / (g * exp(-k1 * time) + (1 - g) * + exp(-k2 * time))) * parent - k_m1 * m1 + +Data: +509 observations of 2 variable(s) grouped in 15 datasets + +Model predictions using solution type analytical + +Fitted in test time 0 s using 300, 100 iterations + +Variance model: Constant variance + +Mean of starting values for individual parameters: + parent_0 k_m1 f_parent_to_m1 k1 k2 + 1.0e+02 1.8e-03 4.8e-01 4.5e-02 1.9e-02 + g + 5.1e-01 + +Fixed degradation parameter values: +None + +Results: + +Likelihood computed by importance sampling + AIC BIC logLik + 2692 2702 -1333 + +Optimised parameters: + est. lower upper +parent_0 1.0e+02 99.3030 1.0e+02 +k_m1 2.2e-03 0.0016 2.8e-03 +f_parent_to_m1 4.9e-01 0.4477 5.3e-01 +k1 4.0e-02 0.0239 5.6e-02 +k2 1.5e-02 0.0085 2.2e-02 +g 5.0e-01 0.3805 6.2e-01 + +Correlation: + prnt_0 k_m1 f_p__1 k1 k2 +k_m1 -0.152 +f_parent_to_m1 -0.138 0.396 +k1 0.085 -0.036 -0.026 +k2 0.005 0.067 0.018 -0.043 +g -0.075 -0.113 -0.029 -0.248 -0.263 + +Random effects: + est. lower upper +SD.parent_0 1.23 0.39 2.07 +SD.k_m1 0.14 -0.48 0.75 +SD.f_parent_to_m1 0.28 0.17 0.39 +SD.k1 0.71 0.42 1.00 +SD.k2 0.78 0.47 1.09 +SD.g 0.27 -0.33 0.86 + +Variance model: + est. lower upper +a.1 2.7 2.6 2.9 + +Resulting formation fractions: + ff +parent_m1 0.49 +parent_sink 0.51 + +Estimated disappearance times: + DT50 DT90 DT50back DT50_k1 DT50_k2 +parent 27 110 33 17 46 +m1 318 1055 NA NA NA diff --git a/tests/testthat/test_f_time_norm.R b/tests/testthat/test_f_time_norm.R new file mode 100644 index 00000000..790cce8b --- /dev/null +++ b/tests/testthat/test_f_time_norm.R @@ -0,0 +1,6 @@ +context("Time step normalisation") + +test_that("Simple temperature and moisture normalisation works", { + expect_equal(round(f_time_norm_focus(25, 20, 25), 2), 1.37) +}) + diff --git a/tests/testthat/test_saem.R b/tests/testthat/test_saem.R index 0b6d4531..d41efbfa 100644 --- a/tests/testthat/test_saem.R +++ b/tests/testthat/test_saem.R @@ -102,15 +102,27 @@ test_that("Parent only models can be fitted with saemix", { test_that("Simple models with metabolite can be fitted with saemix", { + expect_known_output(print(saem_biphasic_s), "print_saem_biphasic_s.txt") + + test_summary <- summary(saem_biphasic_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" + test_summary$date.fit <- "Dummy date for testing" + test_summary$date.summary <- "Dummy date for testing" + test_summary$time <- c(elapsed = "test time 0") + + expect_known_output(print(test_summary, digits = 2), "summary_saem_biphasic_s.txt") + dfop_sfo_pop <- as.numeric(dfop_sfo_pop) ci_dfop_sfo_s_s <- summary(saem_biphasic_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)) - # The following does not work, the k1 and k2 are not fitted well + # The following does not work, as k1 and k2 are not fitted well ci_dfop_sfo_s_m <- summary(saem_biphasic_m)$confint_back # expect_true(all(ci_dfop_sfo_s_m[, "lower"] < dfop_sfo_pop)) - #expect_true(all(ci_dfop_sfo_s_m[, "upper"] > dfop_sfo_pop)) + # expect_true(all(ci_dfop_sfo_s_m[, "upper"] > dfop_sfo_pop)) # Somehow this does not work at the moment. But it took forever (~ 10 min) anyways... #saem_biphasic_2 <- saem(mmkin_biphasic, solution_type = "deSolve", quiet = TRUE) |