From 3529f5ff498d7d054c7b1911ddfc4b242902b85d Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Wed, 28 Sep 2022 16:34:57 +0200 Subject: Fix handling of multistart fits with failures --- R/llhist.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'R/llhist.R') diff --git a/R/llhist.R b/R/llhist.R index b7f6de21..9ddf5b10 100644 --- a/R/llhist.R +++ b/R/llhist.R @@ -16,7 +16,16 @@ llhist <- function(object, breaks = "Sturges", lpos = "topleft", main = "", ...) oldpar <- par(no.readonly = TRUE) on.exit(par(oldpar, no.readonly = TRUE)) - ll <- sapply(object, logLik) + if (inherits(object, "multistart.saem.mmkin")) { + llfunc <- function(object) { + if (inherits(object$so, "try-error")) return(NA) + else return(logLik(object$so)) + } + } else { + stop("llhist is only implemented for multistart.saem.mmkin objects") + } + + ll <- stats::na.omit(sapply(object, llfunc)) kde <- KernSmooth::bkde(ll) par(las = 1) -- cgit v1.2.1