{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Null hypothesis and p-values"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The null hypothesis is that the true odds ratio of the populations underlying the observations is one, and the observations were sampled at random from these populations under a condition: the marginals of the resulting table must equal those of the observed table. Equivalently, the null hypothesis is that the input table is from the hypergeometric distribution with parameters (as used in "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "hypergeom",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "M = a + b + c + d"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "n = a + b"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "N = a + c"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", where the input table is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "[[a, b], [c, d]]"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  This distribution has support "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "max(0, N + n - M) <= x <= min(N, n)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", or, in terms of the values in the input table, "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "min(0, a - d) <= x <= a + min(b, c)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " can be interpreted as the upper-left element of a 2x2 table, so the tables in the distribution have form      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "[  x           n - x     ]\n[N - x    M - (n + N) + x]",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For example, if      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "table = [6  2]\n        [1  4]",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "then the support is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "2 <= x <= 7"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and the tables in the distribution are      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "[2 6]   [3 5]   [4 4]   [5 3]   [6 2]  [7 1]\n[5 0]   [4 1]   [3 2]   [2 3]   [1 4]  [0 5]",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The probability of each table is given by the hypergeometric distribution "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "hypergeom.pmf(x, M, n, N)"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  For this example, these are (rounded to three significant digits)      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "x       2      3      4      5       6        7\np  0.0163  0.163  0.408  0.326  0.0816  0.00466",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "These can be computed with      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> import numpy as np\n>>> from scipy.stats import hypergeom\n>>> table = np.array([[6, 2], [1, 4]])\n>>> M = table.sum()\n>>> n = table[0].sum()\n>>> N = table[:, 0].sum()\n>>> start, end = hypergeom.support(M, n, N)\n>>> hypergeom.pmf(np.arange(start, end+1), M, n, N)\narray([0.01631702, 0.16317016, 0.40792541, 0.32634033, 0.08158508,\n       0.004662  ])",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The two-sided p-value is the probability that, under the null hypothesis, a random table would have a probability equal to or less than the probability of the input table.  For our example, the probability of the input table (where "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x = 6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") is 0.0816.  The x values where the probability does not exceed this are 2, 6 and 7, so the two-sided p-value is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "0.0163 + 0.0816 + 0.00466 ~= 0.10256"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> from scipy.stats import fisher_exact\n>>> res = fisher_exact(table, alternative='two-sided')\n>>> res.pvalue\n0.10256410256410257",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The one-sided p-value for "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "alternative='greater'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is the probability that a random table has "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x >= a"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", which in our example is "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x >= 6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "0.0816 + 0.00466 ~= 0.08626"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> res = fisher_exact(table, alternative='greater')\n>>> res.pvalue\n0.08624708624708627",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This is equivalent to computing the survival function of the distribution at "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x = 5"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (one less than "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " from the input table, because we want to include the probability of "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x = 6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in the sum)      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> hypergeom.sf(5, M, n, N)\n0.08624708624708627",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "alternative='less'"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", the one-sided p-value is the probability that a random table has "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x <= a"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", (i.e. "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x <= 6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in our example), or "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "0.0163 + 0.163 + 0.408 + 0.326 + 0.0816 ~= 0.9949"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": ">>> res = fisher_exact(table, alternative='less')\n>>> res.pvalue\n0.9953379953379957",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This is equivalent to computing the cumulative distribution function of the distribution at "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "x = 6"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ":"
            }
          ]
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Code",
              "__tag": 4050,
              "value": ">>> hypergeom.cdf(6, M, n, N)\n0.9953379953379957",
              "execution_status": null
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Emphasis",
              "__tag": 4047,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Odds ratio"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The calculated odds ratio is different from the value computed by the R function "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fisher.test"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ".  This implementation returns the \"sample\" or \"unconditional\" maximum likelihood estimate, while "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "fisher.test"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " in R uses the conditional maximum likelihood estimate.  To compute the conditional maximum likelihood estimate of the odds ratio, use "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "scipy.stats.contingency.odds_ratio",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": "scipy",
                "version": "*",
                "kind": "api",
                "path": "scipy.stats._odds_ratio:odds_ratio"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Strong",
              "__tag": 4048,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Array API Standard Support"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "fisher_exact",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.stats._stats_py:fisher_exact"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "SCIPY_ARRAY_API=1"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported."
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "====================  ====================  ====================\nLibrary               CPU                   GPU\n====================  ====================  ====================\nNumPy                 ✅                     n/a                 \nCuPy                  n/a                   ⛔                   \nPyTorch               ⛔                     ⛔                   \nJAX                   ⛔                     ⛔                   \nDask                  ⛔                     n/a                 \n====================  ====================  ====================",
          "execution_status": null
        },
        {
          "__type": "Blockquote",
          "__tag": 4059,
          "children": [
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "See "
                },
                {
                  "__type": "InlineRole",
                  "__tag": 4003,
                  "value": "dev-arrayapi",
                  "domain": null,
                  "role": "ref",
                  "inventory": null
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for more information."
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "",
              "annotation": "ValueError",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "table"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is not two-dimensional or has negative entries."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "res",
              "annotation": "SignificanceResult",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An object containing attributes:"
                    }
                  ]
                },
                {
                  "__type": "DefList",
                  "__tag": 4033,
                  "children": [
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "statistic"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "statistic"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "DefListItem",
                      "__tag": 4037,
                      "dt": {
                        "__type": "Paragraph",
                        "__tag": 4045,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "pvalue"
                          }
                        ]
                      },
                      "dd": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "pvalue"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Perform a Fisher exact test on a contingency table."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "table",
              "annotation": "array_like of ints",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "A contingency table.  Elements must be non-negative integers."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "alternative",
              "annotation": "{'two-sided', 'less', 'greater'}, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Defines the alternative hypothesis for 2x2 tables; unused for other table sizes. The following options are available (default is 'two-sided'):"
                    }
                  ]
                },
                {
                  "__type": "BulletList",
                  "__tag": 4053,
                  "ordered": false,
                  "start": 1,
                  "children": [
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "'two-sided': the odds ratio of the underlying population is not one"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "'less': the odds ratio of the underlying population is less than one"
                            }
                          ]
                        }
                      ]
                    },
                    {
                      "__type": "ListItem",
                      "__tag": 4054,
                      "children": [
                        {
                          "__type": "Paragraph",
                          "__tag": 4045,
                          "children": [
                            {
                              "__type": "Text",
                              "__tag": 4046,
                              "value": "'greater': the odds ratio of the underlying population is greater   than one"
                            }
                          ]
                        }
                      ]
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "See the Notes for more details."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "method",
              "annotation": "ResamplingMethod, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Defines the method used to compute the p-value. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "method"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is an instance of "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "PermutationMethod",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.stats._resampling:PermutationMethod"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "/"
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "MonteCarloMethod",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.stats._resampling:MonteCarloMethod"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", the p-value is computed using "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.permutation_test",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._resampling:permutation_test"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "/"
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "scipy.stats.monte_carlo_test",
                      "reference": {
                        "__type": "RefInfo",
                        "__tag": 4000,
                        "module": "scipy",
                        "version": "*",
                        "kind": "api",
                        "path": "scipy.stats._resampling:monte_carlo_test"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " with the provided configuration options and other appropriate settings. Note that if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "method"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is an instance of "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "MonteCarloMethod",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.stats._resampling:MonteCarloMethod"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " attribute must be left unspecified; Monte Carlo samples are always drawn using the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "rvs"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " method of "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "scipy.stats.random_table",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ". Otherwise, the p-value is computed as documented in the notes."
                    }
                  ]
                },
                {
                  "__type": "Admonition",
                  "__tag": 4056,
                  "kind": "versionadded",
                  "base_type": "neutral",
                  "children": [
                    {
                      "__type": "AdmonitionTitle",
                      "__tag": 4055,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "versionadded 1.15.0"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For a 2x2 table, the null hypothesis is that the true odds ratio of the populations underlying the observations is one, and the observations were sampled from these populations under a condition: the marginals of the resulting table must equal those of the observed table. The statistic is the unconditional maximum likelihood estimate of the odds ratio, and the p-value is the probability under the null hypothesis of obtaining a table at least as extreme as the one that was actually observed."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "For other table sizes, or if "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "method"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is provided, the null hypothesis is that the rows and columns of the tables have fixed sums and are independent; i.e., the table was sampled from a "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "scipy.stats.random_table",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " distribution with the observed marginals. The statistic is the probability mass of this distribution evaluated at "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "table"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and the p-value is the percentage of the population of tables with statistic at least as extreme (small) as that of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "table"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". There is only one alternative hypothesis available: the rows and columns are not independent."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "There are other possible choices of statistic and two-sided p-value definition associated with Fisher's exact test; please see the Notes for more information."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/stats/_stats_py.py",
  "item_line": 4788,
  "item_type": "function",
  "aliases": [
    "scipy.stats.fisher_exact"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "from scipy.stats import fisher_exact\nres = fisher_exact([[8, 2], [1, 5]])\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "res.statistic\nres.pvalue\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFor tables with shape other than ``(2, 2)``, provide an instance of\n`scipy.stats.MonteCarloMethod` or `scipy.stats.PermutationMethod` for the\n`method` parameter:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nfrom scipy.stats import MonteCarloMethod\nrng = np.random.default_rng(4507195762371367)\nmethod = MonteCarloMethod(rng=rng)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "fisher_exact([[8, 2, 3], [1, 5, 4]], method=method)\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nFor a more detailed example, see :ref:`hypothesis_fisher_exact`."
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "barnard_exact",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.stats._hypotests:barnard_exact"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Barnard's exact test, which is a more powerful alternative than Fisher's exact test for 2x2 contingency tables."
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "boschloo_exact",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.stats._hypotests:boschloo_exact"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Boschloo's exact test, which is a more powerful alternative than Fisher's exact test for 2x2 contingency tables."
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "chi2_contingency",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.stats.contingency:chi2_contingency"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Chi-square test of independence of variables in a contingency table.  This can be used as an alternative to "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "fisher_exact",
              "domain": null,
              "role": null,
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " when the numbers in the table are large."
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "contingency.odds_ratio",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "contingency.odds_ratio"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Compute the odds ratio (sample or conditional MLE) for a 2x2 contingency table."
            }
          ]
        }
      ],
      "type": "func"
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "hypothesis_fisher_exact",
        "reference": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "current-module",
          "version": "current-version",
          "kind": "to-resolve",
          "path": "hypothesis_fisher_exact"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Extended example"
            }
          ]
        }
      ],
      "type": "ref"
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "table",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "alternative",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "method",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "KEYWORD_ONLY",
        "default": "None"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "fisher_exact"
  },
  "references": [
    ".. [1] Fisher, Sir Ronald A, \"The Design of Experiments:",
    "       Mathematics of a Lady Tasting Tea.\" ISBN 978-0-486-41151-4, 1935.",
    ".. [2] \"Fisher's exact test\",",
    "       https://en.wikipedia.org/wiki/Fisher's_exact_test"
  ],
  "qa": "scipy.stats._stats_py:fisher_exact",
  "arbitrary": [],
  "local_refs": [
    "alternative",
    "method",
    "res",
    "table"
  ]
}