Statistics: fishertest

### Function Reference: `fishertest`

statistics: h = fishertest (x)
statistics: h = fishertest (x, param1, value1, …)
statistics: [h, pval] = fishertest (…)
statistics: [h, pval, stats] = fishertest (…)

Fisher’s exact test.

`h = fishertest (x)` performs Fisher’s exact test on a 2×2 contingency table given in matrix x. This is a test of the hypothesis that there are no non-random associations between the two 2-level categorical variables in x. `fishertest` returns the result of the tested hypothsis in h. h = 0 indicates that the null hypothesis (of no association) cannot be rejected at the 5% significance level. h = 1 indicates that the null hypothesis can be rejected at the 5% level. x must contain only non-negative integers. Use the `crostab` function to generate the contingency table from samples of two categorical variables. Fisher’s exact test is not suitable when all integers in x are very large. Use can use the Chi-square test in this case.

`[h, pval] = fishertest (x)` returns the p-value in pval. That is the probability of observing the given result, or one more extreme, by chance if the null hypothesis is true. Small values of pval cast doubt on the validity of the null hypothesis.

`[p, pval, stats] = fishertest (…)` returns the structure stats with the following fields:

| `OddsRatio` | – the odds ratio
| `ConfidenceInterval` | – the asymptotic confidence interval for the odds ratio. If any of the four entries in the contingency table x is zero, the confidence interval will not be computed, and `[-Inf Inf]` will be displayed.

`[…] = fishertest (…, name, value, …)` specifies one or more of the following name/value pairs:

| Name | Value
--- | --- | ---
| `"alpha"` | the significance level. Default is 0.05.
| `"tail"` | a string specifying the alternative hypothesis

| `"both"` | odds ratio not equal to 1, indicating association between two variables (two-tailed test, default)
| `"left"` | odds ratio greater than 1 (right-tailed test)
| `"right"` | odds ratio is less than 1 (left-tailed test)

See also: crosstab, chi2test, mcnemar_test, ztest2

Source Code: fishertest

### Example: 1

     ## A Fisher's exact test example

     x = [3, 1; 1, 3]
     [h, p, stats] = fishertest(x)

    x =

       3   1
       1   3

    h = 0
    p = 0.4857
    stats =

      scalar structure containing the fields:

        OddsRatio = 9
        ConfidenceInterval =

             0.3666   220.9270