Record Class ChiSqTest

java.lang.Object
java.lang.Record
smile.stat.hypothesis.ChiSqTest
Record Components:
method - the type of test.
chisq - the chi-square statistic.
df - the degree of freedom.
pvalue - the p-value.
CramerV - Cramer's V measure. Cramér's V is a measure of association between two nominal variables, giving a value between 0 and 1 (inclusive). In the case of a 2 × 2 contingency table, Cramér's V is equal to the Phi coefficient.

public record ChiSqTest(String method, double chisq, double df, double pvalue, double CramerV) extends Record
Pearson's chi-square test, also known as the chi-square goodness-of-fit test or chi-square test for independence. Note that the chi-square distribution is only approximately valid for large sample size. If a significant fraction of bins has small numbers of counts (say, < 10), then the statistic is not well approximated by a chi-square probability function.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ChiSqTest(String method, double chisq, double df, double pvalue)
    Constructor.
    ChiSqTest(String method, double chisq, double df, double pvalue, double CramerV)
    Creates an instance of a ChiSqTest record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the value of the chisq record component.
    double
    Returns the value of the CramerV record component.
    double
    df()
    Returns the value of the df record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the method record component.
    double
    Returns the value of the pvalue record component.
    static ChiSqTest
    test(int[][] table)
    Independence test on a two-dimensional contingency table.
    static ChiSqTest
    test(int[] bins, double[] prob)
    One-sample Pearson's chi-square test.
    static ChiSqTest
    test(int[] bins, double[] prob, int constraints)
    One-sample Pearson's chi-square test.
    static ChiSqTest
    test(int[] bins1, int[] bins2)
    Two-sample Pearson's chi-square test.
    static ChiSqTest
    test(int[] bins1, int[] bins2, int constraints)
    Two-sample Pearson's chi-square test.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • ChiSqTest

      public ChiSqTest(String method, double chisq, double df, double pvalue)
      Constructor.
      Parameters:
      method - the type of test.
      chisq - the chi-square statistic.
      df - the degree of freedom.
      pvalue - the p-value.
    • ChiSqTest

      public ChiSqTest(String method, double chisq, double df, double pvalue, double CramerV)
      Creates an instance of a ChiSqTest record class.
      Parameters:
      method - the value for the method record component
      chisq - the value for the chisq record component
      df - the value for the df record component
      pvalue - the value for the pvalue record component
      CramerV - the value for the CramerV record component
  • Method Details

    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • test

      public static ChiSqTest test(int[] bins, double[] prob)
      One-sample Pearson's chi-square test. Given the array bins containing the observed numbers of events, and an array prob containing the expected probabilities of events, and given one constraint, a small value of p-value indicates a significant difference between the distributions.
      Parameters:
      bins - the observed number of events.
      prob - the expected probabilities of events.
      Returns:
      the test results.
    • test

      public static ChiSqTest test(int[] bins, double[] prob, int constraints)
      One-sample Pearson's chi-square test. Given the array bins containing the observed numbers of events, and an array prob containing the expected probabilities of events, and given the number of constraints (normally one), a small value of p-value indicates a significant difference between the distributions.
      Parameters:
      bins - the observed number of events.
      prob - the expected probabilities of events.
      constraints - the constraints on the degree of freedom.
      Returns:
      the test results.
    • test

      public static ChiSqTest test(int[] bins1, int[] bins2)
      Two-sample Pearson's chi-square test. Given the arrays bins1 and bins2, containing two sets of binned data, and given one constraint, a small value of p-value indicates a significant difference between the distributions.
      Parameters:
      bins1 - the observed number of events in first sample.
      bins2 - the observed number of events in second sample.
      Returns:
      the test results.
    • test

      public static ChiSqTest test(int[] bins1, int[] bins2, int constraints)
      Two-sample Pearson's chi-square test. Given the arrays bins1 and bins2, containing two sets of binned data, and given the number of constraints (normally one), a small value of p-value indicates a significant difference between the distributions.
      Parameters:
      bins1 - the observed number of events in first sample.
      bins2 - the observed number of events in second sample.
      constraints - the constraints on the degree of freedom.
      Returns:
      the test results.
    • test

      public static ChiSqTest test(int[][] table)
      Independence test on a two-dimensional contingency table. The rows of contingency table are the values of one nominal variable, the columns are the values of the other nominal variable. The entries are the number of observed events for each combination of row and column.

      Continuity correction will be applied when computing the test statistic for 2x2 tables: one half is subtracted from all |O-E| differences. The correlation coefficient is calculated as Cramer's V.

      Parameters:
      table - the contingency table.
      Returns:
      the test results.
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • method

      public String method()
      Returns the value of the method record component.
      Returns:
      the value of the method record component
    • chisq

      public double chisq()
      Returns the value of the chisq record component.
      Returns:
      the value of the chisq record component
    • df

      public double df()
      Returns the value of the df record component.
      Returns:
      the value of the df record component
    • pvalue

      public double pvalue()
      Returns the value of the pvalue record component.
      Returns:
      the value of the pvalue record component
    • CramerV

      public double CramerV()
      Returns the value of the CramerV record component.
      Returns:
      the value of the CramerV record component