Skip to content

Fix the error of cv_varsel() with LOO and the latent projection for an NA Pareto k of loo::E_loo() - #667

Merged
avehtari merged 9 commits into
masterfrom
latent-pareto-k-psis
Nov 20, 2026
Merged

avehtari merged 9 commits into
masterfrom
latent-pareto-k-psis

Conversation

@avehtari

Copy link
Copy Markdown
Member

Summary

cv_varsel() with cv_method = "LOO" and the latent projection stops with "missing value where TRUE/FALSE needed" if loo::E_loo() gives an NA Pareto k. This happens if most of the PSIS-LOO ratios of an observation underflow to 0, for example with a non-converged reference model. For such an observation, loo::psis() gives a Pareto k of Inf.

Change

cv_varsel() has the Pareto k of the ratios from its own loo::psis() call. With this PR, the warning about the latent response values counts each observation with the larger of this k and the loo::E_loo() k. If the loo::E_loo() k is NA, it counts with the loo::psis() k. This is the rule of stan-dev/loo#421, where loo::E_loo() takes the k of the ratios from the psis() object. With the loo version of stan-dev/loo#421, this rule does not change the count. projpred needs the rule for loo 2.10.1.

Other changes

  • warn_pareto() now gets the k values and the number of draws. It computes the threshold and the number of k values above it.
  • .ps_khat_threshold() now uses posterior::ps_khat_threshold(), capped at 0.7 as in loo.
  • The Pareto k warning of the submodel evaluation counted with the threshold for the reference-model draws, but printed the threshold for the projected draws. Now it counts with the threshold for the projected draws, as the loo::psis() warning that projpred replaces does. So this warning can occur more often, for example with a small nclusters_pred.

Tests

New tests in test_pareto_k.R cover the threshold, warn_pareto() and two cv_varsel() cases:

  • a latent Poisson reference model with fixed draws whose ratios underflow for one observation;
  • the submodel warning with 4000 reference-model draws and nclusters_pred = 30.

With the R/cv_varsel.R of master, the latent test gives the error above, and the submodel warning counts 1 of 30 k values instead of 5.

The full suite passes with NOT_CRAN=true, R 4.6.1, loo 2.10.1.9000 and posterior 1.7.1 (62,669 expectations, 0 failures). This run was before the merge of the master commit of #662. After that merge, test_pareto_k.R, test_latent.R, test_search_latent.R, test_search_screen.R, test_augdat_ll.R and test_loo_weight_perturbation.R pass. test_pareto_k.R also passes with the loo branch of stan-dev/loo#421 and posterior 1.8.0.

This PR was assisted by Claude.

@avehtari
avehtari merged commit 3700c5f into master Nov 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant