Repository navigation
Review #363 (2/19): fix model_compare() estimates by name, default names, measure check - #424
florence-bockting wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## pred_measure #424 +/- ##
================================================
- Coverage 92.03% 91.88% -0.16%
================================================
Files 38 38
Lines 5201 4745 -456
================================================
- Hits 4787 4360 -427
+ Misses 414 385 -29 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
This is how benchmark results would change (along with a 95% confidence interval in relative change) if e48d2d6 is merged into pred_measure:
Further explanation regarding interpretation and methodology can be found in the documentation. |
jgabry
left a comment
There was a problem hiding this comment.
Looks good. A few small suggestions in comments.
One small thing in the PR description: it says this also fixes model_compare_order(), but after the second commit the name matching only applies when bare_names = TRUE. model_compare_order() calls the helper function with bare_names = FALSE or it already looks up rank_col by name, so I don't think it's affected (and it also didn't have the bug).
Thanks for spotting this, I updated the PR description. |
PR 2/19 for the review of #363. This PR does not touch the files of PR 1/19: #423.
1. Estimate columns filled by position
Review comments: r4544927101, r4553271356
Implementation:
.model_compare_estimates_table()(R/model_compare.R) subsets each model'sestimatesby name to the measures that all models share. The row order follows the first model. This applies only withbare_names = TRUE, which is thepred_measurepath. Classic loo/waic/kfold objects keep the match by position, so their output does not change.Tests: The test from the review checks that mse and mae are not in the output. The old code gave m1 a mae column with m1's mse value. A new test uses a different measure order and a different number of measures. It checks the m1 row, which the old code filled wrong. The second case gives the omitted-measures warning and no longer crashes.
2. Default model names assigned after sorting
Review comment: r4544947628
Implementation:
compare_pred_measure()setsnames(loos) <- find_model_names(loos)before the sort, as the classic path does.Test: unnamed inputs where the second model is best give
c("model2", "model1"), asloo_compare()does.3.
identical()onse_diff_funclosuresReview comment: r4544950797
Decision:
ignore.environment = TRUE. It stays an error, not a warning, because a real difference (for example inloss) still means the models disagree. Limit: two closures with the same code but different captured values look equal.Test: the same custom measure made in a helper function, and after
saveRDS()/readRDS(), compares without an error. A differentlossstill errors.4.
grep("elpd")matches custom measuresReview comment: r4545391902
Implementation:
.is_elpd_measure()matcheselpd,elpd_loo,elpd_kfoldandelpd_testexactly.Test: a custom measure named
elpd_customgets its_diffand_se_diffcolumns. With the old function, both columns were missing.5. Tolerance scaled twice
Review comment: r4545429584
Implementation:
.check_declared_aggregation()uses a relative tolerance,sqrt(.Machine$double.eps), scaled by the larger of the two values.all.equal()used an absolute difference for values below 1.5e-8.Test: a measure declared
"mean"whose estimate is 1.5 times the mean, with values around 3e11, now gives the warning. The old tolerance was about 4300, so it missed this. Values scaled by 1e-8 with a correct declaration give no warning. The old tolerance warned there. A wrong declaration with values scaled by 1e-8 now gives the warning.6. Fallback returns
NULLagainReview comment: r4545434713
Implementation: the fallback in
.measure_se_diff_fun()is removed..measure_info()already copiesse_diff_funfrom.measure_spec.7.
compare_referencenot set for subsamplingReview comments: r4544874307, r4545558077, r4544910468
Implementation:
model_compare.psis_loo_ss_list()setscompare_referenceas the classic path does. The fallback in.measure_ref_model()and its doc sentence are removed.Test: in
test_loo_subsampling.R, a subsampling comparison hascompare_reference.Test runs
test_compare.R,test_print.Randtest_loo_subsampling.Rpass. The 3 warnings intest_compare.Rthat are not caught were there before and will be addressed by a later PR.This PR was assisted by use of LLM.