How to use it
- Arrange your data as a 2×2 table: rows are the two groups, columns are the two outcomes.
- Enter the four counts a, b (first row) and c, d (second row).
- Read the two-sided p-value, or a one-sided one if you chose a direction in advance.
| Outcome yes | Outcome no | |
|---|---|---|
| Group 1 | a | b |
| Group 2 | c | d |
How the test works
With the row and column totals fixed, the count a follows the hypergeometric distribution:
P(a) = C(a + b, a) × C(c + d, c) ÷ C(n, a + c)
where C(n, k) is the number of ways to choose k items from n. The calculator lists every table with the same totals:
- Two-sided p = sum of P over all tables no more likely than the observed one (with a relative tolerance of 10⁻⁷ for rounding).
- One-sided p = sum of P over tables with a as small or smaller, or as large or larger.
Worked example
Group 1: 8 yes, 2 no. Group 2: 1 yes, 5 no. Row totals 10 and 6, column totals 9 and 7, n = 16, and C(16, 9) = 11 440 tables in all.
Possible values of a run from 3 to 9, with counts C(10, a) × C(6, 9 − a) of 120, 1260, 3780, 4200, 1800, 270 and 10. The observed a = 8 has 270, so P = 270/11 440 = 0.024. Tables no more likely: a = 3 (120), 8 (270) and 9 (10), so the two-sided p = 400/11 440 = 0.035: significant at 0.05. The one-sided p for larger a is (270 + 10)/11 440 = 0.024.
Tips and common mistakes
- Enter counts of people or items, not percentages.
- Each subject must appear in exactly one cell. For paired yes/no data on the same subjects, use McNemar’s test.
- Decide on one-sided or two-sided before looking at the data.