// Test whether the appearance of "foo" vs. "bar" is independent of the // appearance of "baz" vs. "xxx". auto x = ["foo", "bar", "bar", "foo", "foo"]; auto y = ["xxx", "baz", "baz", "xxx", "baz"]; auto result = chiSquareObs(x, y); // This is equivalent to: auto contingency = new uint[][](2, 2); foreach(i; 0..x.length) { immutable index1 = (x[i] == "foo"); immutable index2 = (y[i] == "xxx"); contingency[index1][index2]++; } auto result2 = chiSquareContingency(contingency);
Given two vectors of observations of jointly distributed variables x, y, tests the null hypothesis that values in x are independent of the corresponding values in y. This is done using Pearson's Chi-Square Test. For a similar test that assumes the data has already been tabulated into a contingency table, see chiSquareContingency.
x and y must both be input ranges. If they are not the same length, a DstatsArgumentException is thrown.