stan-dev / projpred

Projection predictive variable selection
https://mc-stan.org/projpred/
Other
110 stars 26 forks source link

Improve Pareto k-value warnings, use `loo::sis()` for weighted draws #438

Closed fweber144 closed 1 year ago

fweber144 commented 1 year ago

This PR improves the Pareto k-value warnings by suppressing the original warnings from the loo package and throwing customized warnings instead (thank you, @n-kall, for the suggestion).

While implementing this, I realized that if the projected draws used for the performance evaluation in the validate_search = FALSE case have different weights, then loo::sis() needs to be used instead of loo::psis() (because the weights would need to be taken into account when performing the Pareto smoothing). Hence, this fallback to loo::sis() is implemented here as well (and apart from that, we now use loo::sis() explicitly if loo::psis() would not perform the Pareto smoothing due to a small number of draws, but this is merely a safety measure, see the inline comments added in the code).

In order to differentiate between different warnings in the unit tests, other warnings are now thrown conditionally on their own "hidden" global options.

Some enhancements for capture.output() usage in fit_cumul() and fit_cumul_mlvl() are included as well (found when starting to use capture.output() in loo_varsel()).

Also added is a unit test that the warning for full Gaussian multilevel models added in #426 is thrown correctly (this test required the differentiation between different warnings, so it is included here).