Search code examples
androidstatisticsapache-commonschi-squaredapache-commons-math

android java what is a long[ ][ ]?


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

Solution

  • 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.