3

I am using the Apache Commons lib to calculate the p-value with the ChiSquareTest:

I use the method chiSquareTest(double[] expected, long[] observed); But the values I get back don't make sense to me. So I tried numerous ChiSquare Online Calculators to find out what this function calculates.

An example:

  • Group 1: {25,25}
  • Group 2: {30,20}
  • (Taken from Wikipedia, German Chi Square Test article)

P- values from: http://www.quantpsy.org/chisq/chisq.htm and http://vassarstats.net/newcs.html

P = 0.3149 and 0.31490284
0.42154642 and 0.4201
(with and without Yates Correction)


Apache Commons: 0.1489146731787664

Code:

ChiSquareTest tester = new ChiSquareTest();

long[] b = {25,25};
double[] a = {30,20};

tester.chiSquareTest(a,b);

Another thing I do not understand is the need to have a long and a double array. Why not two long arrays?

Sherantha
  • 462
  • 3
  • 19
mnzl
  • 372
  • 3
  • 14

1 Answers1

2

There are two functions in the lib:

  • chiSquareTest(double[] expected, long[] observed)
  • chiSquareTest(long[][] values)

The first one (which I used in the question above) computes the goodness of a fit. But I expected the result from the second one, the test of independence.

The answer was given to me on the Apache Commons user Mailinglist, I will add a link to the archive once it is there. But it is also written in the JavaDoc.

Update: Mailinglist Archive

mnzl
  • 372
  • 3
  • 14