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
Summary
If the pointwise log-likelihood matrix contains
+InforNaN,loo::loo()currently completes without a clear error/warning and can returnNAforelpd_loo.Proposal
Before (or while) computing PSIS-LOO, check the
log_likmatrix for non-finite values and message this clearly to the user.Reproducible example
Context
Seen with truncated-normal
log_likfrom 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