Skip to content

Review #363 (1/19): fix E|X - X'| rounding, acc/bacc y length, RMSE SE diff - #423

Merged
jgabry merged 3 commits into
pred_measurefrom
fix/measure-bugs
Nov 24, 2026
Merged

jgabry merged 3 commits into
pred_measurefrom
fix/measure-bugs

Conversation

@florence-bockting

Copy link
Copy Markdown
Contributor

PR 1/19 for the review of #363.

1. E|X - X'| is not exactly 0 for constant draws

Review comments: r4544689103, r4544848787

Decision: Use the gap form, as suggested by the reviewer

Implementation:

  • .exx_pwm() (R/pred_measure-helpers.R): both paths sum diff(sorted draws) times non-negative coefficients, so constant draws give exactly 0 and the estimate cannot be negative.
    • Unweighted: coefficient 2 * k * (S - k) / (S * (S - 1)). The reported example (all draws 1, y = 0) takes this path.
    • Weighted: 1 - C is computed as a sum from the right (rev(cumsum(rev(w)))). This is the same in math. With 1 - C, rounding can give about -1e-17 at the last gap.
  • measure_rps() (R/pred_measure-builtin.R): the EXX == 0 check now works. The error names both causes of a point mass ("all draws equal, or all weight on one draw"). It mentions the PSIS diagnostics only when weights are given.
  • The long derivation in the helper doc is removed, and so is the link to notes/. The formula stays in the measure_rps() doc. Its "always non-negative" claim is now also true in floating point.

Check against the old code: unweighted, the max difference is 0; weighted, 1,000 random cases, the max difference is 4.4e-16.

2. acc / bacc do not check length(y)

Review comments: r4544794559, r4544798855

Implementation: .acc_pointwise() (used by both measures) checks ncol(mupred) == length(y), as .point_error_from_inputs() does.

3. RMSE SE of a difference is 0 if one MSE is 0

Review comment: r4544853232

Implementation: .se_diff_rmse(): a model with MSE 0 has a constant RMSE of 0, so its term drops out. The result is the SE of the other model's RMSE, the same value that measure_rmse() reports for it. It returns 0 only when both MSE are 0.

Tests

In tests/testthat/test_pred_measure_builtin.R, with small test data:

  • Constant draws: rps gives exactly |3 - y|, with and without weights. srps errors, and the PSIS hint appears only with weights.
  • acc and bacc error when y is too short.
  • .se_diff_rmse() with one perfect model equals the RMSE SE of the other model. With two perfect models, it is 0.

test_pred_measure_builtin.R, test_pred_measure.R, test_pred_measure_helpers.R, test_print.R, test_crps.R and test_compare.R pass. The warnings that are not caught were there before and will be addressed by a later PR.

@florence-bockting
florence-bockting marked this pull request as ready for review November 23, 2026 08:36
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.85%. Comparing base (eaebc86) to head (8c586dd).

Files with missing lines Patch % Lines
R/pred_measure-builtin.R 90.90% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff                @@
##           pred_measure     #423      +/-   ##
================================================
- Coverage         92.03%   91.85%   -0.19%     
================================================
  Files                38       38              
  Lines              5201     4752     -449     
================================================
- Hits               4787     4365     -422     
+ Misses              414      387      -27     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

This is how benchmark results would change (along with a 95% confidence interval in relative change) if 8c586dd is merged into pred_measure:

Status Name Current Incoming Interval
✔️ loo_matrix 1.5s 1.5s [-0.41%, +1.26%]
✔️ loo_function 1.55s 1.55s [-0.77%, +0.44%]

Further explanation regarding interpretation and methodology can be found in the documentation.

@jgabry jgabry left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good just a couple of small suggestions

Comment thread R/pred_measure-helpers.R Resolved
@jgabry
jgabry merged commit 99b8a75 into pred_measure Nov 24, 2026
10 checks passed
@jgabry
jgabry deleted the fix/measure-bugs branch November 24, 2026 18:25
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.

3 participants