Example: TableTwoWay

The data for x in this example is from Hinkley (1977) and Belleman and Hoaglin (1981). The measurement (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 as 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.


import com.imsl.stat.*;
import com.imsl.math.PrintMatrix;

public class TableTwoWayEx1 {

    public static void main(String args[]) {
        int nx = 5, ny = 6;
        double table[][];

        double[] x = {
            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[] = {
            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);

        table = fTbl.getFrequencyTable();

        System.out.println("Example 1 ");
        System.out.println("Use Min and Max for bounds");
        new PrintMatrix("counts").print(table);

        System.out.println("--------------------------");
        System.out.println("Lower xbounds= " + fTbl.getMinimumX());
        System.out.println("Upper xbounds= " + fTbl.getMaximumX());
        System.out.println("Lower ybounds= " + fTbl.getMinimumY());
        System.out.println("Upper ybounds= " + fTbl.getMaximumY());
        System.out.println("--------------------------");

        double xlo = 1.0;
        double xhi = 4.0;
        double ylo = 2.0;
        double yhi = 6.0;
        System.out.println("");
        System.out.println("Use Known bounds");
        table = fTbl.getFrequencyTable(xlo, xhi, ylo, yhi);
        new PrintMatrix("counts").print(table);

        double cmx[] = {0.5, 1.5, 2.5, 3.5, 4.5};
        double cmy[] = {1.5, 2.5, 3.5, 4.5, 5.5, 6.5};
        table = fTbl.getFrequencyTableUsingClassmarks(cmx, cmy);
        System.out.println("");
        System.out.println("Use Class Marks");
        new PrintMatrix("counts").print(table);

        double cpx[] = {1, 2, 3, 4};
        double cpy[] = {2, 3, 4, 5, 6};
        table = fTbl.getFrequencyTableUsingCutpoints(cpx, cpy);
        System.out.println("");
        System.out.println("Use Cutpoints");
        new PrintMatrix("counts").print(table);
    }
}

Output

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  0  

Link to Java source.