diff --git a/xdocs/userguide/stat.xml b/xdocs/userguide/stat.xml index 8ff01f14e..d2e734170 100644 --- a/xdocs/userguide/stat.xml +++ b/xdocs/userguide/stat.xml @@ -17,7 +17,7 @@ --> - + The Commons Math User Guide - Statistics @@ -170,8 +170,66 @@ in.close(); -

This is yet to be written. Any contributions will be gratefully - accepted!

+

+ + org.apache.commons.math.stat.univariate.Frequency + provides a simple interface for maintaining counts and percentages of discrete + values. +

+

+ Strings, integers, longs, chars are all supported as value types, as well as instances + of any class that implements Comparable. The ordering of values + used in computing cumulative frequencies is by default the natural ordering, + but this can be overriden by supplying a Comparator to the constructor. + Adding values that are not comparable to those that have already been added results in an + IllegalArgumentException. +

+

+ Here are some examples. +

+
Compute a frequency distribution based on integer values
+

+
Mixing integers, longs, Integers and Longs: + + Frequency f = new Frequency(); + f.addValue(1); + f.addValue(new Integer(1)); + f.addValue(new Long(1)); + f.addValue(2) + f.addValue(new Integer(-1)); + System.out.prinltn(f.getCount(1)); // displays 3 + System.out.println(f.getCumPct(0)); // displays 0.2 + System.out.println(f.getPct(new Integer(1))); // displays 0.6 + System.out.println(f.getCumPct(-2)); // displays 0 -- all values are greater than this + System.out.println(f.getCumPct(10)); // displays 1 -- all values are less than this + +
+
Count string frequencies
+

+
Using case-sensitive comparison, alpha sort order (natural comparator): + +Frequency f = new Frequency(); +f.addValue("one"); +f.addValue("One"); +f.addValue("oNe"); +f.addValue("Z"); +System.out.println(f.getCount("one")); // displays 1 +System.out.println(f.getCumPct("Z")); // displays 0.5 -- second in sort order + +
+
Using case-insensitive comparator: + +Frequency f = new Frequency(String.CASE_INSENSITIVE_ORDER); +f.addValue("one"); +f.addValue("One"); +f.addValue("oNe"); +f.addValue("Z"); +System.out.println(f.getCount("one")); // displays 3 +System.out.println(f.getCumPct("z")); // displays 1 -- last value + +
+
+

This is yet to be written. Any contributions will be gratefully