aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2020-04-07 20:25:03 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2020-04-07 20:25:03 +0200
commitc5878e0c561a93f36f8fdc64d5839db2a0527572 (patch)
tree639611c6990ac19ec39d822f9d945e23e573d73d
parentc12aba04c7fdc745dec51ae5d640d8013c99b4dd (diff)
Add some tests for the nlme convenience functions
-rw-r--r--DESCRIPTION4
-rw-r--r--build.log2
-rw-r--r--man/mmkin.Rd5
-rw-r--r--test.log28
-rw-r--r--tests/testthat/FOCUS_2006_D.csf2
-rw-r--r--tests/testthat/test_nlme.R63
6 files changed, 89 insertions, 15 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index 1aa5cac2..a9d0e939 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,8 +1,8 @@
Package: mkin
Type: Package
Title: Kinetic Evaluation of Chemical Degradation Data
-Version: 0.9.49.9
-Date: 2020-03-31
+Version: 0.9.49.10
+Date: 2020-04-07
Authors@R: c(person("Johannes", "Ranke", role = c("aut", "cre", "cph"),
email = "jranke@uni-bremen.de",
comment = c(ORCID = "0000-0003-4371-6538")),
diff --git a/build.log b/build.log
index b0765ebb..af1a7be5 100644
--- a/build.log
+++ b/build.log
@@ -6,5 +6,5 @@
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* looking to see if a ‘data/datalist’ file should be added
-* building ‘mkin_0.9.49.9.tar.gz’
+* building ‘mkin_0.9.49.10.tar.gz’
diff --git a/man/mmkin.Rd b/man/mmkin.Rd
index 4bf07370..99895400 100644
--- a/man/mmkin.Rd
+++ b/man/mmkin.Rd
@@ -32,8 +32,9 @@ for parallel execution.}
\item{\dots}{Further arguments that will be passed to \code{\link{mkinfit}}.}
}
\value{
-A matrix of \code{\link{mkinfit}} objects that can be indexed using
- the model and dataset names as row and column indices.
+A two-dimensional \code{\link{array}} of \code{\link{mkinfit}}
+ objects that can be indexed using the model names for the first index (row index)
+ and the dataset names for the second index (column index).
}
\description{
This function calls \code{\link{mkinfit}} on all combinations of models and
diff --git a/test.log b/test.log
index 84b13a10..877d5193 100644
--- a/test.log
+++ b/test.log
@@ -6,15 +6,25 @@ Testing mkin
✔ | 4 | Calculation of FOCUS chi2 error levels [2.2 s]
✔ | 4 | Fitting the SFORB model [1.7 s]
✔ | 5 | Calculation of Akaike weights
-✔ | 10 | Confidence intervals and p-values [9.6 s]
-✔ | 14 | Error model fitting [38.4 s]
-✔ | 6 | Test fitting the decline of metabolites from their maximum [0.7 s]
+✔ | 10 | Confidence intervals and p-values [9.4 s]
+✔ | 14 | Error model fitting [37.5 s]
+✔ | 6 | Test fitting the decline of metabolites from their maximum [0.8 s]
✔ | 1 | Fitting the logistic model [0.9 s]
✔ | 1 | Test dataset class mkinds used in gmkin
-✔ | 12 | Special cases of mkinfit calls [2.2 s]
+✔ | 12 | Special cases of mkinfit calls [2.3 s]
✔ | 9 | mkinmod model generation and printing [0.2 s]
✔ | 3 | Model predictions with mkinpredict [0.3 s]
-✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.2 s]
+✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.1 s]
+✖ | 0 1 | Nonlinear mixed-effects models [1.3 s]
+────────────────────────────────────────────────────────────────────────────────
+test_nlme.R:37: error: nlme_function works correctly
+konnte Funktion "nlme_f" nicht finden
+Backtrace:
+ 1. nlme::nlme(...) tests/testthat/test_nlme.R:37:2
+ 2. nlme::nlme.formula(...)
+ 3. [ base::eval(...) ] with 1 more call
+ 5. [ base::eval(...) ] with 1 more call
+────────────────────────────────────────────────────────────────────────────────
✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2 s]
✔ | 3 | Summary
✔ | 11 | Plotting [0.6 s]
@@ -22,17 +32,17 @@ Testing mkin
✔ | 2 | Residuals extracted from mkinfit models
✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.3 s]
✔ | 1 | Summaries of old mkinfit objects
-✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.1 s]
-✔ | 7 1 | Hypothesis tests [32.5 s]
+✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.0 s]
+✔ | 7 1 | Hypothesis tests [31.9 s]
────────────────────────────────────────────────────────────────────────────────
test_tests.R:60: skip: We can do a likelihood ratio test using an update specification
Reason: This errors out if called by testthat while it works in a normal R session
────────────────────────────────────────────────────────────────────────────────
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 112.1 s
+Duration: 111.4 s
OK: 138
-Failed: 0
+Failed: 1
Warnings: 0
Skipped: 1
diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf
index fe5e481a..f492a57f 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-04-01
+Date: 2020-04-07
Optimiser: IRLS
[Data]
diff --git a/tests/testthat/test_nlme.R b/tests/testthat/test_nlme.R
new file mode 100644
index 00000000..b3c41f00
--- /dev/null
+++ b/tests/testthat/test_nlme.R
@@ -0,0 +1,63 @@
+context("Nonlinear mixed-effects models")
+
+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(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(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(parent = 103), sampling_times)
+ d_SFO_3_long <- mkin_wide_to_long(d_SFO_3, time = "time")
+
+ d1 <- add_err(d_SFO_1, function(value) 3, n = 1, seed = 123456)
+ d2 <- add_err(d_SFO_2, function(value) 2, n = 1, seed = 234567)
+ d3 <- add_err(d_SFO_3, function(value) 4, n = 1, seed = 345678)
+ ds <- c(d1 = d1, d2 = d2, d3 = d3)
+
+ f <- mmkin("SFO", ds, cores = 1, quiet = TRUE)
+
+ mean_dp <- mean_degparms(f)
+ grouped_data <- nlme_data(f)
+ nlme_f <- nlme_function(f)
+
+ m_nlme_raw <- nlme(value ~ SSasymp(time, 0, parent_0, log_k_parent_sink),
+ data = grouped_data,
+ fixed = parent_0 + log_k_parent_sink ~ 1,
+ random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
+ start = mean_dp)
+
+ m_nlme_mkin <- nlme(value ~ nlme_f(name, time, parent_0, log_k_parent_sink),
+ data = grouped_data,
+ fixed = parent_0 + log_k_parent_sink ~ 1,
+ random = pdDiag(parent_0 + log_k_parent_sink ~ 1),
+ start = mean_dp)
+
+ expect_equal(m_nlme_raw$coefficients, m_nlme_mkin$coefficients)
+
+ m_nlme_raw_up_1 <- update(m_nlme_raw, random = log_k_parent_sink ~ 1)
+ # The following two calls give an error although they should
+ # do the same as the call above
+ # The error occurs in the evaluation of the modelExpression in the
+ # call to .C(fit_nlme, ...)
+ # m_nlme_mkin_up_1 <- update(m_nlme_mkin, random = log_k_parent_sink ~ 1)
+ # m_nlme_mkin <- nlme(value ~ nlme_f(name, time, parent_0, log_k_parent_sink),
+ # data = grouped_data,
+ # fixed = parent_0 + log_k_parent_sink ~ 1,
+ # random = log_k_parent_sink ~ 1,
+ # start = mean_dp)
+
+ m_nlme_raw_up_2 <- update(m_nlme_raw, random = parent_0 ~ 1)
+ m_nlme_mkin_up_2 <- update(m_nlme_mkin, random = parent_0 ~ 1)
+ expect_equal(m_nlme_raw_up_2$coefficients, m_nlme_mkin_up_2$coefficients)
+
+ # update(m_nlme_mkin) # works
+
+})

Contact - Imprint