[
https://issues.apache.org/jira/browse/SPARK-6312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14361650#comment-14361650
]
Chunnan Yao commented on SPARK-6312:
------------------------------------
According to
https://sites.google.com/a/lakeheadu.ca/bweaver/Home/statistics/notes/chisqr_assumptions,
the following to conditions should be met to use Chi-Square test in
contingency table:
1. Each observation is independent of all the others (i.e., one observation per
subject);
2. "No more than 20% of the expected counts are less than 5 and all individual
expected counts are 1 or greater" (Yates, Moore & McCabe, 1999, p. 734).
So I suggest add judgement codes in def chiSquaredMatrix(counts: Matrix,
methodName:String = PEARSON.name) as follows:
def chiSquaredMatrix(counts: Matrix, methodName:String = PEARSON.name):
ChiSqTestResult = {
.......
var check = 0 //variable to count the number of small entries
while (j < colMajorArr.size) {
.......
val expected = colSum * rowSum / total
if (expected < 5) {
check += 1
}
if (expected < 1) {
logWarning(s"All individual expected counts shoud be 1 or greater")
}
statistic += method.chiSqFunc(colMajorArr(j), expected)
j += 1
}
if (check.toDouble/(numCols * numRows)> 0.2) {
logWarning(s"Chi-squared independence test may not be accurate due to low
expected frequencies.")
}
........
}
> ChiSqTest should check for too few counts
> -----------------------------------------
>
> Key: SPARK-6312
> URL: https://issues.apache.org/jira/browse/SPARK-6312
> Project: Spark
> Issue Type: Improvement
> Components: MLlib
> Affects Versions: 1.2.0
> Reporter: Joseph K. Bradley
>
> ChiSqTest assumes that elements of the contingency matrix are large enough
> (have enough counts) s.t. the central limit theorem kicks in. It would be
> reasonable to do one or more of the following:
> * Add a note in the docs about making sure there are a reasonable number of
> instances being used (or counts in the contingency table entries, to be more
> precise and account for skewed category distributions).
> * Add a check in the code which could:
> ** Log a warning message
> ** Alter the p-value to make sure it indicates the test result is
> insignificant
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]