(n, k)
| 690 | # Binomial coefficient. |
| 691 | # n! / k!(n-k)! for 0 <= k <= n |
| 692 | def C(n, k): |
| 693 | if len(_cache) > 10000: |
| 694 | _cache.clear() |
| 695 | if k > n - k: # 2x speedup. |
| 696 | k = n - k |
| 697 | if 0 <= k <= n and (n, k) not in _cache: |
| 698 | c = 1.0 |
| 699 | for i in range(1, int(k + 1)): |
| 700 | c *= n - k + i |
| 701 | c /= i |
| 702 | _cache[(n, k)] = c # 3x speedup. |
| 703 | return _cache.get((n, k), 0.0) |
| 704 | # Probability of the given data. |
| 705 | cutoff = p(a, b, c, d) |
| 706 | # Probabilities of "more extreme" data, in both directions (two-tailed). |