public static AssociativeArray getScore(DataTable2D dataTable) {
        /*
        //avoid calling it for performance purposes
        if(dataTable.isValid()==false) {
            throw new IllegalArgumentException("The provided Table does not have a rectangular format.");
        }
        */
        //Estimate marginal scores and sum
        Map<Object, Double> XdotJ = new HashMap<>();
        Map<Object, Double> XIdot = new HashMap<>();
        double Xdotdot=0.0;
        
        for(Map.Entry<Object, AssociativeArray> entry1 : dataTable.entrySet()) {
            Object i = entry1.getKey();
            AssociativeArray row = entry1.getValue();
            
            for(Map.Entry<Object, Object> entry2 : row.entrySet()) {
                Object j = entry2.getKey();
                Object value = entry2.getValue();
                
                double v = TypeInference.toDouble(value);
                
                //Summing the columns
                if(XdotJ.containsKey(j)==false) {
                    XdotJ.put(j, v);
                }
                else {
                    XdotJ.put(j, XdotJ.get(j) + v);
                }

                //Summing the rows
                if(XIdot.containsKey(i)==false) {
                    XIdot.put(i, v);
                }
                else {
                    XIdot.put(i, XIdot.get(i) + v);
                }
                
                Xdotdot+=v;
            }
        }

        int k=XdotJ.size();
        int n=XIdot.size();

        //Calculating Chisquare score
        double ChisquareScore=0.0;        
        if(k==2 && n==2) { //if 2x2 then perform the Yates correction. Make this check outside the loops to make it faster
            for(Map.Entry<Object, AssociativeArray> entry1 : dataTable.entrySet()) {
                Object i = entry1.getKey();
                AssociativeArray row = entry1.getValue();

                for(Map.Entry<Object, Object> entry2 : row.entrySet()) {
                    Object j = entry2.getKey();
                    Object value = entry2.getValue();

                    double v = TypeInference.toDouble(value);

                    //expected value under null hypothesis
                    double eij = XIdot.get(i)*XdotJ.get(j)/Xdotdot;
                    if(eij==0) {
                        continue;
                    }
                    ChisquareScore+=Math.pow((Math.abs(v-eij)-0.5),2)/eij;
                }
            }
        }
        else {
            for(Map.Entry<Object, AssociativeArray> entry1 : dataTable.entrySet()) {
                Object i = entry1.getKey();
                AssociativeArray row = entry1.getValue();

                for(Map.Entry<Object, Object> entry2 : row.entrySet()) {
                    Object j = entry2.getKey();
                    Object value = entry2.getValue();
            
                    double v = TypeInference.toDouble(value);

                    //expected value under null hypothesis
                    double eij = XIdot.get(i)*XdotJ.get(j)/Xdotdot;

                    ChisquareScore+=Math.pow((v-eij),2)/eij;
                }
            }
        }
        //XdotJ = null;
        //XIdot = null;

        AssociativeArray result = new AssociativeArray();
        result.put("k", k);
        result.put("n", n);
        result.put("score", ChisquareScore);
        
        return result;
    }
public static AssociativeArray getScore ( DataTable2D dataTable ) { Map < Object , Double > XdotJ = new HashMap < > ( ) ; Map < Object , Double > XIdot = new HashMap < > ( ) ; double Xdotdot = 0.0 ; for ( Map . Entry < Object , AssociativeArray > entry1 : dataTable . entrySet ( ) ) { Object i = entry1 . getKey ( ) ; AssociativeArray row = entry1 . getValue ( ) ; for ( Map . Entry < Object , Object > entry2 : row . entrySet ( ) ) { Object j = entry2 . getKey ( ) ; Object value = entry2 . getValue ( ) ; double v = TypeInference . toDouble ( value ) ; if ( XdotJ . containsKey ( j ) == false ) { XdotJ . put ( j , v ) ; } else { XdotJ . put ( j , XdotJ . get ( j ) + v ) ; } if ( XIdot . containsKey ( i ) == false ) { XIdot . put ( i , v ) ; } else { XIdot . put ( i , XIdot . get ( i ) + v ) ; } Xdotdot += v ; } } int k = XdotJ . size ( ) ; int n = XIdot . size ( ) ; double ChisquareScore = 0.0 ; if ( k == 2 && n == 2 ) { for ( Map . Entry < Object , AssociativeArray > entry1 : dataTable . entrySet ( ) ) { Object i = entry1 . getKey ( ) ; AssociativeArray row = entry1 . getValue ( ) ; for ( Map . Entry < Object , Object > entry2 : row . entrySet ( ) ) { Object j = entry2 . getKey ( ) ; Object value = entry2 . getValue ( ) ; double v = TypeInference . toDouble ( value ) ; double eij = XIdot . get ( i ) * XdotJ . get ( j ) / Xdotdot ; if ( eij == 0 ) { continue ; } ChisquareScore += Math . pow ( ( Math . abs ( v - eij ) - 0.5 ) , 2 ) / eij ; } } } else { for ( Map . Entry < Object , AssociativeArray > entry1 : dataTable . entrySet ( ) ) { Object i = entry1 . getKey ( ) ; AssociativeArray row = entry1 . getValue ( ) ; for ( Map . Entry < Object , Object > entry2 : row . entrySet ( ) ) { Object j = entry2 . getKey ( ) ; Object value = entry2 . getValue ( ) ; double v = TypeInference . toDouble ( value ) ; double eij = XIdot . get ( i ) * XdotJ . get ( j ) / Xdotdot ; ChisquareScore += Math . pow ( ( v - eij ) , 2 ) / eij ; } } } AssociativeArray result = new AssociativeArray ( ) ; result . put ( "k" , k ) ; result . put ( "n" , n ) ; result . put ( "score" , ChisquareScore ) ; return result ; }
Calculates the score of Chisquare test.

@param dataTable
@return