Click or drag to resize
Accord.NET (logo)

ChiSquareTest Class

Two-Sample (Goodness-of-fit) Chi-Square Test (Upper Tail)
Inheritance Hierarchy
SystemObject
  Accord.Statistics.TestingHypothesisTestChiSquareDistribution
    Accord.Statistics.TestingChiSquareTest
      More...

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

The ChiSquareTest type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCriticalValue
Gets the critical value for the current significance level.
(Inherited from HypothesisTestTDistribution.)
Public propertyDegreesOfFreedom
Gets the degrees of freedom for the Chi-Square distribution.
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 Chi-Square 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

A chi-square test (also chi-squared or χ² test) is any statistical hypothesis test in which the sampling distribution of the test statistic is a chi-square distribution when the null hypothesis is true, or any in which this is asymptotically true, meaning that the sampling distribution (if the null hypothesis is true) can be made to approximate a chi-square distribution as closely as desired by making the sample size large enough.

The chi-square test is used whenever one would like to test whether the actual data differs from a random distribution.

References:

Examples

The following example has been based on the example section of the Pearson's chi-squared test article on Wikipedia.

// Suppose we would like to test the hypothesis that a random sample of 
// 100 people has been drawn from a population in which men and women are
// equal in frequency. 

// Under this hypothesis, the observed number of men and women would be 
// compared to the theoretical frequencies of 50 men and 50 women. So,
// after drawing our sample, we found out that there were 44 men and 56
// women in the sample:

//                     man  woman
double[] observed = {  44,   56  };
double[] expected = {  50,   50  };

// If the null hypothesis is true (i.e., men and women are chosen with 
// equal probability), the test statistic will be drawn from a chi-squared
// distribution with one degree of freedom. If the male frequency is known, 
// then the female frequency is determined.
// 
int degreesOfFreedom = 1;

// So now we have:
// 
var chi = new ChiSquareTest(expected, observed, degreesOfFreedom);


// The chi-squared distribution for 1 degree of freedom shows that the 
// probability of observing this difference (or a more extreme difference 
// than this) if men and women are equally numerous in the population is 
// approximately 0.23. 

double pvalue = chi.PValue; // 0.23

// This probability is higher than conventional criteria for statistical
// significance (0.001 or 0.05), so normally we would not reject the null
// hypothesis that the number of men in the population is the same as the
// number of women.

bool significant = chi.Significant; // false
See Also
Inheritance Hierarchy