package com.imsl.test.example.stat; import com.imsl.stat.*; import com.imsl.math.*; /** *

Computes a two-way table in the presence of missing values. *

*

* The data is a \(10 \times 3\) matrix and columns \(0\) and \(1\) are the keys or variables in the * 2-way tabulation. Two missing values (NaNs) are introduced into the keys. NaN is displayed as a "?". * The table of frequencies is displayed, where the values of the * first variable are the row labels and the values of the second variable * are the column labels. The ngroups * array contains the number of rows per group as well, except that a grouping with * a NaN present is not counted.

* * * @see Code * @see Output */ public class TableMultiWayEx1 { public static void main(String args[]) { int nKeys = 2; double x[][] = { {1.0, 1.0, 1.0}, {2.0, 1.0, 2.0}, {1.0, 1.0, 3.0}, {1.0, 1.0, 4.0}, {2.0, 2.0, 5.0}, {1.0, 2.0, 6.0}, {1.0, 2.0, 7.0}, {1.0, 1.0, 8.0}, {2.0, 2.0, 9.0}, {1.0, 1.0, 9.0} }; x[4][1] = Double.NaN; x[6][0] = Double.NaN; PrintMatrix pm = new PrintMatrix("The Input Array"); PrintMatrixFormat mf = new PrintMatrixFormat(); mf.setNoRowLabels(); mf.setNoColumnLabels(); // Print the array pm.print(mf, x); System.out.println(); TableMultiWay tbl = new TableMultiWay(x, nKeys); double table[] = tbl.getBalancedTable().getTable(); double values[] = tbl.getBalancedTable().getValues(); int nvalues[] = tbl.getBalancedTable().getNvalues(); System.out.println("Table:"); System.out.printf("\t"); for (int j = 0; j < nvalues[1]; j++) { System.out.printf("%2.0f \t", values[j + nvalues[0]]); } System.out.println(""); for (int i = 0; i < nvalues[0]; i++) { System.out.printf("%2.0f\t", values[i]); for (int j = 0; j < nvalues[1]; j++) { System.out.printf("%2.0f \t", table[i * nvalues[1] + j]); } System.out.println(""); } int ngroups[] = tbl.getGroups(); System.out.println("\n ngroups"); for (int i = 0; i < ngroups.length; i++) { System.out.print(ngroups[i] + " "); } System.out.println(); } }