Repository navigation
Review #363 (4/19): Soft-deprecate old functions with lifecycle - #428
Merged
Merged
Conversation
Call lifecycle::deprecate_soft() before UseMethod() in loo_compare(), crps(), scrps(), loo_crps(), loo_scrps(), elpd(), and loo_predictive_metric(). Remove .deprecate_once(). Add tests that compare the old and new functions.
jgabry
requested changes
Nov 24, 2026
jgabry
left a comment
Member
There was a problem hiding this comment.
One important thing and then two small things:
- I think by warning in the generic
loo_comparefunction rstanarm and brms users will still see the warning (see my comment inline) - The new tests showing that
crps()andmeasure_rps()have opposite signs reminds me that we should mention that in the CRPS section ofvignettes/migration-guide.Rmd. Right now it only says the results aren't identical and a sign change is easy to miss. - Two tests still let a deprecation warning through: "elpd handles negative infinite log likelihoods" in
tests/testthat/test_loo_and_waic.R(line 71) and "methods for single data point pass permutations to matrix methods" intests/testthat/test_crps.R(lines 214-218).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## pred_measure #428 +/- ##
================================================
+ Coverage 91.89% 91.94% +0.05%
================================================
Files 38 38
Lines 4751 4744 -7
================================================
- Hits 4366 4362 -4
+ Misses 385 382 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if ee2433a is merged into pred_measure:
Further explanation regarding interpretation and methodology can be found in the documentation. |
jgabry
approved these changes
Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 4/19 for the review of #363.
1. Soft deprecation until brms and rstanarm are updated
Review comments: r4552563077, main review
Decision:
lifecycle::deprecate_soft()now. We change tolifecycle::deprecate_warn()after brms and rstanarm have a release that callsmodel_compare(). The same plan applies to all 7 deprecated functions (section 2).Implementation:
lifecycleis added toImportsinDESCRIPTION. A user sees the warning only when they call the function directly. A call from brms or rstanarm gives no warning.NEWS.mdnow says "Soft-deprecate".2. One deprecation mechanism
Review comments: r4552580093, r4552601476, r4552665625, r4552666608, r4552667491, r4552673867, r4552675331, r4552704181, main review
Decision:
lifecycle::deprecate_soft("3.0.0", ...)for all of them, in the generic beforeUseMethod(). The exception isloo_compare(): there the call is in the loo methods (r4685306347).Implementation:
crps(),scrps(),loo_crps(),loo_scrps(),elpd()andloo_predictive_metric().loo_compare(), the call is inloo_compare.default()andloo_compare.psis_loo_ss_list(). brms and rstanarm re-export theloo_compare()generic and register their own methods. A user who callsloo_compare(fit1, fit2)on their fits gets no warning, becausemodel_compare()has no methods for these fits yet..Deprecated(), 2.deprecate_once()) are removed..deprecate_once()is removed fromR/helpers.R.compare(),psislw()andpsis_approximate_posterior()keep.Deprecated(). They are deprecated since earlier releases.The call is in the generic and not in the methods because
crps.numeric()callscrps.matrix(). Adeprecate_soft()call incrps.matrix()sees loo as the caller and does not warn. The same applies toscrps().Tests:
test_deprecated_measures.Ruseslifecycle::expect_deprecated()for all 7 functions.test_compare.R: the "once per session" test is replaced by alifecycle::expect_deprecated()test.test_compare.R: "loo_compare is still a generic" now checks that aloo_comparemethod from another package dispatches without a deprecation warning. It fails on the first commit of this PR (deprecation in the generic).elpd()vector-input test and "elpd handles negative infinite log likelihoods" intest_loo_and_waic.R, "methods for single data point pass permutations to matrix methods" intest_crps.R, and the twoloo_compare()calls outsidetest_that()intest_loo_subsampling.R.3. Old and new functions give the same answer
Review comment: main review
Implementation: new tests in
test_deprecated_measures.Ruse simulated data with 4000 draws, 20 observations and Pareto k below 0.7.elpd()measure_elpd()loo_predictive_metric()withmae,rmse,mse,accmeasure_mae(),measure_rmse(),measure_mse(),measure_acc()with the PSIS log weightsloo_predictive_metric()withbalanced_accmeasure_bacc()crps(),scrps()measure_rps(),measure_srps()loo_crps(),loo_scrps()loo_pred_measure(measures = c("rps", "srps"))loo_compare()model_compare()test_compare.R("loo_compare still returns what model_compare returns")Where the results differ:
crps()estimate has the opposite sign ofrps.crps()is a utility andrpsis a loss.scrps()andsrpshave the same sign. The CRPS section ofvignettes/migration-guide.Rmdnow states this sign change.crps()uses one random pairing ofxandx2.measure_rps()uses all pairs of draws inypred.baccSE differs.measure_bacc()uses the SE per class, sqrt(sum_c p_c (1 − p_c) / n_c) / K. The old.balanced_accuracy()divides by the totaln, and its code comment says that this approximation is biased.Test runs
test_deprecated_measures.R,test_compare.R,test_loo_and_waic.R,test_crps.R,test_loo_predictive_metric.R,test_model_weighting.R,test_loo_subsampling.R,test_pred_measure.R,test_pred_measure_helpers.Randtest_pred_measure_builtin.Rpass. On the base branch, the 5 deprecation tests fail, and the equivalence tests pass.The 68 warnings in
test_deprecated_measures.Rwere there before this PR. They are PSIS warnings from the smallloo_crps()input in the "loo_crps() is deprecated" test.I used LLM to assist me in this PR.