in commons-statistics-inference/src/main/java/org/apache/commons/statistics/inference/UnconditionedExactTest.java [888:920]
private double findExtremeTablesBoschloo(int a, int b, int m, int n, XYList tableList) {
final double statistic = statisticBoschloo(a, b, m, n);
// Function to compute the statistic
BoschlooStatistic func;
if (alternative == AlternativeHypothesis.GREATER_THAN) {
func = (dist, x) -> dist.sf(x - 1);
} else if (alternative == AlternativeHypothesis.LESS_THAN) {
func = Hypergeom::cdf;
} else {
func = UnconditionedExactTest::statisticBoschlooTwoSided;
}
// All tables are: 0 <= i <= m by 0 <= j <= n
// Diagonal (upper-left to lower-right) strips of the possible
// tables use the same hypergeometric distribution
// (i.e. i+j == number of successes). To enumerate all requires
// using the full range of all distributions: 0 <= i+j <= m+n.
// Note the column sum m is fixed.
final int mn = m + n;
for (int k = 0; k <= mn; k++) {
final Hypergeom dist = new Hypergeom(mn, k, m);
final int lo = dist.getSupportLowerBound();
final int hi = dist.getSupportUpperBound();
for (int i = lo; i <= hi; i++) {
if (func.value(dist, i) <= statistic) {
// j = k - i
tableList.add(i, k - i);
}
}
}
return statistic;
}