From 307a317666b8a1cdfe2293371ad8671403680a36 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 4 Jun 2019 21:10:58 +0200 Subject: Fix a bug introduced in the last commit --- R/mkinfit.R | 6 ++++-- tests/testthat/test_error_models.R | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/mkinfit.R b/R/mkinfit.R index 13c7aa90..60697cb1 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -505,13 +505,15 @@ mkinfit <- function(mkinmod, observed, upper = upper[names(parms.start)], control = control, ...) fit$logLik <- - nlogLik.current + if (error_model_algorithm == "d_3") { - if (abs((fit_direct$logLik - fit$logLik))/mean(c(fit_direct$logLik, fit$logLik)) < 0.001) { + rel_diff <- abs((fit_direct$logLik - fit$logLik))/-mean(c(fit_direct$logLik, fit$logLik)) + if (rel_diff < 0.0001) { if (!quiet) { message("Direct fitting and three-step fitting yield approximately the same likelihood") } } else { - if (fit_direct$logLik < fit$logLik) { + if (fit$logLik > fit_direct$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") diff --git a/tests/testthat/test_error_models.R b/tests/testthat/test_error_models.R index 6bb93d48..404f02ab 100644 --- a/tests/testthat/test_error_models.R +++ b/tests/testthat/test_error_models.R @@ -181,7 +181,7 @@ test_that("Reweighting method 'tc' produces reasonable variance estimates", { test_that("The different error model fitting methods work for parent fits", { skip_on_cran() - f_9_OLS <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, + f_9_OLS <- mkinfit("SFO", experimental_data_for_UBA_2019[[9]]$data, quiet = TRUE) expect_equivalent(round(AIC(f_9_OLS), 2), 137.43) -- cgit v1.2.3