Class ChiSquareIndependenceTest


  • public class ChiSquareIndependenceTest
    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
    • Constructor Detail

      • ChiSquareIndependenceTest

        public ChiSquareIndependenceTest​(Matrix sample,
                                         int nSims,
                                         ChiSquareIndependenceTest.Type type)
        Assess whether the two random variables in the contingency table are independent.
        Parameters:
        sample - a contingency table
        nSims - the number of simulations when EXACT distribution is used
        type - the type of distribution
      • ChiSquareIndependenceTest

        public ChiSquareIndependenceTest​(Matrix sample)
        Assess whether the two random variables in the contingency table are independent.
        Parameters:
        sample - a contingency table
    • Method Detail

      • getExpectedContingencyTable

        public static Matrix getExpectedContingencyTable​(int[] rowSums,
                                                         int[] colSums)
        Assume the null hypothesis of independence, we compute the expected frequency of each category.
        Parameters:
        rowSums - the row totals
        colSums - the column totals
        Returns:
        a table of expected frequencies 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 if to minus 0.5 for each observation in the test statistics
        Returns:
        the Pearson's cumulative test statistic