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 classChiSquareIndependenceTest.Typethe 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 StringgetAlternativeHypothesis()Get the description of the alternative hypothesis.static MatrixgetExpectedContingencyTable(int[] rowSums, int[] colSums)Assume the null hypothesis of independence, we compute the expected frequency of each category.StringgetNullHypothesis()Get a description of the null hypothesis.static doublepearsonStat(Matrix O, Matrix E, boolean YatesContinuityCorrection)Compute the Pearson's cumulative test statistic, which asymptotically approaches a χ2 distribution.doublepValue()Get the p-value for the test statistics.doublestatistics()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:HypothesisTestGet a description of the null hypothesis.- Specified by:
getNullHypothesisin classHypothesisTest- Returns:
- the null hypothesis description
- See Also:
- Wikipedia: Null hypothesis
-
getAlternativeHypothesis
public String getAlternativeHypothesis()
Description copied from class:HypothesisTestGet the description of the alternative hypothesis.- Specified by:
getAlternativeHypothesisin classHypothesisTest- Returns:
- the alternative hypothesis description
- See Also:
- Wikipedia: Alternative hypothesis
-
statistics
public double statistics()
Description copied from class:HypothesisTestGet the test statistics.- Specified by:
statisticsin classHypothesisTest- Returns:
- the test statistics
- See Also:
- Wikipedia: Test statistic
-
pValue
public double pValue()
Description copied from class:HypothesisTestGet the p-value for the test statistics.- Specified by:
pValuein 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-trueif to minus 0.5 for each observation in the test statistics- Returns:
- the Pearson's cumulative test statistic
-
-