From c8a808979e6d8d1b69522ea9e570817a0cb76622 Mon Sep 17 00:00:00 2001 From: Admin_mschuemi Date: Thu, 9 Nov 2023 02:22:28 -0500 Subject: [PATCH] Handling edge case when likelihood is infinite during profiling. Prevents 'missing value where TRUE/FALSE needed' error --- R/ModelFit.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/ModelFit.R b/R/ModelFit.R index 3919efeb..9c98ab40 100644 --- a/R/ModelFit.R +++ b/R/ModelFit.R @@ -937,21 +937,22 @@ getCyclopsProfileLogLikelihood <- function(object, while (length(grid) != 0) { ll <- fixedGridProfileLogLikelihood(object, parm, grid, includePenalty) profile <- bind_rows(profile, ll) %>% arrange(.data$point) - - if (any(is.nan(profile$value))) { - if (all(is.nan(profile$value))) { + invalid <- is.nan(profile$value) | is.infinite(profile$value) + if (any(invalid)) { + if (all(invalid)) { warning("Failing to compute likelihood at entire initial grid.") return(NULL) } - start <- min(which(!is.nan(profile$value))) - end <- max(which(!is.nan(profile$value))) + start <- min(which(!invalid)) + end <- max(which(!invalid)) if (start == end) { warning("Failing to compute likelihood at entire grid except one. Giving up") return(NULL) } profile <- profile[start:end, ] - if (any(is.nan(profile$value))) { + invalid <- invalid[start:end] + if (any(invalid)) { warning("Failing to compute likelihood in non-extreme regions. Giving up.") return(NULL) }