# Boschloo's test

Boschloo's test is a statistical hypothesis test for analysing 2x2 contingency tables. It examines the association of two Bernoulli distributed random variables and is a uniformly more powerful alternative to Fisher's exact test. It was proposed in 1970 by R. D. Boschloo.

## Setting

A 2 × 2 contingency table visualizes $\ n\$ independent observations of two binary variables $\ A\$ and $\ B\$:
    ${\begin{array}{c|cc|c}&B=1&B=0&{\mbox{Total}}\\\hline A=1&x_{11}&x_{10}&n_{1}\\A=0&x_{01}&x_{00}&n_{0}\\\hline {\mbox{Total}}&s_{1}&s_{0}&n\\\end{array}}$
The probability distribution of such tables can be classified into three distinct cases.
* The row sums $\ n_{1}\ ,n_{0}\$ and column sums $\ s_{1}\ ,s_{0}\$ are fixed in advance and not random. Then all $\ x_{ij}\$ are determined by $\ x_{11}~.$ If $\ A\$ and $\ B\$ are independent, $\ x_{11}\$ follows a hypergeometric distribution with parameters $\ n\ ,n_{1}\ ,s_{1}\ :$ $\ x_{11}\ \sim \ {\mbox{Hypergeometric}}(\ n\ ,n_{1}\ ,s_{1}\ )~.$
* The row sums $\ n_{1}\ ,n_{0}\$ are fixed in advance but the column sums $\ s_{1}\ ,s_{0}\$ are not. Then all random parameters are determined by $\ x_{11}\$ and $x_{01}\$ and $\ x_{11}\ ,x_{01}\$ follow a binomial distribution with probabilities $\ p_{1}\ ,p_{0}\ :$ $\ x_{11}\ \sim \ B(\ n_{1}\ ,p_{1}\ )\$ $\ x_{01}\ \sim \ B(\ n_{0}\ ,p_{0}\ )\$
* Only the total number $\ n\$ is fixed but the row sums $\ n_{1}\ ,n_{0}\$ and the column sums $\ s_{1}\ ,s_{0}\$ are not. Then the random vector $\ (\ x_{11},x_{10}\ ,x_{01}\ ,x_{00}\ )\$ follows a multinomial distribution with probability vector $\ (p_{11}\ ,p_{10}\ ,p_{01}\ ,p_{00}\ )~.$

### Experiment type 1: Rare taste-test experiment, fully constrained

Fisher's exact test is designed for the first case and therefore an exact conditional test (because it conditions on the column sums). The typical example of such a case is the Lady tasting tea: A lady tastes 8 of tea with milk. In 4 of those cups the milk is poured in before the tea. In the other 4 cups the tea is poured in first.
The lady tries to assign the cups to the two categories. Following our notation, the random variable $\ A\$ represents the used method (1 = milk first, 0 = milk last) and $\ B\$ represents the lady's guesses (1 = milk first guessed, 0 = milk last guessed). Then the row sums are the fixed numbers of cups prepared with each method: $\ n_{1}=4\ ,n_{0}=4~.$ The lady knows that there are 4 cups in each category, so will assign 4 cups to each method. Thus, the column sums are also fixed in advance: $\ s_{1}=4\ ,s_{0}=4~.$ If she is not able to tell the difference, $\ A\$ and $\ B\$ are independent and the number $\ x_{11}\$ of correctly classified cups with milk first follows the hypergeometric distribution $\ {\mbox{Hypergeometric}}(8,4,4)~.$

### Experiment type 2: Normal laboratory controlled experiment, only one margin constrained

Boschloo's test is designed for the second case and therefore an exact unconditional test. Examples of such a case are often found in medical research, where a binary endpoint is compared between two patient groups. Following our notation, $\ A=1\$ represents the first group that receives some medication of interest. $\ A=0\$ represents the second group that receives a placebo. $B$ indicates the cure of a patient (1 = cure, 0 = no cure). Then the row sums equal the group sizes and are usually fixed in advance. The column sums are the total number of cures respectively disease continuations and not fixed in advance.

### Experiment type 3: Field observation, no marginal constraints at all

