/* nag_mann_whitney (g08amc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6a revised, 2001. */ #include #include #include #include int main (void) { Integer exit_status=0, i, n1, n2; NagError fail; double p, u, *x=0, *y=0, z; INIT_FAIL(fail); Vprintf("nag_mann_whitney (g08amc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld %ld ", &n1, &n2); Vprintf("%s%5ld\n","Sample size of group 1 = ", n1); Vprintf("%s%5ld\n", "Sample size of group 2 = ", n2); if (!(x = NAG_ALLOC(n1, double)) || !(y = NAG_ALLOC(n2, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } Vprintf("\n"); for (i = 1; i <= n1; ++i) Vscanf("%lf", &x[i - 1]); Vprintf("%s\n","Mann-Whitney U test"); Vprintf("\n"); Vprintf("%s\n", "Data values"); Vprintf("\n"); Vprintf("%s"," Group 1 "); for (i = 1; i <= n1; ++i) Vprintf("%5.1f%s",x[i - 1], i%8?"":"\n "); for (i = 1; i <= n2; ++i) Vscanf("%lf", &y[i - 1]); Vprintf("\n"); Vprintf("%s"," Group 2 "); for (i = 1; i <= n2; ++i) Vprintf("%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) { Vprintf("Error from nag_mann_whitney (g08amc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n\n"); Vprintf("%s%8.4f\n","Test statistic = ", u); Vprintf("%s%8.4f\n","Normal Statistic = ", z); Vprintf("%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) { Vprintf("Error from nag_mann_whitney (g08amc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("%s%8.4f\n","Exact tail probability = ", p); END: if(x) NAG_FREE(x); if(y) NAG_FREE(y); return exit_status; }