/* nag_friedman_test (g08aec) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, ix, j, k, n; NagError fail; double fr, sig, *x = 0; #define X(I, J) x[((I) -1)*n +(J) -1] INIT_FAIL(fail); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_friedman_test (g08aec) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); n = 18; k = 3; ix = k; if (!(x = NAG_ALLOC(ix*n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= ix; ++i) for (j = 1; j <= n; ++j) fscanf(fpin, "%lf", &X(i, j)); fprintf(fpout, "\nFriedman test\n"); fprintf(fpout, "\nData values\n"); fprintf(fpout, "\n Group Group Group\n"); fprintf(fpout, " 1 2 3\n"); for (j = 1; j <= 18; ++j) { for (i = 1; i <= 3; ++i) fprintf(fpout, "%7.1f", X(i, j)); fprintf(fpout, "\n"); } /* nag_friedman_test (g08aec). * Friedman two-way analysis of variance on k matched * samples */ nag_friedman_test(k, n, x, n, &fr, &sig, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_friedman_test (g08aec).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, "%s%6.3f\n", "Test statistic ", fr); fprintf(fpout, "%s%6ld\n", "Degrees of freedom ", k-1); fprintf(fpout, "%s%6.3f\n", "Significance ", sig); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); return exit_status; }