Example 1: One-way analysis of covariance model

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

import com.imsl.stat.ANCOVA;
import com.imsl.math.PrintMatrix;

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());
    }
}

Output

             * * * Analysis of Variance * * *

                  Sum of         Mean                Prob of
Source   DF      Squares        Square    Overall F  Larger F
Model    2       54432.75       27216.38  14.97      0.000042
Error    27      49103.91       1818.66 
Total    29      103536.67 


           * * * Test for Parallelism  * * *

                       Sum of     Mean     F      Prob of
Source           DF    Squares   Square   Test    Larger F
Extra due to
Nonparallelism   1     709.05    709.05   0.38093 0.5425
Extra Assuming
Nonparallelism   26    48394.86  1861.34 
Error Assuming
Parallelism      27    49103.91 


         XY Mean Matrix

   0     1        2        3     
0  11  53.091  207.727  195.521  
1  19  45.947  217.105  224.172  
2  30  48.567  213.667  213.667  



Var./Covar. Matrix of Adjusted Group Means

      0       1     
0  170.368  -2.915  
1   -2.915  97.407  

Link to Java source.