/* nag_median_test (g08acc) 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 above, below, exit_status = 0, i, n1, n2; NagError fail; double p, *x = 0, *y = 0; 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_median_test (g08acc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); n1 = 16; n2 = 23; if (!(x = NAG_ALLOC(n1, double)) || !(y = NAG_ALLOC(n2, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n1; ++i) fscanf(fpin, "%lf", &x[i - 1]); for (i = 1; i <= n2; ++i) fscanf(fpin, "%lf", &y[i - 1]); fprintf(fpout, "\nMedian test\n\n"); fprintf(fpout, "Data values\n\n"); fprintf(fpout, " Group 1 "); for (i = 1; i <= n1; ++i) fprintf(fpout, "%4.0f%s", x[i - 1], i%8?"":"\n "); fprintf(fpout, "\n"); fprintf(fpout, " Group 2 "); for (i = 1; i <= n2; ++i) fprintf(fpout, "%4.0f%s", y[i - 1], i%8?"":"\n "); fprintf(fpout, "\n"); /* nag_median_test (g08acc). * Median test on two samples of unequal size */ nag_median_test(n1, x, n2, y, &above, &below, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_median_test (g08acc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, "%6ld%s\n", above, " scores below median in group 1"); fprintf(fpout, "%6ld%s\n", below, " scores below median in group 2"); fprintf(fpout, "\n%s%8.5f\n", " Significance ", p); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (y) NAG_FREE(y); return exit_status; }