Click or drag to resize
Accord.NET (logo)

FisherExactTest Class

Fisher's exact test for contingency tables.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.TestingHypothesisTestHypergeometricDistribution
    Accord.Statistics.TestingFisherExactTest

Namespace:  Accord.Statistics.Testing
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class FisherExactTest : HypothesisTest<HypergeometricDistribution>
Request Example View Source

The FisherExactTest type exposes the following members.

Constructors
  NameDescription
Public methodFisherExactTest
Constructs a new Fisher's exact test.
Top
Properties
  NameDescription
Public propertyCriticalValue
Gets the critical value for the current significance level.
(Inherited from HypothesisTestTDistribution.)
Public propertyHypothesis
Gets the alternative hypothesis under test. If the test is Significant, the null hypothesis can be rejected in favor of this alternative hypothesis.
Public propertyPValue
Gets the P-value associated with this test.
(Inherited from HypothesisTestTDistribution.)
Public propertySignificant
Gets whether the null hypothesis should be rejected.
(Inherited from HypothesisTestTDistribution.)
Public propertySize
Gets the significance level for the test. Default value is 0.05 (5%).
(Inherited from HypothesisTestTDistribution.)
Public propertyStatistic
Gets the test statistic.
(Inherited from HypothesisTestTDistribution.)
Public propertyStatisticDistribution
Gets the distribution associated with the test statistic.
(Inherited from HypothesisTestTDistribution.)
Public propertyTail
Gets the test type.
(Inherited from HypothesisTestTDistribution.)
Top
Methods
  NameDescription
Protected methodCompute
Computes the Fisher's exact test.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodOnSizeChanged
Called whenever the test significance level changes.
(Inherited from HypothesisTestTDistribution.)
Public methodPValueToStatistic
Converts a given p-value to a test statistic.
(Overrides HypothesisTestTDistributionPValueToStatistic(Double).)
Public methodStatisticToPValue
Converts a given test statistic to a p-value.
(Overrides HypothesisTestTDistributionStatisticToPValue(Double).)
Public methodToString
Converts the numeric P-Value of this test to its equivalent string representation.
(Inherited from HypothesisTestTDistribution.)
Public methodToString(String, IFormatProvider)
Converts the numeric P-Value of this test to its equivalent string representation.
(Inherited from HypothesisTestTDistribution.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

This test statistic distribution is the Hypergeometric.

Examples
// Example from https://en.wikipedia.org/wiki/Fisher%27s_exact_test

// This example comes directly from the Wikipedia page referenced above. In this example, 
// a sample of teenagers might be divided into male and female on the one hand, and those
// that are and are not currently studying for a statistics exam on the other. We hypothesize,
// for example, that the proportion of studying individuals is higher among the women than
// among the men, and we want to test whether any difference of proportions that we observe
// is significant. The data might look like this:

var matrix = new ConfusionMatrix(new int[,] 
{
    /*                    Men     Women  */
    /* Studying    */  {   1,       9    },
    /* Not-studying*/  {  11,       3    },
});

// Let's check that the row totals and column
// totals match the ones reported in Wikipedia:
int[] rowTotals = matrix.RowTotals;    // should be 10, 14
int[] colTotals = matrix.ColumnTotals; // should be 12, 12
int total = matrix.NumberOfSamples;    // should be 24

// The question we ask about these data is: knowing that 10 of these 24 teenagers are studiers,
// and that 12 of the 24 are female, and assuming the null hypothesis that men and women are 
// equally likely to study, what is the probability that these 10 studiers would be so unevenly
// distributed between the women and the men? If we were to choose 10 of the teenagers at random,
// what is the probability that 9 or more of them would be among the 12 women, and only 1 or fewer
// from among the 12 men?

var fet = new FisherExactTest(matrix, alternate: OneSampleHypothesis.ValueIsDifferentFromHypothesis);
double p = fet.PValue; // should be approximately 0.0027594561852200832
bool significant = fet.Significant; // should be true

// The same result can be verified in R using:
//  fisher.test(matrix(c(1, 9, 11, 3), 2,2))
/*
    Fisher's Exact Test for Count Data

    data: matrix(c(1, 9, 11, 3), 2, 2)
    p - value = 0.002759
    alternative hypothesis: true odds ratio is not equal to 1
    95 percent confidence interval:
                0.0006438284 0.4258840381
    sample estimates:
    odds ratio
    0.03723312*/
See Also