Skip to Content

BOSCHLOO_EXACT

Overview

The BOSCHLOO_EXACT function performs Boschloo’s exact test on a 2x2 contingency table. This test is a uniformly more powerful alternative to Fisher’s exact test for 2x2 tables. It uses Fisher’s exact test p-value as a statistic and computes Boschloo’s p-value as the probability of observing such an extreme statistic value under the null hypothesis. For more details, see the Scipy documentation.

Excel has no equivalent to Boschloo’s exact test. This specialized statistical test requires implementing Fisher’s exact test as an intermediate step and then using sophisticated algorithms to compute the exact distribution of Fisher’s p-values under the null hypothesis. The computational methodology is far beyond standard Excel capabilities and requires specialized statistical software.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=BOSCHLOO_EXACT(table, [alternative])
  • table (2D list, required): 2x2 contingency table with non-negative integer entries.
  • alternative (str, optional, default=‘two-sided’): Defines the alternative hypothesis. Options are ‘two-sided’, ‘less’, ‘greater’.

The function returns a single row (2D list) with two values: the Fisher’s exact p-value (test statistic) and Boschloo’s p-value.

Examples

Example 1: Two-sided test

Inputs:

tablealternative
12529two-sided
79

Excel formula:

=BOSCHLOO_EXACT({{12,5};{7,9}}, "two-sided")

Expected output:

Fisher p-valueBoschloo p-value
0.11370.1333

Example 2: Greater alternative

Inputs:

tablealternative
7431greater
4332

Excel formula:

=BOSCHLOO_EXACT({{74,31};{43,32}}, "greater")

Expected output:

Fisher p-valueBoschloo p-value
0.04830.0356

Example 3: Less alternative

Inputs:

tablealternative
1020less
1525

Excel formula:

=BOSCHLOO_EXACT({{10,20};{15,25}}, "less")

Expected output:

Fisher p-valueBoschloo p-value
0.45850.3719

Example 4: Default alternative (two-sided)

Inputs:

tablealternative
82
15

Excel formula:

=BOSCHLOO_EXACT({{8,2};{1,5}})

Expected output:

Fisher p-valueBoschloo p-value
0.02450.0244

Python Code

from scipy.stats import boschloo_exact as scipy_boschloo_exact def boschloo_exact(table, alternative='two-sided'): """ Perform Boschloo's exact test on a 2x2 contingency table. Args: table: 2D list (2x2) contingency table with non-negative integer entries. alternative: Defines the alternative hypothesis. Options are 'two-sided', 'less', 'greater'. Returns: A 2D list containing the test statistic (Fisher's exact p-value) and Boschloo's p-value, each as a separate element in the first row. This example function is provided as-is without any representation of accuracy. """ # Validate table if not isinstance(table, list) or len(table) != 2 or not all(isinstance(row, list) and len(row) == 2 for row in table): return [["Invalid input: table must be a 2x2 list of non-negative integers."]] try: arr = [[int(x) for x in row] for row in table] except Exception: return [["Invalid input: table must contain integers."]] if any(x < 0 for row in arr for x in row): return [["Invalid input: table must contain non-negative integers."]] if alternative not in ['two-sided', 'less', 'greater']: return [["Invalid input: alternative must be 'two-sided', 'less', or 'greater'."]] try: res = scipy_boschloo_exact(arr, alternative=alternative) stat = float(res.statistic) pval = float(res.pvalue) # Disallow nan/inf if any([s is None or p is None for s, p in [(stat, pval)]]) or any([not (s == s and p == p) for s, p in [(stat, pval)]]) or any([abs(s) == float('inf') or abs(p) == float('inf') for s, p in [(stat, pval)]]): return [["Invalid result: nan or inf encountered."]] return [[stat, pval]] except Exception as e: return [[f"scipy.stats.boschloo_exact error: {e}"]]

Example Workbook

Link to Workbook

Last updated on