Example: TableOneWay

The data for this example is from Hinkley (1977) and Belleman and Hoaglin (1981). The measurements (in inches) are for precipitation in Minneapolis/St. Paul during the month of March for 30 consecutive years.

The first test uses the default tally method which may be appropriate when the range of data is unknown. The minimum and maximum data bounds are displayed.

The second test computes the table usings known bounds, where the lower bound is 0.5 and the upper bound is 4.5. The eight interior intervals each have width (4.5 - 0.5)/(10-2) = 0.5. The 10 intervals are (-\infty, 0.5], (0.5,1.0],...,(4.0,4.5], and (4.5,\infty].

In the third test, 10 class marks, 0.25, 0.75, 1.25,...,4.75, are input. This defines the class intervals (0.0,0.5],(0.5,1.0],...,(4.0,4.5],(4.5,5.0]. Note that unlike the previous test, the initial and last intervals are the same length as the remaining intervals.

In the fourth test, cutpoints, 0.5,1.0, 1.5, 2.0, ...,4.5, are input to define the same 10 intervals as in the second test. Here again, the initial and last intervals are semi- infinite intervals.

using System;
using Imsl.Stat;

public class TableOneWayEx1
{
	public static void  Main(String[] args)
	{
		int nIntervals = 10;
		
		double[] x = new double[]{   0.77, 1.74, 0.81, 1.20, 1.95, 
									 1.20, 0.47, 1.43, 3.37, 2.20, 
									 3.00, 3.09, 1.51, 2.10, 0.52,  
									 1.62, 1.31, 0.32, 0.59, 0.81, 
									 2.81, 1.87, 1.18, 1.35, 4.75,
									 2.48, 0.96, 1.89, 0.9, 2.05};
		double[] cutPoints = new double[]{   0.5, 1.0, 1.5, 2.0, 2.5,
											 3.0, 3.5, 4.0, 4.5};
		double[] classMarks = new double[]{   0.25, 0.75, 1.25, 1.75, 
											  2.25, 2.75, 3.25, 3.75, 
											  4.25, 4.75};
		
		TableOneWay fTbl = new TableOneWay(x, nIntervals);
		
		double[] table = fTbl.GetFrequencyTable();
		
		Console.Out.WriteLine("Example 1 ");
		for (int i = 0; i < table.Length; i++)
			Console.Out.WriteLine(i + "          " + table[i]);
		
		Console.Out.WriteLine("--------------------------");
		Console.Out.WriteLine("Lower bounds= " + fTbl.Minimum);
		Console.Out.WriteLine("Upper bounds= " + fTbl.Maximum);
		Console.Out.WriteLine("--------------------------");
		/*  getFrequencyTable using a set of known bounds */
		table = fTbl.GetFrequencyTable(0.5, 4.5);
		for (int i = 0; i < table.Length; i++)
			Console.Out.WriteLine(i + "          " + table[i]);
		
		Console.Out.WriteLine("---------------------");
		
		table = fTbl.GetFrequencyTableUsingClassmarks(classMarks);
		for (int i = 0; i < table.Length; i++)
			Console.Out.WriteLine(i + "          " + table[i]);
		
		Console.Out.WriteLine("--------------------");
		table = fTbl.GetFrequencyTableUsingCutpoints(cutPoints);
		for (int i = 0; i < table.Length; i++)
			Console.Out.WriteLine(i + "          " + table[i]);
	}
}

Output

Example 1 
0          4
1          8
2          5
3          5
4          3
5          1
6          3
7          0
8          0
9          1
--------------------------
Lower bounds= 0.32
Upper bounds= 4.75
--------------------------
0          2
1          7
2          6
3          6
4          4
5          2
6          2
7          0
8          0
9          1
---------------------
0          2
1          7
2          6
3          6
4          4
5          2
6          2
7          0
8          0
9          1
--------------------
0          2
1          7
2          6
3          6
4          4
5          2
6          2
7          0
8          0
9          1

Link to C# source.