Skip to content

Make two-sided Fisher p-value independent of group order - #5836

Open
arieleven wants to merge 1 commit into
cBioPortal:masterfrom
arieleven:fix/fisher-two-sided-tolerance
Open

arieleven wants to merge 1 commit into
cBioPortal:masterfrom
arieleven:fix/fisher-two-sided-tolerance

Conversation

@arieleven

@arieleven arieleven commented Nov 17, 2026 •

Copy link
Copy Markdown

Fix cBioPortal/cbioportal#12501 (frontend part)

Describe changes proposed in this pull request:

  • getTwoTailedPValue in src/shared/lib/calculation/FisherExactTestCalculator.ts kept a table only if its probability was <= the observed table's. With equal-size groups the mirror table has exactly the same probability, but the two log-factorial sums can differ in the last bits, so it could be dropped and the p-value changed when the groups were swapped. For example, getTwoTailedPValue(298, 2, 299, 1) returns 1 but getTwoTailedPValue(299, 1, 298, 2) returns 0.624.
  • It now compares with a relative tolerance of 1e-7, the same as R's fisher.test, and caps the sum at 1 (it could come out as 1.0000000000006).
  • This is the frontend counterpart of the backend change in Fix group-order dependence in Java Fisher exact test cbioportal#12502. It affects the comparison lollipop's Fisher test, the two-sided test label, and mutual exclusivity.

Checks

  • Has tests: two new cases in FisherExactTestCalculator.spec.ts (swapped groups give the same p-value and match R's fisher.test; the p-value is never above 1). Both fail on master and pass with the change; the existing cases still pass unchanged. I ran the spec file with a small standalone runner because I didn't do a full pnpm install here, so CI's Jest run is the real check.
  • The commit log is comprehensible (single commit).
  • Not adding logic based on clinical attributes.

Label: could a maintainer add fix? I can't set labels from a fork.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

getTwoTailedPValue kept a table only if its probability was <= the
observed table's. With equal-size groups the mirror table has exactly
the same probability, but the two log-factorial sums can differ in the
last bits, so the result changed when the groups were swapped (for
example 1 vs 0.624 for 299/1 vs 298/2). Compare with a relative
tolerance of 1e-7, as R's fisher.test does, and cap the sum at 1.

This matches the backend fix proposed in cBioPortal/cbioportal#12502
for cBioPortal/cbioportal#12501.
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cbioportal-frontend Ready Ready Preview Nov 17, 2026 4:28pm UTC

Request Review

@arieleven

Copy link
Copy Markdown
Author

Marking this ready for review. The failing CircleCI jobs here (e2e_localdb_merge, e2e_localdb_shards, remote_e2e and remote_e2e_shards) also fail on other recent PRs, such as #5832, #5833 and #5837 to #5839, so they don't look related to this change. Unit tests, typecheck, prettier and the build all pass.

This branch was successfully deployed

1 active deployment
Preview — 0f89edbb Deployed Nov 17, 2026 by vercel[bot]
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.

[BUG] Two-sided Fisher p-value in alteration enrichments changes when the two groups are renamed

1 participant