The data for x in 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 data for y were created by adding small integers to the data in x.
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 using known bounds, where the x lower, x upper, y lower, y upper bounds are chosen so that the intervals will be 0 to 1, 1 to 2, and so on for x and 1 to 2, 2 to 3 and so on for y.
In the third test, the class boundaries are input at the same intervals as in the second test. The first element of cmx and cmy specify the first cutpoint between classes.
The fourth test uses the cutpoints tally option with cutpoints such that the intervals are specified as in the previous tests.
using System; using Imsl.Stat; using PrintMatrix = Imsl.Math.PrintMatrix; public class TableTwoWayEx1 { public static void Main(String[] args) { int nx = 5; int ny = 6; 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[] y = new double[]{ 1.77, 3.74, 3.81, 2.20, 3.95, 4.20, 1.47, 3.43, 6.37, 3.20, 5.00, 6.09, 2.51, 4.10, 3.52, 2.62, 3.31, 3.32, 1.59, 2.81, 5.81, 2.87, 3.18, 4.35, 5.75, 4.48, 3.96, 2.89, 2.9, 5.05}; TableTwoWay fTbl = new TableTwoWay(x, nx, y, ny); double[,] table = fTbl.GetFrequencyTable(); Console.Out.WriteLine("Example 1 "); Console.Out.WriteLine("Use Min and Max for bounds"); new PrintMatrix("counts").Print(table); Console.Out.WriteLine("--------------------------"); Console.Out.WriteLine("Lower xbounds= " + fTbl.MinimumX); Console.Out.WriteLine("Upper xbounds= " + fTbl.MaximumX); Console.Out.WriteLine("Lower ybounds= " + fTbl.MinimumY); Console.Out.WriteLine("Upper ybounds= " + fTbl.MaximumY); Console.Out.WriteLine("--------------------------"); double xlo = 1.0; double xhi = 4.0; double ylo = 2.0; double yhi = 6.0; Console.Out.WriteLine(""); Console.Out.WriteLine("Use Known bounds"); table = fTbl.GetFrequencyTable(xlo, xhi, ylo, yhi); new PrintMatrix("counts").Print(table); double[] cmx = new double[]{0.5, 1.5, 2.5, 3.5, 4.5}; double[] cmy = new double[]{1.5, 2.5, 3.5, 4.5, 5.5, 6.5}; table = fTbl.GetFrequencyTableUsingClassmarks(cmx, cmy); Console.Out.WriteLine(""); Console.Out.WriteLine("Use Class Marks"); new PrintMatrix("counts").Print(table); double[] cpx = new double[]{1, 2, 3, 4}; double[] cpy = new double[]{2, 3, 4, 5, 6}; table = fTbl.GetFrequencyTableUsingCutpoints(cpx, cpy); Console.Out.WriteLine(""); Console.Out.WriteLine("Use Cutpoints"); new PrintMatrix("counts").Print(table); } }
Example 1 Use Min and Max for bounds counts 0 1 2 3 4 5 0 4 2 4 2 0 0 1 0 4 3 2 1 0 2 0 0 1 2 0 1 3 0 0 0 0 1 2 4 0 0 0 0 0 1 -------------------------- Lower xbounds= 0.32 Upper xbounds= 4.75 Lower ybounds= 1.47 Upper ybounds= 6.37 -------------------------- Use Known bounds counts 0 1 2 3 4 5 0 3 2 4 0 0 0 1 0 5 5 2 0 0 2 0 0 1 3 2 0 3 0 0 0 0 0 2 4 0 0 0 0 1 0 Use Class Marks counts 0 1 2 3 4 5 0 3 2 4 0 0 0 1 0 5 5 2 0 0 2 0 0 1 3 2 0 3 0 0 0 0 0 2 4 0 0 0 0 1 0 Use Cutpoints counts 0 1 2 3 4 5 0 3 2 4 0 0 0 1 0 5 5 2 0 0 2 0 0 1 3 2 0 3 0 0 0 0 0 2 4 0 0 0 0 1 0Link to C# source.