Skip to content

Commit

Permalink
Handling edge case when likelihood is infinite during profiling. Prev…
Browse files Browse the repository at this point in the history
…ents 'missing value where TRUE/FALSE needed' error
  • Loading branch information
Admin_mschuemi authored and Admin_mschuemi committed Nov 9, 2023
1 parent a2b3a95 commit c8a8089
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions R/ModelFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c8a8089

Please sign in to comment.