You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Michael Menzel <Mi...@bioinfsys.uni-giessen.de> on 2015/12/18 10:34:03 UTC

Weird results from ChiSquareTest

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

I have a problem with the ChiSquareTest Method supplied by Apache
Commons. I already postet it on StackOverflow, so I will just copy
everything from there
(https://stackoverflow.com/questions/34333243/apachecommons-weird-results-from-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?



Maybe one of you can help me understand the result.

Thanks in advance.

Michael
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJWc9MIAAoJEL6dFkylAyuLeY4QAInDSvdI0pU+9QC9xxKNpvWb
OK1s32zcj+B8MkNCQQ+IrFg8nyJiaT9EMyTBC4xKDdB2fb8rVZyV6cwAjh1TOcNf
vo+wqOTtMcPW92eXEHxaJkrknB3dbl/Jc8NQX3afF+rmEnf9I1qfQUfhwoyOm79G
WjLqgm1PGi7SY4BwjBbHt8sUxPowLUHj6ZbSpRkVDT64rb1PSeo9tet/Mnzwk1Vo
wML/IOayxQlLMjYgbXDeEmP3nQhx3qY1+zc6TmvDHI5fMEQRAz1hCvOO1MnwlNUU
+hEoJrOmkz3nXyenq4fw9pqKQNZOUUwOghptkK/SQqki+qyeIlF2dTZHaGycEckM
Lcot/twki2xxvF8Z0T4MLBSBJKBQ20MtvQrUBbgIa/msg9JeFVUYYyNbFVHm666/
xBJOo1pyeRGYl+q0/nMvbMUTHeY7oNB4v5JGS/8aQjWooSMdDp0INXcdEOiiw5Oo
+7i5kHxZBvw1AwJ7cNmGFlRIOCV2W97Pv205+ziId70tNLYGvQH+OGRej2sZt911
CP5c7ZXRacHR5DeBMzxIIVOniulCEMHQxwXX0J86lxL3rVzNcwi6J+A2VLckewkC
20WH6o2ofPbAbTRZvJT91mbfnDhKIdosGhYDjlpY42dAnE/jAnA7MmuTem3iQzom
FNmS9pIsGYyByDsBM9Xj
=iM1r
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Weird results from ChiSquareTest

Posted by Thomas Neidhart <th...@gmail.com>.
Hi Michael,

there are basically two different ways to use the ChiSquare test:

 * compute the chi-square test of independence (use the
chiSquareTest(long[][]) method)
 * compute the chi-square goodness of fit test (use the
chiSquareTest(double[], long[]) method)

In your example, you computed the goodness of fit test, but were expecting
the result of the test of independence.

The first provided link makes the distinction as well and you can compute
both values, getting the same result as commons-math.

Thomas


On Fri, Dec 18, 2015 at 10:34 AM, Michael Menzel <
Michael.Menzel@bioinfsys.uni-giessen.de> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Hi,
>
> I have a problem with the ChiSquareTest Method supplied by Apache
> Commons. I already postet it on StackOverflow, so I will just copy
> everything from there
> (
> https://stackoverflow.com/questions/34333243/apachecommons-weird-results-from-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?
>
>
>
> Maybe one of you can help me understand the result.
>
> Thanks in advance.
>
> Michael
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
>
> iQIcBAEBCAAGBQJWc9MIAAoJEL6dFkylAyuLeY4QAInDSvdI0pU+9QC9xxKNpvWb
> OK1s32zcj+B8MkNCQQ+IrFg8nyJiaT9EMyTBC4xKDdB2fb8rVZyV6cwAjh1TOcNf
> vo+wqOTtMcPW92eXEHxaJkrknB3dbl/Jc8NQX3afF+rmEnf9I1qfQUfhwoyOm79G
> WjLqgm1PGi7SY4BwjBbHt8sUxPowLUHj6ZbSpRkVDT64rb1PSeo9tet/Mnzwk1Vo
> wML/IOayxQlLMjYgbXDeEmP3nQhx3qY1+zc6TmvDHI5fMEQRAz1hCvOO1MnwlNUU
> +hEoJrOmkz3nXyenq4fw9pqKQNZOUUwOghptkK/SQqki+qyeIlF2dTZHaGycEckM
> Lcot/twki2xxvF8Z0T4MLBSBJKBQ20MtvQrUBbgIa/msg9JeFVUYYyNbFVHm666/
> xBJOo1pyeRGYl+q0/nMvbMUTHeY7oNB4v5JGS/8aQjWooSMdDp0INXcdEOiiw5Oo
> +7i5kHxZBvw1AwJ7cNmGFlRIOCV2W97Pv205+ziId70tNLYGvQH+OGRej2sZt911
> CP5c7ZXRacHR5DeBMzxIIVOniulCEMHQxwXX0J86lxL3rVzNcwi6J+A2VLckewkC
> 20WH6o2ofPbAbTRZvJT91mbfnDhKIdosGhYDjlpY42dAnE/jAnA7MmuTem3iQzom
> FNmS9pIsGYyByDsBM9Xj
> =iM1r
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>