0

I need to do the chiSquaredTest. I'm using the Apache Commons Math library but not sure what is a long[][] what the difference to a long[] ? Here is the method description :

  public double chiSquareTest(long[][] counts)
                 throws NullArgumentException,
                        DimensionMismatchException,
                        NotPositiveException,
                        MaxCountExceededException

Returns the observed significance level, or p-value, associated with a chi-square test of independence based on the input counts array, viewed as a two-way table.

The rows of the 2-way table are count[ 0 ], ... , count[count.length - 1]

Preconditions:

  • List item All counts must be ≥ 0.
  • The count array must be rectangular (i.e. all count[ i ] subarrays must have the same length).
  • The 2-way table represented by counts must have at least 2 columns and at least 2 rows.
  • If any of the preconditions are not met, an IllegalArgumentException is thrown.

Parameters:

  • counts - array representation of 2-way table

Returns:

  • p-value
Iamat8
  • 3,888
  • 9
  • 25
  • 35
Alivajorg
  • 19
  • 7

3 Answers3

0

long[] - it is one dimensional array.

long[] array = new long[4];

/* result of that array
{0, 0, 0, 0}
*/

long[][] - it is array of arrays / two dimensional array.

long[][] array2 = new long[4][];
array2[0] = new long[1];
array2[1] = new long[2];
array2[2] = new long[4];
array2[3] = new long[3];

/* result of that array
{
    {0},
    {0, 0},
    {0, 0, 0, 0},
    {0, 0, 0},
}
*/

or it can be like that:

long[][] array = new long[4][4];

/* result of that array
{
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
    {0, 0, 0, 0},
}
*/

For more examples go to this link.

Community
  • 1
  • 1
Artur Szymański
  • 1,639
  • 1
  • 19
  • 22
  • Hello! ok i got it. so if i want to add a value to thw first row would be – Alivajorg Jun 28 '16 at 21:24
  • Hello! ok i got it. so if i want to add a values to the first row would be array2[0][0] = (long) 3.2; ---first,first array2[1][0] = 8; ---first,second – Alivajorg Jun 28 '16 at 21:51
0

Keep in mind that the ChiSquareTest class in Apache Commons Math provides two different measures:

  1. Goodness of fit test: use chiSquareTest(double[] expected, double[] observed) - tests if your observed data comes from a claimed distribution.

  2. Test of independence: use chiSquareTest(double[][] counts) - tests if two different variables are associated with each other.

These two tests are slightly different and the results will be different.

Edit: as the question is actually related to the chidst function of Excel and how to calculate the same result in Java, the solution with Apache Commons Math3 would be as follows:

ChiSquaredDistribution dist = new ChiSquaredDistribution(df);
double chidst = 1 - dist.cumulativeProbability(chi);
T. Neidhart
  • 6,060
  • 2
  • 15
  • 38
  • Yeah! i need the Test of independence usually i do it in excel and whit chidst function i need two values chidst(chi,df), still can't figurate out how to do it in java using there libraries and the two dimensional array do you have an idea? – Alivajorg Jun 29 '16 at 00:48
  • The chidst function in excel computes the right-tailed probability of the ChiSquare distribution. With commons-math you can get the same like this: ChiSquaredDistribution dist = new ChiSquaredDistribution(df); double chidst = 1 - dist.cumulativeProbability(chi); – T. Neidhart Jun 30 '16 at 10:04
  • I suggest that you update your question to reflect what you are really looking for. – T. Neidhart Jun 30 '16 at 10:09
0

Thanks! yes i got confuse. I found this post Why does tail probability in apache math drop to zero after 1E-16? is actually better to use regularizedGammaQ(); http://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/index.html

Community
  • 1
  • 1
Alivajorg
  • 19
  • 7