From 5e8190f26611c094a1a5d877a314cbca53e3e530 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 5 Apr 2019 18:55:44 +0200 Subject: Report negative log-likelihood during fits If not quiet = TRUE --- R/mkinfit.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/R/mkinfit.R b/R/mkinfit.R index 796b25c7..73c2f485 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -261,9 +261,6 @@ mkinfit <- function(mkinmod, observed, max(observed$time), length.out = n.outtimes)))) - calls <- 0 # Counter for number of model solutions - out_predicted <- NA - # Define log-likelihood function for optimisation, including (back)transformations nlogLik <- function(P, trans = TRUE) { @@ -330,6 +327,11 @@ mkinfit <- function(mkinmod, observed, nlogLik <- - with(data_log_lik, sum(dnorm(x = value.x, mean = value.y, sd = std, log = TRUE))) + + if (nlogLik < nlogLik.current) { + assign("nlogLik.current", nlogLik, inherits = TRUE) + if (!quiet) cat("Negative log-likelihood at call ", calls, ": ", nlogLik.current, "\n", sep = "") + } return(nlogLik) } @@ -384,6 +386,10 @@ mkinfit <- function(mkinmod, observed, lower["a"] <- 0 } + # Counter for likelihood evaluations + calls = 0 + nlogLik.current <- Inf + # Show parameter names if tracing is requested if(trace_parms) cat(names_optim, "\n") @@ -502,7 +508,7 @@ summary.mkinfit <- function(object, data = TRUE, distimes = TRUE, alpha = 0.05, lci <- param + qt(alpha/2, rdf) * se uci <- param + qt(1-alpha/2, rdf) * se } - + beparms.optim <- c(object$bparms.optim, object$par[epnames]) if (!is.numeric(covar_notrans) | is.na(covar_notrans[1])) { covar_notrans <- NULL -- cgit v1.2.1