From 2bc4adb7080e5893ab423768fe2e24777b292f19 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 4 Jun 2019 19:46:55 +0200 Subject: For the d_3 algorithm, report which was better, if any --- R/mkinfit.R | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/R/mkinfit.R b/R/mkinfit.R index 33e13d8e..13c7aa90 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -505,8 +505,19 @@ mkinfit <- function(mkinmod, observed, upper = upper[names(parms.start)], control = control, ...) fit$logLik <- - nlogLik.current - if (error_model_algorithm == "d_3" && fit_direct$logLik > fit$logLik) { - fit <- fit_direct + if (error_model_algorithm == "d_3") { + if (abs((fit_direct$logLik - fit$logLik))/mean(c(fit_direct$logLik, fit$logLik)) < 0.001) { + if (!quiet) { + message("Direct fitting and three-step fitting yield approximately the same likelihood") + } + } else { + if (fit_direct$logLik < fit$logLik) { + if (!quiet) message("Three-step fitting yielded a higher likelihood than direct fitting") + } else { + if (!quiet) message("Direct fitting yielded a higher likelihood than three-step fitting") + fit <- fit_direct + } + } } } if (err_mod != "const" & error_model_algorithm == "IRLS") { -- cgit v1.2.1