From 3e601788eb7393d233d19328a11845130b5b29e5 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 17 Apr 2020 11:21:32 +0200 Subject: Fix summarizing old objects --- R/summary.mkinfit.R | 18 ++++++++++++------ test.log | 16 +++++++++------- tests/testthat/FOCUS_2006_D.csf | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/R/summary.mkinfit.R b/R/summary.mkinfit.R index 246bc41d..a67f17ee 100644 --- a/R/summary.mkinfit.R +++ b/R/summary.mkinfit.R @@ -125,9 +125,6 @@ summary.mkinfit <- function(object, data = TRUE, distimes = TRUE, alpha = 0.05, warning = object$warning, use_of_ff = object$mkinmod$use_of_ff, error_model_algorithm = object$error_model_algorithm, - AIC = AIC(object), - BIC = BIC(object), - logLik = logLik(object), df = c(p, rdf), covar = covar, covar_notrans = covar_notrans, @@ -142,6 +139,13 @@ summary.mkinfit <- function(object, data = TRUE, distimes = TRUE, alpha = 0.05, ans$fit_version <- object$version ans$fit_Rversion <- object$Rversion } + + AIC <- try(AIC(object)) + if (!inherits(AIC, "try-error")) { + ans$AIC = AIC(object) + ans$BIC = BIC(object) + ans$logLik = logLik(object) + } ans$diffs <- object$mkinmod$diffs if(data) ans$data <- object$data @@ -220,9 +224,11 @@ print.summary.mkinfit <- function(x, digits = max(3, getOption("digits") - 3), . if(length(x$fixed$value) == 0) cat("None\n") else print(x$fixed) - cat("\nResults:\n\n") - print(data.frame(AIC = x$AIC, BIC = x$BIC, logLik = x$logLik, - row.names = " ")) + if (!is.null(x$AIC)) { + cat("\nResults:\n\n") + print(data.frame(AIC = x$AIC, BIC = x$BIC, logLik = x$logLik, + row.names = " ")) + } cat("\nOptimised, transformed parameters with symmetric confidence intervals:\n") print(signif(x$par, digits = digits)) diff --git a/test.log b/test.log index 128ea38b..dd1a1cc0 100644 --- a/test.log +++ b/test.log @@ -7,29 +7,31 @@ Testing mkin ✔ | 4 | Fitting the SFORB model [1.7 s] ✔ | 5 | Calculation of Akaike weights ✔ | 10 | Confidence intervals and p-values [9.4 s] -✔ | 14 | Error model fitting [38.1 s] +✔ | 14 | Error model fitting [37.9 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.3 s] ✔ | 9 | mkinmod model generation and printing [0.2 s] -✔ | 3 | Model predictions with mkinpredict [0.4 s] +✔ | 3 | Model predictions with mkinpredict [0.3 s] ✔ | 16 | Evaluations according to 2015 NAFTA guidance [4.1 s] -✔ | 8 | Nonlinear mixed-effects models [11.9 s] +✔ | 9 | Nonlinear mixed-effects models [12.0 s] ✔ | 4 | Calculation of maximum time weighted average concentrations (TWAs) [2.2 s] ✔ | 3 | Summary ✔ | 14 | Plotting [4.9 s] ✔ | 4 | AIC calculation ✔ | 4 | 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 +✔ | 2 | Complex test case from Schaefer et al. (2007) Piacenza paper [5.4 s] + ⠏ | 0 | Summaries of old mkinfit objectsError in attr(val, "df") <- length(object$bparms.optim) + length(object$errparms) : + Versuch ein Attribut von NULL zu setzen + ✔ | 1 | Summaries of old mkinfit objects ✔ | 4 | Results for synthetic data established in expertise for UBA (Ranke 2014) [7.1 s] -✔ | 9 | Hypothesis tests [36.9 s] +✔ | 9 | Hypothesis tests [37.0 s] ══ Results ═════════════════════════════════════════════════════════════════════ Duration: 132.2 s -OK: 153 +OK: 154 Failed: 0 Warnings: 0 Skipped: 0 diff --git a/tests/testthat/FOCUS_2006_D.csf b/tests/testthat/FOCUS_2006_D.csf index dfccc13f..c61b55c4 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-16 +Date: 2020-04-17 Optimiser: IRLS [Data] -- cgit v1.2.1