Skip to content

Preserve small Kendall asymptotic p-values - #3675

Open
WeiLiuu wants to merge 3 commits into
Lightning-AI:masterfrom
WeiLiuu:fix/kendall-asymptotic-tail
Open

WeiLiuu wants to merge 3 commits into
Lightning-AI:masterfrom
WeiLiuu:fix/kendall-asymptotic-tail

Conversation

@WeiLiuu

@WeiLiuu WeiLiuu commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

The asymptotic Kendall test returns a zero p-value for 30 strictly ordered float32 observations. The normal CDF rounds away the lower tail. Evaluate that tail with the complementary error function so the two-sided result is approximately 8.4363e-15, consistent with SciPy.

The regression covers increasing and decreasing inputs and all three alternatives. It uses a relative tolerance with zero absolute tolerance so a result of zero fails.

Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

Evaluate the normal tail with erfc to avoid cancellation for strongly ordered samples.
@codecov-commenter

codecov-commenter commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 35%. Comparing base (d184220) to head (1859439).
⚠️ Report is 70 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #3675    +/-   ##
=======================================
- Coverage      37%     35%    -1%     
=======================================
  Files         349     357     +8     
  Lines       19901   20284   +383     
=======================================
- Hits         7264    7189    -75     
- Misses      12637   13095   +458     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@atishay-kasliwal atishay-kasliwal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compared kendall_rank_corrcoef(..., t_test=True) p-values with scipy.stats.kendalltau(method='asymptotic') on float64 inputs. Here they match scipy down to 1e-26 (n=40: 1.83e-09, n=60: 5.88e-15, n=100: 5.16e-26); master returned 0.0 for all three.

t_value = t_value.nan_to_num()
p_value = normal_dist.cdf(t_value)
return p_value.where(~is_nan, torch.tensor(float("nan"), dtype=p_value.dtype, device=p_value.device))
return 0.5 * torch.erfc(-t_value / math.sqrt(2.0))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The returned p-value is float32 even when preds/target are float64, so anything below the float32 range still comes out as 0.0. Example: n=200 with tau 0.79 gives 0.0 here, while scipy gives 1.1e-61. Computing t_value in the input dtype would keep those. Fine as a follow-up if float32 is intended.

Compute the t statistic in the promoted input dtype so float64 inputs keep tail probabilities below the float32 range.
@WeiLiuu

WeiLiuu commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Changed in 1859439: the t statistic is now computed in the promoted input dtype, so float64 inputs return a float64 p-value, while float32 and lower still return float32. The new test checks an n=200, tau 0.79 float64 case against scipy (p around 1e-62) and the float32 dtype.

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.

3 participants