private static DataTable2D bivariateMatrix ( Dataframe dataSet , BivariateType type ) { DataTable2D bivariateMatrix = new DataTable2D ( ) ; //extract values of first variable Map < Object , TypeInference . DataType > columnTypes = dataSet . getXDataTypes ( ) ; Object [ ] allVariables = columnTypes . keySet ( ) . toArray ( ) ; int numberOfVariables = allVariables . length ; TransposeDataList transposeDataList ; for ( int i = 0 ; i < numberOfVariables ; ++ i ) { Object variable0 = allVariables [ i ] ; if ( columnTypes . get ( variable0 ) == TypeInference . DataType . CATEGORICAL ) { continue ; } transposeDataList = new TransposeDataList ( ) ; //extract values of first variable transposeDataList . put ( 0 , dataSet . getXColumn ( variable0 ) ) ; for ( int j = i ; j < numberOfVariables ; ++ j ) { Object variable1 = allVariables [ j ] ; if ( columnTypes . get ( variable1 ) == TypeInference . DataType . CATEGORICAL ) { continue ; } transposeDataList . put ( 1 , dataSet . getXColumn ( variable1 ) ) ; double value = 0.0 ; if ( type == BivariateType . COVARIANCE ) { value = Descriptives . covariance ( transposeDataList , true ) ; } else if ( type == BivariateType . PEARSONCORRELATION ) { if ( variable0 . equals ( variable1 ) ) { value = 1.0 ; } else { value = PearsonCorrelation . calculateCorrelation ( transposeDataList ) ; } } else if ( type == BivariateType . SPEARMANCORRELATION ) { if ( variable0 . equals ( variable1 ) ) { value = 1.0 ; } else { value = SpearmanCorrelation . calculateCorrelation ( transposeDataList ) ; } } else if ( type == BivariateType . KENDALLTAUCORRELATION ) { if ( variable0 . equals ( variable1 ) ) { value = 1.0 ; } else { value = KendallTauCorrelation . calculateCorrelation ( transposeDataList ) ; } } //bivariateMatrix.internalData.get(variable0).internalData.put(variable1, value); bivariateMatrix . put2d ( variable0 , variable1 , value ) ; if ( ! variable0 . equals ( variable1 ) ) { /* if(!bivariateMatrix.internalData.containsKey(variable1)) { bivariateMatrix.internalData.put(variable1, new AssociativeArray()); } bivariateMatrix.internalData.get(variable1).internalData.put(variable0, value); */ bivariateMatrix . put2d ( variable1 , variable0 , value ) ; } } //transposeDataList = null; } return bivariateMatrix ; }
Calculates BivariateMatrix for a given statistic