import java.text.*; import com.imsl.stat.*; import com.imsl.math.PrintMatrix; import com.imsl.math.PrintMatrixFormat; public class ANOVAFactorialEx2 { public static void main(String args[]) { int nSubscripts = 3, i; int[] nLevels = {3, 2, 10}; double[] y = { 73.0, 102.0, 118.0, 104.0, 81.0, 107.0, 100.0, 87.0, 117.0, 111.0, 90.0, 76.0, 90.0, 64.0, 86.0, 51.0, 72.0, 90.0, 95.0, 78.0, 98.0, 74.0, 56.0, 111.0, 95.0, 88.0, 82.0, 77.0, 86.0, 92.0, 107.0, 95.0, 97.0, 80.0, 98.0, 74.0, 74.0, 67.0, 89.0, 58.0, 94.0, 79.0, 96.0, 98.0, 102.0, 102.0, 108.0, 91.0, 120.0, 105.0, 49.0, 82.0, 73.0, 86.0, 81.0, 97.0, 106.0, 70.0, 61.0, 82.0 }; String[] labels = { "degrees of freedom for the model ", "degrees of freedom for error ", "total (corrected) degrees of freedom ", "sum of squares for the model ", "sum of squares for error ", "total (corrected) sum of squares ", "model mean square ", "error mean square ", "F-statistic ", "p-value ", "R-squared (in percent) ", "Adjusted R-squared (in percent) ", "est. standard deviation of the model error ", "overall mean of y ", "coefficient of variation (in percent) " }; String[] rlabels = {"A", "B", "A*B"}; String[] mlabels = { "grand mean ", "A1 ", "A2 ", "A3 ", "B1 ", "B2 ", "A1*B1 ", "A1*B2 ", "A2*B1 ", "A2*B2 ", "A3*B1 ", "A3*B2 " }; NumberFormat nf = NumberFormat.getInstance(); ANOVAFactorial af = new ANOVAFactorial(nSubscripts, nLevels, y); nf.setMinimumFractionDigits(6); System.out.println("P-value = " + nf.format(af.compute())); nf.setMaximumFractionDigits(4); System.out.println("\n * * * Analysis of Variance * * *"); double[] anova = af.getANOVATable(); for (i = 0; i < anova.length; i++) { System.out.println(labels[i] + " " + nf.format(anova[i])); } System.out.println("\n * * * Variation Due to the " + "Model * * *"); System.out.println("Source\tDF\tSum of Squares\tMean Square" + "\tProb. of Larger F"); double[][] te = af.getTestEffects(); for (i = 0; i < te.length; i++) { System.out.println(rlabels[i] + "\t" + nf.format(te[i][0]) + "\t" + nf.format(te[i][1]) + "\t" + nf.format(te[i][2]) + "\t\t" + nf.format(te[i][3])); } System.out.println("\n* * * Subgroup Means * * *"); double[] means = af.getMeans(); for (i = 0; i < means.length; i++) { System.out.println(mlabels[i] + " " + nf.format(means[i])); } } }