FisherExactTest Class |
Namespace: Accord.Statistics.Testing
[SerializableAttribute] public class FisherExactTest : HypothesisTest<HypergeometricDistribution>
The FisherExactTest type exposes the following members.
Name | Description | |
---|---|---|
FisherExactTest |
Constructs a new Fisher's exact test.
|
Name | Description | |
---|---|---|
CriticalValue |
Gets the critical value for the current significance level.
(Inherited from HypothesisTestTDistribution.) | |
Hypothesis |
Gets the alternative hypothesis under test. If the test is
Significant, the null hypothesis
can be rejected in favor of this alternative hypothesis.
| |
PValue |
Gets the P-value associated with this test.
(Inherited from HypothesisTestTDistribution.) | |
Significant |
Gets whether the null hypothesis should be rejected.
(Inherited from HypothesisTestTDistribution.) | |
Size |
Gets the significance level for the
test. Default value is 0.05 (5%).
(Inherited from HypothesisTestTDistribution.) | |
Statistic |
Gets the test statistic.
(Inherited from HypothesisTestTDistribution.) | |
StatisticDistribution |
Gets the distribution associated
with the test statistic.
(Inherited from HypothesisTestTDistribution.) | |
Tail |
Gets the test type.
(Inherited from HypothesisTestTDistribution.) |
Name | Description | |
---|---|---|
Compute |
Computes the Fisher's exact test.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OnSizeChanged |
Called whenever the test significance level changes.
(Inherited from HypothesisTestTDistribution.) | |
PValueToStatistic |
Converts a given p-value to a test statistic.
(Overrides HypothesisTestTDistributionPValueToStatistic(Double).) | |
StatisticToPValue |
Converts a given test statistic to a p-value.
(Overrides HypothesisTestTDistributionStatisticToPValue(Double).) | |
ToString |
Converts the numeric P-Value of this test to its equivalent string representation.
(Inherited from HypothesisTestTDistribution.) | |
ToString(String, IFormatProvider) |
Converts the numeric P-Value of this test to its equivalent string representation.
(Inherited from HypothesisTestTDistribution.) |
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(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.) | |
ToT | 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.) |
This test statistic distribution is the Hypergeometric.
// 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*/