Package smile.stat.hypothesis
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
-
Method Summary
Modifier and TypeMethodDescriptiondouble
chisq()
Returns the value of thechisq
record component.double
CramerV()
Returns the value of theCramerV
record component.double
df()
Returns the value of thedf
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.method()
Returns the value of themethod
record component.double
pvalue()
Returns the value of thepvalue
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.toString()
Returns a string representation of this record class.
-
Constructor Details
-
ChiSqTest
Constructor.- Parameters:
method
- the type of test.chisq
- the chi-square statistic.df
- the degree of freedom.pvalue
- the p-value.
-
ChiSqTest
Creates an instance of aChiSqTest
record class.
-
-
Method Details
-
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. -
test
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
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
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
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
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. -
equals
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 withObjects::equals(Object,Object)
; primitive components are compared with '=='. -
method
Returns the value of themethod
record component.- Returns:
- the value of the
method
record component
-
chisq
public double chisq()Returns the value of thechisq
record component.- Returns:
- the value of the
chisq
record component
-
df
public double df()Returns the value of thedf
record component.- Returns:
- the value of the
df
record component
-
pvalue
public double pvalue()Returns the value of thepvalue
record component.- Returns:
- the value of the
pvalue
record component
-
CramerV
public double CramerV()Returns the value of theCramerV
record component.- Returns:
- the value of the
CramerV
record component
-