/* nag_wilcoxon_test (g08agc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { Integer exit_status=0, i, n, non_zero; NagError fail; double *data=0, median, p, w, *x=0, *y=0, z; INIT_FAIL(fail); Vprintf("nag_wilcoxon_test (g08agc) Example Program Results"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld", &n); if (!(x = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double)) || !(data = NAG_ALLOC(n, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) Vscanf("%lf", &x[i - 1]); for (i = 1; i <= n; ++i) Vscanf("%lf", &y[i - 1]); Vprintf("\n\n"); Vprintf("%s\n", "Wilcoxon one sample signed ranks test"); Vprintf("\n"); Vprintf("%s", "Data values\n"); for (i = 1; i <= n; ++i) Vprintf("%5.1f%s", x[i - 1], i%8?"":"\n"); for (i = 1; i <= n; ++i) Vprintf("%5.1f%s", y[i - 1], i%8?"":"\n"); for (i = 1; i <= n; ++i) data[i - 1] = x[i - 1] - y[i - 1]; median = 0.0; /* nag_wilcoxon_test (g08agc). * Performs the Wilcoxon one-sample (matched pairs) signed * rank test */ nag_wilcoxon_test(n, data, median, Nag_TwoTail, Nag_IncSignZerosN, &w, &z, &p, &non_zero, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_wilcoxon_test (g08agc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n\n"); Vprintf("%s%8.4f\n", "Test statistic = ", w); Vprintf("%s%8.4f\n", "Normalized test statistic = ", z); Vprintf("%s%8ld\n","Degrees of freedom = ", non_zero); Vprintf("%s%8.4f\n", "Two tail probability = ", p); END: if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (data) NAG_FREE(data); return exit_status; }