Skip to content

769: Make test arguments of get_pairwise_comparisons() explicit - #1249

Draft
nikosbosse wants to merge 4 commits into
mainfrom
issue-769-pairwise-explicit-args
Draft

nikosbosse wants to merge 4 commits into
mainfrom
issue-769-pairwise-explicit-args

Conversation

@nikosbosse

@nikosbosse nikosbosse commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

CLAUDE:

Description

Part of #769. This PR makes the test arguments explicit and documents what the one-sided test checks. It does not change the test itself; the open question in #769 about the null hypothesis of the one-sided test remains (see "Not addressed" below).

get_pairwise_comparisons() used to pass test_type, one_sided and n_permutations on via ... to the internal pairwise test. Following the discussion in #769, these are now explicit arguments:

  • get_pairwise_comparisons() gains test_type = c("non_parametric", "permutation"), one_sided = FALSE and n_permutations = 999 in place of .... They are validated up front: match.arg() for test_type (skipped when NULL), assert_flag() for one_sided and assert_count(positive = TRUE) for n_permutations. Previously, an invalid one_sided/n_permutations was silently ignored unless a permutation test ran, and a misspelled argument disappeared into .... It now errors with "unused argument".
  • The internal pairwise_comparison_one_group() also takes these as explicit arguments and passes them to compare_scores() by name, so ... no longer appears anywhere on this path.
  • add_relative_skill() keeps its test_type = NULL default from add_relative_skill() runs Wilcoxon tests whose p-values it then discards #1222 and still forwards ... to get_pairwise_comparisons(). Its ... doc now says these arguments (one_sided, n_permutations) only affect p-values, which add_relative_skill() does not return.
  • The parameter docs move from compare_forecasts() onto get_pairwise_comparisons(), and the other functions inherit them. This also fixes the "whether two conduct" typo. The one_sided doc now says three things. It only affects the permutation test, because the Wilcoxon test is always two-sided. Its alternative is that the comparator appearing first in scores has the higher (worse) mean score. Each pair is tested once, and that p-value is shown in both output rows of the pair.
  • The no-op NULL is removed from the test_type default vectors of compare_scores() and compare_forecasts().
  • NAMESPACE: assert_count and assert_flag are added to the grouped importFrom(checkmate, ...) block. I checked this against roxygen2 8.1.0, the version in Config/roxygen2/version. It regenerates NAMESPACE and DESCRIPTION exactly as committed.
  • NEWS item added. It is marked as a breaking change, because calls that passed these arguments positionally after baseline now bind them differently. Calls that passed them by name are unaffected.

