package com.imsl.test.example.stat; import com.imsl.stat.ANCOVA; import com.imsl.math.PrintMatrix; /** *
* Performs a one-way analysis of covariance.
** This example fits a one-way analysis of covariance model assuming parallelism * using data discussed by Snedecor and Cochran (Table 14.6.1, pages 432-436). * The responses are concentrations of cholesterol (in mg/100 ml) in the blood * of two groups of women: women from Iowa and women from Nebraska. The age of a * woman is the single covariate. The cholesterol concentrations and ages of the * women according to state are shown in the following table. (There are 11 Iowa * women and 19 Nebraska women in the study. Only the first 5 women from each * state are shown here.)
*| Iowa | *Nebraska | *||
|---|---|---|---|
| Age | *Cholesterol | *Age | *Cholesterol | *
| 46 | *181 | *18 | *137 | *
| 52 | *228 | *44 | *173 | *
| 39 | *182 | *33 | *177 | *
| 65 | *249 | *78 | *241 | *
| 54 | *259 | *51 | *225 | *
* There is no evidence from the data to indicate that the regression lines for * cholesterol concentration as a function of age are not parallel for Iowa and * Nebraska women (p-value is 0.5425). The parallel line model suggests that * Nebraska women may have higher cholesterol concentrations than Iowa women. * The cholesterol concentrations (adjusted for age) are 195.5 for Iowa women * versus 224.2 for Nebraska women. The difference is 28.7 with an estimated * standard error of
* $$\sqrt{170.4 + 97.4 - 2(2.9)} = 16.1$$ * * @see Code * @see Output */ public class ANCOVAEx1 { public static void main(String args[]) { double y[][] = { {181.0, 228.0, 182.0, 249.0, 259.0, 201.0, 121.0, 339.0, 224.0, 112.0, 189.0}, {137.0, 173.0, 177.0, 241.0, 225.0, 223.0, 190.0, 257.0, 337.0, 189.0, 214.0, 140.0, 196.0, 262.0, 261.0, 356.0, 159.0, 191.0, 197.0}}; double x[][][] = new double[1][2][]; x[0][0] = new double[]{46.0, 52.0, 39.0, 65.0, 54.0, 33.0, 49.0, 76.0, 71.0, 41.0, 58.0}; x[0][1] = new double[]{18.0, 44.0, 33.0, 78.0, 51.0, 43.0, 44.0, 58.0, 63.0, 19.0, 42.0, 30.0, 47.0, 58.0, 70.0, 67.0, 31.0, 21.0, 56.0}; ANCOVA awc = new ANCOVA(y, x); double testpl[] = awc.compute(); double aov[] = awc.getANCOVA(); System.out.println(" * * * Analysis of Variance * * *\n"); System.out.println(" Sum of " + "Mean Prob of"); System.out.println("Source DF Squares Square " + "Overall F Larger F"); System.out.printf("Model %3.0f %10.2f %9.2f %2.2f " + "%8.6f\n", aov[0], aov[3], aov[6], aov[8], aov[9]); System.out.printf("Error %3.0f %10.2f %9.2f \n", aov[1], aov[4], aov[7]); System.out.printf("Total %3.0f %10.2f \n\n\n", aov[2], aov[5]); System.out.println(" * * * Test for Parallelism * * *\n"); System.out.println(" Sum of Mean F " + " Prob of"); System.out.println("Source DF Squares Square Test " + " Larger F"); System.out.println("Extra due to"); System.out.printf("Nonparallelism %3.0f %10.2f %7.2f %7.5f %5.4f\n", testpl[0], testpl[3], testpl[6], testpl[8], testpl[9]); System.out.println("Extra Assuming"); System.out.printf("Nonparallelism %3.0f %10.2f %7.2f \n", testpl[1], testpl[4], testpl[7]); System.out.println("Error Assuming"); System.out.printf("Parallelism %3.0f %10.2f \n\n\n", testpl[2], testpl[5]); new PrintMatrix("XY Mean Matrix\n").print(awc.getMeans()); new PrintMatrix("\n\nVar./Covar. Matrix of Adjusted Group Means" + "\n").print(awc.getVarCovAdjustedMeans()); } }