public static Statistics statisticsOf ( CollectionNumber data ) { IteratorNumber iterator = data . iterator ( ) ; if ( ! iterator . hasNext ( ) ) { return null ; } int count = 0 ; double min = iterator . nextDouble ( ) ; while ( Double . isNaN ( min ) ) { if ( ! iterator . hasNext ( ) ) { return null ; } else { min = iterator . nextDouble ( ) ; } } double max = min ; double total = min ; double totalSquare = min * min ; count ++ ; while ( iterator . hasNext ( ) ) { double value = iterator . nextDouble ( ) ; if ( ! Double . isNaN ( value ) ) { if ( value > max ) max = value ; if ( value < min ) min = value ; total += value ; totalSquare += value * value ; count ++ ; } } double average = total / count ; double stdDev = Math . sqrt ( totalSquare / count - average * average ) ; return new StatisticsImpl ( count , min , max , average , stdDev ) ; }
Calculates data statistics excluding NaN values .