chiSquareObs

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.

chiSquareObs
(
T
U
)
(
T x
,
U y
)
if (
isInputRange!T &&
isInputRange!U
)

Examples

1 // Test whether the appearance of "foo" vs. "bar" is independent of the
2 // appearance of "baz" vs. "xxx".
3 auto x = ["foo", "bar", "bar", "foo", "foo"];
4 auto y = ["xxx", "baz", "baz", "xxx", "baz"];
5 auto result = chiSquareObs(x, y);
6 
7 // This is equivalent to:
8 auto contingency = new uint[][](2, 2);
9 foreach(i; 0..x.length) {
10     immutable index1 = (x[i] == "foo");
11     immutable index2 = (y[i] == "xxx");
12     contingency[index1][index2]++;
13 }
14 
15 auto result2 = chiSquareContingency(contingency);

Meta