NMath Stats User's Guide

TOC | Previous | Next | Index

5.8 Fisher's Exact Test (.NET, C#, CSharp, VB, Visual Basic, F#)

StatsFunctions provides the FisherEactTest() method for performing a Fisher's Exact Test for a specified 2 x 2 contingency table. Fisher's Exact Test is a useful alternative to the chi-square test in cases where sample sizes are small.

Fisher's Exact Test is so-called because the significance of the deviation from a null hypothesis can be calculated exactly, rather than relying on an approximation. The usual rule of thumb for deciding whether the chi-squared approximation is good enough is whether the expected values in all cells of the contingency table is greater than or equal to 5.

You can perform a Fisher's Exact Test by providing the cell values directly, plus an HypothesisType specifying the form of the alternative hypothesis:

Code Example – C# Fisher's exact test

int a = 12, b = 17, c = 4, d = 25;
double pvalue = StatsFunctions.FishersExactTest( a, b, c, d, 
  HypothesisType.TwoSided );

Values a, b, c and d are cell counts for contingency table:

a  b
c  d

If no hypothesis type is specified, FisherExactTest() returns the lesser of the right and left tail p-value.

Overloads are also provided for data in an int[,] array or DataFrame containg two DFIntColumn.


Top

Top