bundles / scipy latest / scipy / stats / _hypotests / boschloo_exact
function
scipy.stats._hypotests:boschloo_exact
source: /scipy/stats/_hypotests.py :1259
Signature
def boschloo_exact ( table , alternative = two-sided , n = 32 ) Summary
Perform Boschloo's exact test on a 2x2 contingency table.
Parameters
table: array_like of intsA 2x2 contingency table. Elements should be non-negative integers.
alternative: {'two-sided', 'less', 'greater'}, optionalDefines the null and alternative hypotheses. Default is 'two-sided'. Please see explanations in the Notes section below.
n: int, optionalNumber of sampling points used in the construction of the sampling method. Note that this argument will automatically be converted to the next higher power of 2 since scipy.stats.qmc.Sobol is used to select sample points. Default is 32. Must be positive. In most cases, 32 points is enough to reach good precision. More points comes at performance cost.
Returns
ber: BoschlooExactResultA result object with the following attributes.
statistic
statistic
pvalue
pvalue
Notes
Boschloo's test is an exact test used in the analysis of contingency tables. It examines the association of two categorical variables, and is a uniformly more powerful alternative to Fisher's exact test for 2x2 contingency tables.
Boschloo's exact test uses the p-value of Fisher's exact test as a statistic, and Boschloo's p-value is the probability under the null hypothesis of observing such an extreme value of this statistic.
Let's define a 2x2 matrix representing the observed sample, where each column stores the binomial experiment, as in the example below. Let's also define the theoretical binomial probabilities for and . When using Boschloo exact test, we can assert three different alternative hypotheses:
versus , with
alternative= "less"versus , with
alternative= "greater"versus , with
alternative= "two-sided" (default)
There are multiple conventions for computing a two-sided p-value when the null distribution is asymmetric. Here, we apply the convention that the p-value of a two-sided test is twice the minimum of the p-values of the one-sided tests (clipped to 1.0). Note that fisher_exact follows a different convention, so for a given table, the statistic reported by boschloo_exact may differ from the p-value reported by fisher_exact when alternative='two-sided'.
Array API Standard Support
boschloo_exact has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ⛔ ⛔ JAX ⛔ ⛔ Dask ⛔ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
In the following example, we consider the article "Employee attitudes and job satisfaction" [3]_ which reports the results of a survey from 63 scientists and 117 college professors. Of the 63 scientists, 31 said they were very satisfied with their jobs, whereas 74 of the college professors were very satisfied with their work. Is this significant evidence that college professors are happier with their work than scientists? The following table summarizes the data mentioned above:: college professors scientists Very Satisfied 74 31 Dissatisfied 43 32 When working with statistical hypothesis testing, we usually use a threshold probability or significance level upon which we decide to reject the null hypothesis :math:`H_0`. Suppose we choose the common significance level of 5%. Our alternative hypothesis is that college professors are truly more satisfied with their work than scientists. Therefore, we expect :math:`p_1` the proportion of very satisfied college professors to be greater than :math:`p_2`, the proportion of very satisfied scientists. We thus call `boschloo_exact` with the ``alternative="greater"`` option:import scipy.stats as stats res = stats.boschloo_exact([[74, 31], [43, 32]], alternative="greater")✓
res.statistic res.pvalue✗
See also
- barnard_exact
Barnard's exact test, which is a more powerful alternative than Fisher's exact test for 2x2 contingency tables.
- chi2_contingency
Chi-square test of independence of variables in a contingency table.
- fisher_exact
Fisher exact test on a 2x2 contingency table.
Aliases
-
scipy.stats.boschloo_exact