package com.imsl.test.example.stat; import com.imsl.stat.ANCOVA; /** *
* Performs one-way analysis of covariance and tests for parallelism.
* ** This example fits a one-way analysis of covariance model and performs a test * for parallelism using data discussed by Snedecor and Cochran (1967, Table * 14.8.1, pages 438-443). The responses are weight gains (in pounds per day) of * 40 pigs for four groups of pigs under varying treatments. Two * covariates-initial age (in days) and initial weight (in pounds) are used. For * each treatment, there are 10 pigs. Only the first 5 pigs from each treatment * are shown here.
* *Treatment 1 | *Treatment 2 | *Treatment 3 | *Treatment 4 | *||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Age | *Wt. | *Gain | *Age | *Wt. | *Gain | *Age | *Wt. | *Gain | *Age | *Wt. | *Gain | *
78 | *61 | *1.4 | *78 | *74 | *1.61 | *78 | *80 | *1.67 | *77 | *62 | *1.4 | *
90 | *59 | *1.79 | *99 | *75 | *1.31 | *83 | *61 | *1.41 | *71 | *55 | *1.47 | *
94 | *76 | *1.72 | *80 | *64 | *1.12 | *79 | *62 | *1.73 | *78 | *62 | *1.37 | *
71 | *50 | *1.47 | *75 | *48 | *1.35 | *70 | *47 | *1.23 | *70 | *43 | *1.15 | *
99 | *61 | *1.26 | *94 | *62 | *1.29 | *85 | *59 | *1.49 | *95 | *57 | *1.22 | *
* For these data, the test for non-parallelism is not statistically significant * (p = 0.901). The one-way analysis of covariance test for the treatment means * adjusted for the covariates, assuming parallel slopes, is statistically * significant at a stated significance level of * \(\alpha = 0.05\), (p = 0.04931). Multiple comparisons can * be done using the least significant difference approach of comparing each * pair of treatment groups with the two-sample student-t test. Since the * adjusted means in the one-way analysis of covariance are correlated, the * standard error for these comparisons must be computed using the variances and * covariances in covm. The standard errors for these comparisons are fairly * similar ranging from 0.0630 to 0.0638. The Student's t comparisons identify * differences between groups 1 and 2, and 1 and 4 as being statistically * significant with p-values of 0.01225 and 0.03854 respectively.
* * @see Code * @see Output */ public class ANCOVAEx2 { public static void main(String[] args) { int j; int ngroup = 4; double x1[][] = { {78.0, 90.0, 94.0, 71.0, 99.0, 80.0, 83.0, 75.0, 62.0, 67.0}, {78.0, 99.0, 80.0, 75.0, 94.0, 91.0, 75.0, 63.0, 62.0, 67.0}, {78.0, 83.0, 79.0, 70.0, 85.0, 83.0, 71.0, 66.0, 67.0, 67.0}, {77.0, 71.0, 78.0, 70.0, 95.0, 96.0, 71.0, 63.0, 62.0, 67.0} }; double x2[][] = { {61.0, 59.0, 76.0, 50.0, 61.0, 54.0, 57.0, 45.0, 41.0, 40.0}, {74.0, 75.0, 64.0, 48.0, 62.0, 42.0, 52.0, 43.0, 50.0, 40.0}, {80.0, 61.0, 62.0, 47.0, 59.0, 42.0, 47.0, 42.0, 40.0, 40.0}, {62.0, 55.0, 62.0, 43.0, 57.0, 51.0, 41.0, 40.0, 45.0, 39.0} }; double y[][] = { {1.40, 1.79, 1.72, 1.47, 1.26, 1.28, 1.34, 1.55, 1.57, 1.26}, {1.61, 1.31, 1.12, 1.35, 1.29, 1.24, 1.29, 1.43, 1.29, 1.26}, {1.67, 1.41, 1.73, 1.23, 1.49, 1.22, 1.39, 1.39, 1.56, 1.36}, {1.40, 1.47, 1.37, 1.15, 1.22, 1.48, 1.31, 1.27, 1.22, 1.36} }; double x[][][] = {x1, x2}; /* setup covariate input matrix */ ANCOVA awc = new ANCOVA(y, x); double testpl[] = awc.compute(); double aov[] = awc.getANCOVA(); double adjAov[] = awc.getAdjustedANOVA(); double xymean[][] = awc.getMeans(); double covm[][] = awc.getVarCovAdjustedMeans(); System.out.println("\n * * * 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.3f\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]); 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 %f %f %f %5.4f\n", aov[0], aov[3], aov[6], aov[8], aov[9]); System.out.printf("Error %3.0f %f %f \n", aov[1], aov[4], aov[7]); System.out.printf("Total %3.0f %f \n\n\n", aov[2], aov[5]); System.out.println(" * * * Adjusted Analysis of Variance * " + "* *\n"); System.out.println(" Sum of " + "F Prob of"); System.out.println("Source DF Squares " + "Test Larger F"); System.out.printf("Groups after Covariates %3.0f %10.2f %5.2f " + " %7.5f\n", adjAov[0], adjAov[2], adjAov[4], adjAov[6]); System.out.printf("Covariates after Groups %3.0f %10.2f %5.2f " + " %7.5f\n\n\n", adjAov[1], adjAov[3], adjAov[5], adjAov[7]); System.out.println(" * * * Group Means * * *\n"); System.out.println("GROUP | Unadjusted | Adjusted | Std. Error"); for (int i = 0; i < ngroup; i++) { double se = Math.sqrt(covm[i][i]); System.out.printf(" %d | %5.4f | %5.4f | %7.4f\n", i + 1, xymean[i][ngroup - 1], xymean[i][ngroup], se); } System.out.println("\n\n * * * Student-t Multiple Comparisons * " + "* *\n"); System.out.println(" Groups | Diff | Std. Error | Student-t | " + "P-Value"); for (int i = 0; i < ngroup - 1; i++) { for (j = i + 1; j < ngroup; j++) { double delta = xymean[i][ngroup] - xymean[j][ngroup]; double se = Math.sqrt(covm[i][i] + covm[j][j] - 2.0 * covm[i][j]); double t = delta / se; double df = xymean[i][0] + xymean[j][0] - 2; double pvalue = 1.0 - com.imsl.stat.Cdf.studentsT(t, df); System.out.printf(" %d vs %d | %7.4f | %7.4f | %7.3f " + "| %7.5f\n", i + 1, j + 1, delta, se, t, pvalue); } } } }