Class ChiSquareIndependenceTest
- java.lang.Object
-
- dev.nm.stat.test.HypothesisTest
-
- dev.nm.stat.test.distribution.pearson.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ChiSquareIndependenceTest.Type
the available distributions used for the test
-
Constructor Summary
Constructors Constructor Description ChiSquareIndependenceTest(Matrix sample)
Assess whether the two random variables in the contingency table are independent.ChiSquareIndependenceTest(Matrix sample, int nSims, ChiSquareIndependenceTest.Type type)
Assess whether the two random variables in the contingency table are independent.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAlternativeHypothesis()
Get the description of the alternative hypothesis.static Matrix
getExpectedContingencyTable(int[] rowSums, int[] colSums)
Assume the null hypothesis of independence, we compute the expected frequency of each category.String
getNullHypothesis()
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.double
pValue()
Get the p-value for the test statistics.double
statistics()
Get the test statistics.-
Methods inherited from class dev.nm.stat.test.HypothesisTest
isNullRejected, nGroups, nObs, oneSidedPvalue
-
-
-
-
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 tablenSims
- the number of simulations when EXACT distribution is usedtype
- 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
-
getNullHypothesis
public String getNullHypothesis()
Description copied from class:HypothesisTest
Get a description of the null hypothesis.- Specified by:
getNullHypothesis
in classHypothesisTest
- Returns:
- the null hypothesis description
- See Also:
- Wikipedia: Null hypothesis
-
getAlternativeHypothesis
public String getAlternativeHypothesis()
Description copied from class:HypothesisTest
Get the description of the alternative hypothesis.- Specified by:
getAlternativeHypothesis
in classHypothesisTest
- Returns:
- the alternative hypothesis description
- See Also:
- Wikipedia: Alternative hypothesis
-
statistics
public double statistics()
Description copied from class:HypothesisTest
Get the test statistics.- Specified by:
statistics
in classHypothesisTest
- Returns:
- the test statistics
- See Also:
- Wikipedia: Test statistic
-
pValue
public double pValue()
Description copied from class:HypothesisTest
Get the p-value for the test statistics.- Specified by:
pValue
in classHypothesisTest
- Returns:
- the p-value
- See Also:
- Wikipedia: P-value
-
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 totalscolSums
- 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 matrixE
- the expectation matrixYatesContinuityCorrection
-true
if to minus 0.5 for each observation in the test statistics- Returns:
- the Pearson's cumulative test statistic
-
-