package com.imsl.test.example.stat; import java.text.*; import com.imsl.stat.*; /** *

* Performs a three-way factorial analysis of variance.

*

* This example performs a three-way analysis of variance using data discussed * by John (1971, pp. 91 92). The responses are weights (in grams) of roots of * carrots grown with varying amounts of applied nitrogen (A), potassium * (B), and phosphorus (C). Each cell of the three-way layout has * one response. Note that the ABC interactions sum of squares, which is 186, is * given incorrectly by John (1971, Table 5.2.) The three-way layout is given in * the following table:

* * @see Code * @see Output */ public class ANOVAFactorialEx3 { public static void main(String args[]) { int nSubscripts = 3, i; int[] nLevels = {3, 3, 3}; double[] y = { 88.76, 87.45, 86.01, 91.41, 98.27, 104.2, 97.85, 95.85, 90.09, 94.83, 84.57, 81.06, 100.49, 97.2, 120.8, 99.75, 112.3, 108.77, 99.9, 92.98, 94.72, 100.23, 107.77, 118.39, 104.51, 110.94, 102.87 }; 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", "C", "A*B", "A*C", "B*C"}; NumberFormat nf = NumberFormat.getInstance(); ANOVAFactorial af = new ANOVAFactorial(nSubscripts, nLevels, y); af.setErrorIncludeType(ANOVAFactorial.POOL_INTERACTIONS); 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++) { StringBuffer sb = new StringBuffer(rlabels[i]); int len = sb.length(); for (int j = 0; j < (8 - len); j++) { sb.append(' '); } sb.append(nf.format(te[i][0])); len = sb.length(); for (int j = 0; j < (16 - len); j++) { sb.append(' '); } sb.append(nf.format(te[i][1])); len = sb.length(); for (int j = 0; j < (32 - len); j++) { sb.append(' '); } sb.append(nf.format(te[i][2])); len = sb.length(); for (int j = 0; j < (48 - len); j++) { sb.append(' '); } sb.append(nf.format(te[i][3])); System.out.println(sb.toString()); } } }