Generating summary statistics
We can generate summary statistics for data by using the SummaryStatistics
class. This is similar to the DescriptiveStatistics
class used in the preceding recipe; the major difference is that unlike the DescriptiveStatistics
class, the SummaryStatistics
class does not store data in memory.
How to do it...
Like the preceding recipe, create a method that takes a
double
array as argument:public void getSummaryStats(double[] values){
Create an object of class
SummaryStatistics:
SummaryStatistics stats = new SummaryStatistics();
Add all the values to this object of theÂ
SummaryStatistics
class:for( int i = 0; i < values.length; i++) { stats.addValue(values[i]); }
Finally, use methods in the
SummaryStatistics
class to generate the summary statistics for the values. Close the method when you are done using the statistics:
double mean = stats.getMean(); double std = stats...