Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/1733#discussion_r15981438
--- Diff: mllib/src/main/scala/org/apache/spark/mllib/stat/Statistics.scala
---
@@ -89,4 +91,64 @@ object Statistics {
*/
@Experimental
def corr(x: RDD[Double], y: RDD[Double], method: String): Double =
Correlations.corr(x, y, method)
+
+ /**
+ * :: Experimental ::
+ * Conduct Pearson's chi-squared goodness of fit test of the observed
data against the
+ * expected distribution.
+ *
+ * Note: the two input Vectors need to have the same size.
+ * `observed` cannot contain negative values.
+ * `expected` cannot contain nonpositive values.
+ *
+ * @param observed Vector containing the observed categorical
counts/relative frequencies.
+ * @param expected Vector containing the expected categorical
counts/relative frequencies.
+ * `expected` is rescaled if the `expected` sum differs
from the `observed` sum.
+ * @return ChiSquaredTest object containing the test statistic, degrees
of freedom, p-value,
+ * the method used, and the null hypothesis.
+ */
+ @Experimental
+ def chiSqTest(observed: Vector,
+ expected: Vector): ChiSquaredTestResult =
ChiSquaredTest.chiSquared(observed, expected)
+
+ /**
+ * :: Experimental ::
+ * Conduct Pearson's chi-squared goodness of fit test of the observed
data against the uniform
+ * distribution, with each category having an expected frequency of `1 /
observed.size`.
+ *
+ * Note: `observed` cannot contain negative values.
+ *
+ * @param observed Vector containing the observed categorical
counts/relative frequencies.
+ * @return ChiSquaredTest object containing the test statistic, degrees
of freedom, p-value,
+ * the method used, and the null hypothesis.
+ */
+ @Experimental
+ def chiSqTest(observed: Vector): ChiSquaredTestResult =
ChiSquaredTest.chiSquared(observed)
+
+ /**
+ * :: Experimental ::
+ * Conduct Pearson's independence test on the input contingency matrix,
which cannot contain
+ * negative entries or columns or rows that sum up to 0.
+ *
+ * @param counts The contingency matrix.
+ * @return ChiSquaredTest object containing the test statistic, degrees
of freedom, p-value,
+ * the method used, and the null hypothesis.
+ */
+ @Experimental
+ def chiSqTest(counts: Matrix): ChiSquaredTestResult =
ChiSquaredTest.chiSquaredMatrix(counts)
--- End diff --
`counts` -> `observed`? This table could also be probabilities.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]