### Example 1: Two-way Analysis of Variance

A two-way analysis of variance is performed with balanced data discussed by Snedecor and Cochran (1967, Table 12.5.1, p. 347). The responses are the weight gains (in grams) of rats that were fed diets varying in the source (A) and level (B) of protein. The model is

where

and

The first responses in each cell in the two-way layout are given in the following table:

 Protein Source (A) Protein Level (B) Beef Cereal Pork High 73, 102, 118, 104, 81, 107, 100, 87, 117, 111 98, 74, 56, 111, 95, 88, 82, 77, 86, 92 94, 79, 96, 98, 102, 102, 108, 91, 120, 105 Low 90, 76, 90, 64, 86, 51, 72, 90, 95, 78 107, 95, 97, 80, 98, 74, 74, 67, 89, 58 49, 82, 73, 86, 81, 97, 106, 70, 61, 82

import java.text.*;
import com.imsl.stat.*;

public class ANOVAFactorialEx1 {

public static void main(String args[]) {
int nSubscripts = 3;
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
};
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(6);
ANOVAFactorial af = new ANOVAFactorial(nSubscripts, nLevels, y);

System.out.println("P-value = " + nf.format(af.compute()));
}
}


#### Output

P-value = 0.002299