Categorical calculator

Fisher's exact test calculator

Calculate exact hyper-geometric p-values and odds ratios for 2x2 contingency tables using Fisher's exact test.

Run this test live in StatLab npm i @statlab/core

When to use it

Use for 2x2 tables when sample sizes are small or expected cell counts are < 5.

Required Inputs

  • 2x2 Contingency Matrix counts [[a, b], [c, d]]
  • Alternative hypothesis (two-sided, greater, less)

Mathematical Formula

p = [ (a+b)! (c+d)! (a+c)! (b+d)! ] / [ a! b! c! d! n! ]

Reporting Cautions

  • Valid for 2x2 tables; computationally intensive for larger tables.
  • Provides exact p-values without relying on asymptotic normal approximations.

Code Snippets (Python, R, TypeScript)

Python (SciPy / Statsmodels)
from scipy import stats
oddsratio, pvalue = stats.fisher_exact([[4, 1], [0, 5]])
print(f"OR={oddsratio:.4f}, p={pvalue:.4f}")
R Language
fisher.test(matrix(c(4, 0, 1, 5), nrow=2))
TypeScript (@statlab/core)
import { fisherExact } from '@statlab/core';
const res = fisherExact([[4, 1], [0, 5]]);

Developer Use Cases & Production Integrations

  • Testing small-sample rare event frequencies in security audit logs.
  • Comparing low-occurrence failure rates across microservices.

VoxelPulse Telemetry Control Plane

Continuous A/B testing, statistical telemetry analysis, and automated feedback loops for live backend services.

Explore VoxelPulse →

VoxelAssurance Release Readiness

Fixed-price AI release-readiness sprints, automated regression testing, and reliability statistical benchmarks.

Explore VoxelAssurance →

Related Statistical Test Calculators

Explore static calculators across the StatLab inference engine suite.