Pearson's chi-squared test (without any "continuity correction") is the correct choice for the third case, where there are no constraints on either the row totals or the column totals. This third scenario describes most observational studies or "field-observations", where data is collected as-available in an uncontrolled environment. For example, if one goes out collecting two types of butterflies of some particular predetermined identifiable color, which can be recognized before capture, however it is not possible to distinguished whether a butterfly is species 1 or species 0; before it is captured and closely examined: One can merely tell by its color that a butterfly being pursued must be either one of the two species of interest. For any one day's session of butterfly collecting, one cannot predetermine how many of each species will be collected, only perhaps the total number of capture, depending on the collector's criterion for stopping. If the species are tallied in separate rows of the table, then the row sums are unconstrained and independently binomially distributed. The second distinction between the captured butterflies will be whether the butterfly is female (type 1) or male (type 0), tallied in the columns. If its sex also requires close examination of the butterfly, that also is independently binomially random. That means that because of the experimental design, the column sums are unconstrained just like the rows are: Neither the count for either of species, nor count of the sex of the captured butterflies in each species is predetermined by the process of observation, and neither total constrains the other.
The only possible constraint is the grand total of all butterflies captured, and even that could itself be unconstrained, depending on how the collector decides to stop. But since one cannot reliably know beforehand for any one particular day in any one particular meadow how successful one's pursuit might be during the time available for collection, even the grand total might be unconstrained: It depends on whether the constraint on data collected is the time available to catch butterflies, or some predetermined total to be collected, perhaps to ensure adequately significant statistics.
This type of 'experiment' (also called a "field observation") is almost entirely uncontrolled, hence some prefer to only call it an 'observation', not an 'experiment'. All the numbers in the table are independently random. Each of the cells of the contingency table is a separate binomial probability and neither Fisher's fully constrained 'exact' test nor Boschloo's partly-constrained test are based on the statistics arising from the experimental design. Pearson's chi-squared test is the appropriate test for an unconstrained observational study, and Pearson's test, in turn, employs the wrong statistical model for the other two types of experiment. (Note in passing that Pearson's chi-squared statistic should never have any "continuity correction" applied, what-so-ever, e.g. no "Yates' correction": The consequence of that "correction" will be to distort its p values to match Fisher's test, i.e. give the wrong answer.)

## Test hypothesis

The null hypothesis of Boschloo's one-tailed test (high values of $x_{1}$ favor the alternative hypothesis) is:
    $H_{0}:p_{1}\leq p_{0}$
The null hypothesis of the one-tailed test can also be formulated in the other direction (small values of $x_{1}$ favor the alternative hypothesis):
    $H_{0}:p_{1}\geq p_{0}$
The null hypothesis of the two-tailed test is:
    $H_{0}:p_{1}=p_{0}$
There is no universal definition of the two-tailed version of Fisher's exact test. Since Boschloo's test is based on Fisher's exact test, a universal two-tailed version of Boschloo's test also doesn't exist. In the following we deal with the one-tailed test and $H_{0}:p_{1}\leq p_{0}$.

## Boschloo's idea

We denote the desired significance level by $\alpha$. Fisher's exact test is a conditional test and appropriate for the first of the above mentioned cases. But if we treat the observed column sum $s_{1}$ as fixed in advance, Fisher's exact test can also be applied to the second case. The true size of the test then depends on the nuisance parameters $p_{1}$ and $p_{0}$. It can be shown that the size maximum $\max \limits _{p_{1}\leq p_{0}}{\big{\mbox{size}}(p_{1},p_{0}){\big )}$ is taken for equal proportions $p=p_{1}=p_{0}$ and is still controlled by $\alpha$. However, Boschloo stated that for small sample sizes, the maximal size is often considerably smaller than $\alpha$. This leads to an undesirable loss of power.
Boschloo proposed to use Fisher's exact test with a greater nominal level $\alpha ^{*}>\alpha$. Here, $\alpha ^{*}$ should be chosen as large as possible such that the maximal size is still controlled by $\alpha$: $\max \limits _{p\in [0,1]}{\big{\mbox{size}}(p){\big )}\leq \alpha$. This method was especially advantageous at the time of Boschloo's publication because $\alpha ^{*}$ could be looked up for common values of $\alpha ,n_{1}$ and $n_{0}$. This made performing Boschloo's test computationally easy.

## Test statistic

The decision rule of Boschloo's approach is based on Fisher's exact test. An equivalent way of formulating the test is to use the p-value of Fisher's exact test as test statistic. Fisher's p-value is calculated from the hypergeometric distribution (for ease of notation we write $x_{1},x_{0}$ instead of $x_{11},x_{01}$):
    $p_{F}=1-F_{{\mbox{Hypergeometric}}(n,n_{1},x_{1}+x_{0})}(x_{1}-1)$
The distribution of $p_{F}$ is determined by the binomial distributions of $x_{1}$ and $x_{0}$ and depends on the unknown nuisance parameter $p$. For a specified significance level $\alpha ,$ the critical value of $p_{F}$ is the maximal value $\alpha ^{*}$ that satisfies $\max \limits _{p\in [0,1]}P(p_{F}\leq \alpha ^{*})\leq \alpha$. The critical value $\alpha ^{*}$ is equal to the nominal level of Boschloo's original approach.

## Modification

Boschloo's test deals with the unknown nuisance parameter $p$ by taking the maximum over the whole parameter space $[0,1]$. The Berger & Boos procedure takes a different approach by maximizing $P(p_{F}\leq \alpha ^{*})$ over a $(1-\gamma )$ confidence interval of $p=p_{1}=p_{0}$ and adding $\gamma$. $\gamma$ is usually a small value such as 0.001 or 0.0001. This results in a modified Boschloo's test which is also exact.

## Comparison to other exact tests

All exact tests hold the specified significance level but can have varying power in different situations. Mehrotra et al. compared the power of some exact tests in different situations. The results regarding Boschloo's test are summarized in the following.

### Modified Boschloo's test

Boschloo's test and the modified Boschloo's test have similar power in all considered scenarios. Boschloo's test has slightly more power in some cases, and vice versa in some other cases.

### Fisher's exact test

Boschloo's test is by construction uniformly more powerful than Fisher's exact test. For small sample sizes (e.g. 10 per group) the power difference is large, ranging from 16 to 20 percentage points in the regarded cases. The power difference is smaller for greater sample sizes.

### Exact Z-Pooled test

This test is based on the test statistic
    $Z_{P}(x_{1},x_{0})={\frac {{\hat {p}}_{1}-{\hat {p}}_{0}}{\sqrt {{\tilde {p}}(1-{\tilde {p}})({\frac {1}{n_{1}}}+{\frac {1}{n_{0}}})}}},$
where ${\hat {p}}_{i}={\frac {x_{i}}{n_{i}}}$ are the group event rates and ${\tilde {p}}={\frac {x_{1}+x_{0}}{n_{1}+n_{0}}}$ is the pooled event rate.
The power of this test is similar to that of Boschloo's test in most scenarios. In some cases, the $Z$-Pooled test has greater power, with differences mostly ranging from 1 to 5 percentage points. In very few cases, the difference goes up to 9 percentage points.
This test can also be modified by the Berger & Boos procedure. However, the resulting test has very similar power to the unmodified test in all scenarios.

### Exact Z-Unpooled test

This test is based on the test statistic
    $Z_{U}(x_{1},x_{0})={\frac {{\hat {p}}_{1}-{\hat {p}}_{0}}{\sqrt {{\frac {{\hat {p}}_{1}(1-{\hat {p}}_{1})}{n_{1}}}+{\frac {{\hat {p}}_{0}(1-{\hat {p}}_{0})}{n_{0}}}}}},$
where ${\hat {p}}_{i}={\frac {x_{i}}{n_{i}}}$ are the group event rates.
The power of this test is similar to that of Boschloo's test in many scenarios. In some cases, the $Z$-Unpooled test has greater power, with differences ranging from 1 to 5 percentage points. However, in some other cases, Boschloo's test has noticeably greater power, with differences up to 68 percentage points.
This test can also be modified by the Berger & Boos procedure. The resulting test has similar power to the unmodified test in most scenarios. In some cases, the power is considerably improved by the modification but the overall power comparison to Boschloo's test remains unchanged.

## Software

The calculation of Boschloo's test can be performed in following software:
* The function scipy.stats.boschloo_exact from SciPy
* Packages Exact and exact2x2 of the programming language R
* StatXact