Not addressed (left for #769 / a follow-up)

  • one_sided still has no effect on the default Wilcoxon test.
  • Each pair's p-value is reused for the mirrored comparison. A one-sided p-value is therefore only meaningful in one direction, and that direction depends on the row order of scores.

Both points are about which hypothesis to test, which #769 raises as an open question. Changing them changes the p-values users get, so I left that decision to the maintainers instead of folding it into this refactor.

Tests

  • get_pairwise_comparisons() validates the test arguments (#769): I ran this test against origin/main's R/pairwise-comparisons.R. Only the one_sided = "yes", n_permutations = 0 and add_relative_skill(n_permutations = 2.5) expectations fail there, and all three pass after the change. The test_type = "t_test" and alternative = "less" → "unused argument" expectations already pass before the change, so they only guard existing behaviour. The test_type expectation matches "non_parametric" rather than base R's translated "should be one of" message.
  • permutation_tests work as expected (existing test, extended): this test guards the forwarding of all three arguments and passes both before and after the change. n_permutations is checked through p-values that are multiples of 1/51. test_type is checked through permutation p-values that differ from the Wilcoxon ones, and NULL gives NA. one_sided is checked with a deterministic two-model case: one model is better on every forecast, so the two-sided p is 1/51 and the one-sided p is 1. I ran a mutation check: replacing one_sided = one_sided with FALSE at each of the three forwarding sites (get_pairwise_comparisons → pairwise_comparison_one_group → compare_scores → permutation_test) makes this test fail.

Checklist

  • My PR is based on a package issue and I have explicitly linked it (Part of Rethink the way arguments are passed in get_pairwise_comparisons() #769).
  • I have included the target issue or issues in the PR title as follows: issue-number: PR title
  • I have tested my changes locally. The full suite passes with devtools::test(): FAIL 0, PASS 1050. The 4 warnings come from unrelated pre-existing tests.
  • I have added or updated unit tests where necessary. The validation tests are verified to fail before and pass after the change. The forwarding expectations are guards that I verified with mutation checks, as described above.
  • I have updated the documentation if required.
  • I have built the package locally and run rebuilt docs using roxygen2 (8.1.0, matching Config/roxygen2/version). This produced no churn outside this change.
  • My code follows the established coding standards and I have run lintr::lint_package() to check for style issues introduced by my changes. I ran lintr::lint() on the changed files. The only lints are the spurious object_usage_linter ones that also hit pre-existing code.
  • I have added a news item linked to this PR.
  • I have reviewed CI checks for this PR and addressed them as far as I am able. CI pending.

Implementation: two independent drafts were compared by a judge agent; draft A was chosen as base.

Review

An independent adversarial agent reviewed this PR. Changes made in response:

  • one_sided forwarding was untested (major): I added a deterministic check (described above) and confirmed with mutation checks at all three forwarding sites that it catches a dropped one_sided. The PR description no longer claims more than the tests pin down.
  • Test overlap: I merged the separate "passes the test arguments on" test into the existing permutation_tests work as expected test.
  • One-sided semantics / "closes Rethink the way arguments are passed in get_pairwise_comparisons() #769": the one_sided doc now states which direction is tested, that it does not affect the Wilcoxon test, and that the p-value is shared by both rows of a pair. The PR now says "Part of Rethink the way arguments are passed in get_pairwise_comparisons() #769" instead of closing it.
  • NEWS: the item is now marked as breaking and mentions positional calls.
  • ... in add_relative_skill(): the doc now says these arguments cannot change its output.
  • Locale-dependent error match: the test now matches "non_parametric".
  • No-op NULL in the default vectors: removed from compare_scores() and compare_forecasts().
  • NAMESPACE hand edit: verified against roxygen2 8.1.0, the version the repo records. The suggested 7.3.3 is not the repo's version and generates an ungrouped NAMESPACE. 8.1.0 reproduces the committed file exactly.

Rebutted:

  • Make the Wilcoxon test one-sided too (alternative = ...): the mirrored-row issue above means a one-sided p-value is only valid for one row of each pair. Extending one_sided to the default test would spread that problem to every default call, and it would silently change p-values. That belongs to the null-hypothesis discussion in Rethink the way arguments are passed in get_pairwise_comparisons() #769, not to this refactor. Also, the suggested "less" would be the opposite direction to the permutation test, which tests that the first comparator is worse, i.e. "greater".
  • Drop the defaults in pairwise_comparison_one_group(): I tried this. Existing tests call the internal function directly without the test arguments, and they then fail with argument "test_type" is missing. Keeping the defaults, which match compare_scores(), is simpler than making every direct caller spell out three arguments it does not care about.

🤖 Generated with Claude Code

nikosbosse and others added 3 commits November 8, 2026 13:09
Replace `...` in get_pairwise_comparisons() and
pairwise_comparison_one_group() with explicit `test_type`, `one_sided`
and `n_permutations` arguments, validate them up front, and document
them on get_pairwise_comparisons(). add_relative_skill() keeps its
`test_type = NULL` default and forwards `...` to
get_pairwise_comparisons().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reword the one_sided parameter doc, drop the signature-only test that
inspected formals(), and explain in the validation test why these
arguments are now checked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.18%. Comparing base (8b18f07) to head (c1ff0e0).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1249   +/-   ##
=======================================
  Coverage   99.18%   99.18%           
=======================================
  Files          41       41           
  Lines        2333     2344   +11     
=======================================
+ Hits         2314     2325   +11     
  Misses         19       19           

☔ 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.

- Merge the forwarding checks into the existing permutation test and add
  a deterministic check that `one_sided` reaches permutation_test().
- Document that `one_sided` only affects the permutation test, which
  direction it tests, and that the p-value is shared by both rows of a pair.
- Clarify that `...` in add_relative_skill() cannot change its output.
- Drop the no-op NULL from the test_type defaults of compare_scores() and
  compare_forecasts().
- Make the test_type error expectation locale-independent.
- Flag the NEWS item as breaking for positional calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

Rethink the way arguments are passed in get_pairwise_comparisons()

1 participant