Skip to content

Detect non-finite log_lik (Inf / NaN) and explicitely inform the user #386

Description

@florence-bockting

Summary

If the pointwise log-likelihood matrix contains +Inf or NaN, loo::loo() currently completes without a clear error/warning and can return NA for elpd_loo.

Proposal

Before (or while) computing PSIS-LOO, check the log_lik matrix for non-finite values and message this clearly to the user.

Reproducible example

library(loo)

set.seed(1)
ll <- matrix(rnorm(400 * 20, -1, 0.5), 400, 20)
ll[1:5, 1] <- Inf
loo(ll)$estimates  # elpd_loo is NA; no clear message that log_lik had +Inf
#          Estimate SE
# elpd_loo       NA NA
# p_loo          NA NA
# looic          NA NA

Context

Seen with truncated-normal log_lik from brms, where the truncation normalizer can underflow:
https://discourse.mc-stan.org/t/difficulty-adding-loo-criterion-to-longitudinal-truncated-normal-model/41447/12

Corresponding brms Issue: paul-buerkner/brms#1899

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions