SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.stats.test.distribution.pearson
Class ChiSquare4Independence

java.lang.Object
  extended by com.numericalmethod.suanshu.stats.test.HypothesisTest
      extended by com.numericalmethod.suanshu.stats.test.distribution.pearson.ChiSquare4Independence

public class ChiSquare4Independence
extends HypothesisTest

Pearson's chi-square test of independence assesses whether paired observations on two variables, expressed in a contingency table, are independent of each other.

See Also:
Wikipedia: Pearson's chi-square test

Nested Class Summary
static class ChiSquare4Independence.Type
          the distribution used for the test
 
Field Summary
 
Fields inherited from class com.numericalmethod.suanshu.stats.test.HypothesisTest
k, N, pValue, testStatistics
 
Constructor Summary
ChiSquare4Independence(Matrix sample)
          Assess whether the two random variable in the contingency table is independent.
ChiSquare4Independence(Matrix sample, int nSim, ChiSquare4Independence.Type type)
          Assess whether the two random variable in the contingency table is independent.
 
Method Summary
 java.lang.String alternativeHypothesis()
          Get a description of the alternative hypothesis.
static Matrix expectedContingencyTable(int[] rowSums, int[] colSums)
          Assume the null hypothesis of independence, we compute the expected frequency of each category.
 java.lang.String nullHypothesis()
          Get a description of the null hypothesis.
static double pearsonStat(Matrix O, Matrix E, boolean YatesContinuityCorrection)
          Compute the Pearson's cumulative test statistic, which asymptotically approaches a χ2 distribution.
 
Methods inherited from class com.numericalmethod.suanshu.stats.test.HypothesisTest
oneSidedPvalue, pValue, rejectNull, testStatistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChiSquare4Independence

public ChiSquare4Independence(Matrix sample,
                              int nSim,
                              ChiSquare4Independence.Type type)
Assess whether the two random variable in the contingency table is independent.

Parameters:
sample - a contingency table
nSim - number of simulation when EXACT distribution is used
type - the type of distribution

ChiSquare4Independence

public ChiSquare4Independence(Matrix sample)
Assess whether the two random variable in the contingency table is independent.

Parameters:
sample - a contingency table
Method Detail

nullHypothesis

public java.lang.String nullHypothesis()
Description copied from class: HypothesisTest
Get a description of the null hypothesis.

Specified by:
nullHypothesis in class HypothesisTest
Returns:
the null hypothesis description
See Also:
Wikipedia: Null hypothesis

alternativeHypothesis

public java.lang.String alternativeHypothesis()
Description copied from class: HypothesisTest
Get a description of the alternative hypothesis.

Specified by:
alternativeHypothesis in class HypothesisTest
Returns:
the alternative hypothesis description
See Also:
Wikipedia: Alternative hypothesis

expectedContingencyTable

public static Matrix expectedContingencyTable(int[] rowSums,
                                              int[] colSums)
Assume the null hypothesis of independence, we compute the expected frequency of each category.

Parameters:
rowSums - row totals
colSums - column totals
Returns:
a table of expected frequency under the null hypothesis

pearsonStat

public static double pearsonStat(Matrix O,
                                 Matrix E,
                                 boolean YatesContinuityCorrection)
Compute the Pearson's cumulative test statistic, which asymptotically approaches a χ2 distribution.

Parameters:
O - the observation matrix
E - the expectation matrix
YatesContinuityCorrection - true iff to minus 0.5 for each observation in the test statistics
Returns:
the Pearson's cumulative test statistic

SuanShu, a Java numerical and statistical library

Copyright © 2011 Numerical Method Inc. Ltd. All Rights Reserved.