aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2018-02-02 12:38:55 +0100
committerJohannes Ranke <jranke@uni-bremen.de>2018-02-02 12:38:55 +0100
commita8ab5f5f1139d97f8636c22cb39e4a31b71bc889 (patch)
tree52abe3ef6db4c5bd1975e3cff6e3a92136260237
parent4de47be0bc4e6b923a6db15b9abc461046a99eac (diff)
mkinfit: Work around a bug in the current FME version
that prevented the convergence message to be returned in the case of non-convergence.
-rw-r--r--NEWS.md2
-rw-r--r--R/mkinfit.R21
-rw-r--r--docs/news/index.html1
3 files changed, 18 insertions, 6 deletions
diff --git a/NEWS.md b/NEWS.md
index 87bad442..a0241743 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -4,6 +4,8 @@
- 'mkinfit': Added the iterative reweighting method 'tc' using the two-component error model from Rocke and Lorenzato. NA values in the data are not returned any more.
+- 'mkinfit': Work around a bug in the current FME version that prevented the convergence message to be returned in the case of non-convergence.
+
- 'summary.mkinfit': Improved output regarding weighting method. No predictions are returned for NA values in the model (see above).
- 'summary.mkinfit': Show versions of mkin and R used for fitting (not the ones used for the summary) if the fit was generated with mkin >= 0.9.47.1
diff --git a/R/mkinfit.R b/R/mkinfit.R
index ab7b5ad2..c471b01c 100644
--- a/R/mkinfit.R
+++ b/R/mkinfit.R
@@ -36,7 +36,7 @@ mkinfit <- function(mkinmod, observed,
transform_rates = TRUE,
transform_fractions = TRUE,
plot = FALSE, quiet = FALSE,
- err = NULL,
+ err = NULL,
weight = c("none", "std", "mean", "tc"),
tc = c(sigma_low = 0.5, rsd_high = 0.07),
scaleVar = FALSE,
@@ -439,7 +439,7 @@ mkinfit <- function(mkinmod, observed,
if (reweight.method == "tc") {
sr_old <- tc_fitted
observed[err] <- predict(tc_fit)
-
+
}
fit <- modFit(cost, fit$par, method = method.modFit,
control = control.modFit, lower = lower, upper = upper, ...)
@@ -483,13 +483,22 @@ mkinfit <- function(mkinmod, observed,
if(!quiet) cat("Optimisation by method", method.modFit, "successfully terminated.\n")
}
}
- if (method.modFit %in% c("Port", "SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B")) {
+ if (method.modFit == "Port") {
+ if (fit$convergence != 0) {
+ fit$warning = paste0("Optimisation by method ", method.modFit,
+ " did not converge:\n",
+ if(is.character(fit$counts)) fit$counts # FME bug
+ else fit$message)
+ warning(fit$warning)
+ } else {
+ if(!quiet) cat("Optimisation by method", method.modFit, "successfully terminated.\n")
+ }
+ }
+ if (method.modFit %in% c("SANN", "Nelder-Mead", "BFGS", "CG", "L-BFGS-B")) {
if (fit$convergence != 0) {
fit$warning = paste0("Optimisation by method ", method.modFit,
" did not converge.\n",
- "Convergence code is ", fit$convergence,
- ifelse(is.null(fit$message), "",
- paste0("\nMessage is ", fit$message)))
+ "Convergence code returned by optim() is", fit$convergence)
warning(fit$warning)
} else {
if(!quiet) cat("Optimisation by method", method.modFit, "successfully terminated.\n")
diff --git a/docs/news/index.html b/docs/news/index.html
index 0e7ceabf..41920ac2 100644
--- a/docs/news/index.html
+++ b/docs/news/index.html
@@ -109,6 +109,7 @@
<ul>
<li><p>‘test_data_from_UBA_2014’: Added this list of datasets containing experimental data used in the expertise from 2014</p></li>
<li><p>‘mkinfit’: Added the iterative reweighting method ‘tc’ using the two-component error model from Rocke and Lorenzato. NA values in the data are not returned any more.</p></li>
+<li><p>‘mkinfit’: Work around a bug in the current FME version that prevented the convergence message to be returned in the case of non-convergence.</p></li>
<li><p>‘summary.mkinfit’: Improved output regarding weighting method. No predictions are returned for NA values in the model (see above).</p></li>
<li><p>‘summary.mkinfit’: Show versions of mkin and R used for fitting (not the ones used for the summary) if the fit was generated with mkin &gt;= 0.9.47.1</p></li>
</ul>

Contact - Imprint