aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2022-11-01 09:46:33 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2022-11-01 09:46:33 +0100
commitfd4bd411df739903279d8b52faa19d5059afbda7 (patch)
treeca1ea04a1d6e54949e5d69147d5ac253efaf95d7
parent300aa6ec27529f46deda07874566dc8fcee4e6e7 (diff)
Improved printing for illparms()
For the case of single fits and no ill-defined parameters found
-rw-r--r--NAMESPACE2
-rw-r--r--R/illparms.R24
-rw-r--r--log/check.log6
-rw-r--r--log/test.log61
-rw-r--r--man/illparms.Rd7
-rw-r--r--tests/testthat/test_mhmkin.R3
-rw-r--r--tests/testthat/test_saemix_parent.R1
7 files changed, 80 insertions, 24 deletions
diff --git a/NAMESPACE b/NAMESPACE
index 877fc744..9f87fce6 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -44,7 +44,9 @@ S3method(plot,mkinfit)
S3method(plot,mmkin)
S3method(plot,nafta)
S3method(print,illparms.mhmkin)
+S3method(print,illparms.mkinfit)
S3method(print,illparms.mmkin)
+S3method(print,illparms.saem.mmkin)
S3method(print,mhmkin)
S3method(print,mixed.mmkin)
S3method(print,mkinds)
diff --git a/R/illparms.R b/R/illparms.R
index 931d8f05..003c6db1 100644
--- a/R/illparms.R
+++ b/R/illparms.R
@@ -22,8 +22,9 @@
#' tested?
#' @return For [mkinfit] or [saem] objects, a character vector of parameter
#' names. For [mmkin] or [mhmkin] objects, a matrix like object of class
-#' 'illparms.mmkin' or 'illparms.mhmkin'. The latter objects have a suitable
-#' printing method.
+#' 'illparms.mmkin' or 'illparms.mhmkin'.
+#' @note All objects have printing methods. For the single fits, printing
+#' does not output anything in the case no ill-defined parameters are found.
#' @export
illparms <- function(object, ...)
{
@@ -39,7 +40,18 @@ illparms.mkinfit <- function(object, conf.level = 0.95, ...) {
p_values <- suppressWarnings(summary(object)$bpar[, "Pr(>t)"])
na <- is.na(p_values)
failed <- p_values > 1 - conf.level
- names(parms(object))[na | failed]
+ ret <- names(parms(object))[na | failed]
+ class(ret) <- "illparms.mkinfit"
+ return(ret)
+}
+
+#' @rdname
+#' @export
+print.illparms.mkinfit <- function(x, ...) {
+ class(x) <- NULL
+ if (length(x) > 0) {
+ print(as.character(x))
+ }
}
#' @rdname illparms
@@ -82,7 +94,7 @@ print.illparms.mmkin <- function(x, ...) {
#' @export
illparms.saem.mmkin <- function(object, conf.level = 0.95, random = TRUE, errmod = TRUE, ...) {
if (inherits(object, "try-error")) {
- return(NA)
+ failed <- NA
} else {
ints <- intervals(object, conf.level = conf.level)
failed <- NULL
@@ -95,9 +107,13 @@ illparms.saem.mmkin <- function(object, conf.level = 0.95, random = TRUE, errmod
failed <- c(failed, names(which(failed_errmod)))
}
}
+ class(failed) <- "illparms.saem.mmkin"
return(failed)
}
+#' @export
+print.illparms.saem.mmkin <- print.illparms.mkinfit
+
#' @rdname illparms
#' @export
illparms.mhmkin <- function(object, conf.level = 0.95, random = TRUE, errmod = TRUE, ...) {
diff --git a/log/check.log b/log/check.log
index 36bd30ca..4092108e 100644
--- a/log/check.log
+++ b/log/check.log
@@ -1,5 +1,5 @@
* using log directory ‘/home/jranke/git/mkin/mkin.Rcheck’
-* using R version 4.2.1 (2022-06-23)
+* using R version 4.2.2 (2022-10-31)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* using options ‘--no-tests --as-cran’
@@ -43,7 +43,7 @@ The Date field is over a month old.
* checking S3 generic/method consistency ... OK
* checking replacement functions ... OK
* checking foreign function calls ... OK
-* checking R code for possible problems ... OK
+* checking R code for possible problems ... [14s/14s] OK
* checking Rd files ... OK
* checking Rd metadata ... OK
* checking Rd line widths ... OK
@@ -59,7 +59,7 @@ The Date field is over a month old.
* checking data for ASCII and uncompressed saves ... OK
* checking installed files from ‘inst/doc’ ... OK
* checking files in ‘vignettes’ ... OK
-* checking examples ... OK
+* checking examples ... [15s/15s] OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ... SKIPPED
* checking for unstated dependencies in vignettes ... OK
diff --git a/log/test.log b/log/test.log
index bb81dd43..7152c3fe 100644
--- a/log/test.log
+++ b/log/test.log
@@ -5,18 +5,27 @@
✔ | 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.9s]
+✔ | 1 12 | Dimethenamid data from 2018 [31.6s]
────────────────────────────────────────────────────────────────────────────────
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
────────────────────────────────────────────────────────────────────────────────
-✔ | 14 | Error model fitting [4.9s]
+✔ | 14 | Error model fitting [4.8s]
✔ | 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.3s]
✔ | 1 | Fitting the logistic model [0.2s]
-✔ | 7 | Batch fitting and diagnosing hierarchical kinetic models [15.8s]
+✖ | 1 7 | Batch fitting and diagnosing hierarchical kinetic models [14.4s]
+────────────────────────────────────────────────────────────────────────────────
+Failure (test_mhmkin.R:27:3): Multiple hierarchical kinetic models can be fitted and diagnosed
+illparms(hfit_sfo_tc) not equal to character(0).
+Attributes: < Modes: list, NULL >
+Attributes: < Lengths: 1, 0 >
+Attributes: < names for target but not for current >
+Attributes: < current is not list-like >
+target is illparms.saem.mmkin, current is character
+────────────────────────────────────────────────────────────────────────────────
✔ | 1 12 | Nonlinear mixed-effects models [0.3s]
────────────────────────────────────────────────────────────────────────────────
Skip (test_mixed.R:74:3): saemix results are reproducible for biphasic fits
@@ -27,14 +36,38 @@ Reason: Fitting with saemix takes around 10 minutes when using deSolve
✔ | 3 | mkinfit features [0.7s]
✔ | 8 | mkinmod model generation and printing [0.2s]
✔ | 3 | Model predictions with mkinpredict [0.3s]
-✔ | 7 | Multistart method for saem.mmkin models [36.3s]
-✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.4s]
-✔ | 9 | Nonlinear mixed-effects models with nlme [8.9s]
-✔ | 16 | Plotting [9.9s]
+✔ | 7 | Multistart method for saem.mmkin models [35.7s]
+✔ | 16 | Evaluations according to 2015 NAFTA guidance [2.3s]
+✔ | 9 | Nonlinear mixed-effects models with nlme [8.6s]
+✔ | 16 | Plotting [10.1s]
✔ | 4 | Residuals extracted from mkinfit models
-✔ | 1 36 | saemix parent models [72.6s]
+✖ | 3 1 34 | saemix parent models [70.9s]
────────────────────────────────────────────────────────────────────────────────
-Skip (test_saemix_parent.R:152:3): We can also use mkin solution methods for saem
+Failure (test_saemix_parent.R:12:3): Parent fits using saemix are correctly implemented
+illparms(sfo_saem_1) not equal to "sd(parent_0)".
+Attributes: < Modes: list, NULL >
+Attributes: < Lengths: 1, 0 >
+Attributes: < names for target but not for current >
+Attributes: < current is not list-like >
+target is illparms.saem.mmkin, current is character
+
+Failure (test_saemix_parent.R:14:3): Parent fits using saemix are correctly implemented
+illparms(sfo_saem_1_reduced) not equal to character(0).
+Attributes: < Modes: list, NULL >
+Attributes: < Lengths: 1, 0 >
+Attributes: < names for target but not for current >
+Attributes: < current is not list-like >
+target is illparms.saem.mmkin, current is character
+
+Failure (test_saemix_parent.R:25:3): Parent fits using saemix are correctly implemented
+illparms(sfo_saem_1_mkin) not equal to "sd(parent_0)".
+Attributes: < Modes: list, NULL >
+Attributes: < Lengths: 1, 0 >
+Attributes: < names for target but not for current >
+Attributes: < current is not list-like >
+target is illparms.saem.mmkin, current is character
+
+Skip (test_saemix_parent.R:153: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.4s]
@@ -42,16 +75,16 @@ Reason: This still takes almost 2.5 minutes although we do not solve ODEs
✔ | 7 | Fitting the SFORB model [3.7s]
✔ | 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.1s]
-✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2s]
+✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [2.1s]
+✔ | 9 | Hypothesis tests [8.0s]
+✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.3s]
══ Results ═════════════════════════════════════════════════════════════════════
-Duration: 209.2 s
+Duration: 204.9 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 261 ]
+[ FAIL 4 | WARN 0 | SKIP 3 | PASS 259 ]
diff --git a/man/illparms.Rd b/man/illparms.Rd
index 90adf2bb..ebc3185a 100644
--- a/man/illparms.Rd
+++ b/man/illparms.Rd
@@ -41,8 +41,7 @@ tested?}
\value{
For \link{mkinfit} or \link{saem} objects, a character vector of parameter
names. For \link{mmkin} or \link{mhmkin} objects, a matrix like object of class
-'illparms.mmkin' or 'illparms.mhmkin'. The latter objects have a suitable
-printing method.
+'illparms.mmkin' or 'illparms.mhmkin'.
}
\description{
The method for generalised nonlinear regression fits as obtained
@@ -59,6 +58,10 @@ effects expressed as standard deviations include zero, and if
the confidence intervals for the error model parameters include
zero.
}
+\note{
+All objects have printing methods. For the single fits, printing
+does not output anything in the case no ill-defined parameters are found.
+}
\examples{
fit <- mkinfit("FOMC", FOCUS_2006_A, quiet = TRUE)
illparms(fit)
diff --git a/tests/testthat/test_mhmkin.R b/tests/testthat/test_mhmkin.R
index fc588473..72b81fec 100644
--- a/tests/testthat/test_mhmkin.R
+++ b/tests/testthat/test_mhmkin.R
@@ -25,6 +25,7 @@ test_that("Multiple hierarchical kinetic models can be fitted and diagnosed", {
hfit_sfo_tc <- update(hfits[["SFO", "tc"]],
covariance.model = diag(c(0, 1)))
expect_equal(illparms(hfit_sfo_tc), character(0))
+ expect_silent(print(illparms(hfit_sfo_tc)))
test_summary <- summary(hfit_sfo_tc)
test_summary$saemixversion <- "Dummy 0.0 for testing"
@@ -37,7 +38,7 @@ test_that("Multiple hierarchical kinetic models can be fitted and diagnosed", {
expect_known_output(print(test_summary, digits = 1),
"summary_hfit_sfo_tc.txt")
- # It depends on the platform exactly which of the
+ # It depends on the platform exactly which of the
# SFO datasets fail to converge with FOMC
skip_on_travis()
diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R
index 39efa18f..e7574b01 100644
--- a/tests/testthat/test_saemix_parent.R
+++ b/tests/testthat/test_saemix_parent.R
@@ -12,6 +12,7 @@ test_that("Parent fits using saemix are correctly implemented", {
expect_equal(illparms(sfo_saem_1), "sd(parent_0)")
# So we have also done a fit without this variance
expect_equal(illparms(sfo_saem_1_reduced), character(0))
+ expect_silent(print(illparms(sfo_saem_1_reduced)))
# We cannot currently do the fit with completely fixed initial values
mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100))

Contact - Imprint