/* nag_mann_whitney (g08amc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6a revised, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, n1, n2; NagError fail; double p, u, *x = 0, *y = 0, z; 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_mann_whitney (g08amc) Example Program Results\n\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld %ld ", &n1, &n2); fprintf(fpout, "%s%5ld\n", "Sample size of group 1 = ", n1); fprintf(fpout, "%s%5ld\n", "Sample size of group 2 = ", n2); if (!(x = NAG_ALLOC(n1, double)) || !(y = NAG_ALLOC(n2, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } fprintf(fpout, "\n"); for (i = 1; i <= n1; ++i) fscanf(fpin, "%lf", &x[i - 1]); fprintf(fpout, "%s\n", "Mann-Whitney U test"); fprintf(fpout, "\n"); fprintf(fpout, "%s\n", "Data values"); fprintf(fpout, "\n"); fprintf(fpout, "%s", " Group 1 "); for (i = 1; i <= n1; ++i) fprintf(fpout, "%5.1f%s", x[i - 1], i%8?"":"\n "); for (i = 1; i <= n2; ++i) fscanf(fpin, "%lf", &y[i - 1]); fprintf(fpout, "\n"); fprintf(fpout, "%s", " Group 2 "); for (i = 1; i <= n2; ++i) fprintf(fpout, "%5.1f%s", y[i - 1], i%8?"":"\n "); /* nag_mann_whitney (g08amc). * Performs the Mann-Whitney U test on two independent * samples */ nag_mann_whitney(n1, x, n2, y, Nag_LowerTail, Nag_CompProbApprox, &u, &z, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_mann_whitney (g08amc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n\n"); fprintf(fpout, "%s%8.4f\n", "Test statistic = ", u); fprintf(fpout, "%s%8.4f\n", "Normal Statistic = ", z); fprintf(fpout, "%s%8.4f\n", "Approximate tail probability = ", p); /* nag_mann_whitney (g08amc), see above. */ nag_mann_whitney(n1, x, n2, y, Nag_LowerTail, Nag_CompProbExact, &u, &z, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_mann_whitney (g08amc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "%s%8.4f\n", "Exact tail probability = ", 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; }