/* nag_wilcoxon_test (g08agc) 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, n, non_zero; NagError fail; double *data = 0, median, p, w, *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_wilcoxon_test (g08agc) Example Program Results"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld", &n); if (!(x = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double)) || !(data = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &x[i - 1]); for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &y[i - 1]); fprintf(fpout, "\n\n"); fprintf(fpout, "%s\n", "Wilcoxon one sample signed ranks test"); fprintf(fpout, "\n"); fprintf(fpout, "%s", "Data values\n"); for (i = 1; i <= n; ++i) fprintf(fpout, "%5.1f%s", x[i - 1], i%8?"":"\n"); for (i = 1; i <= n; ++i) fprintf(fpout, "%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) { fprintf(fpout, "Error from nag_wilcoxon_test (g08agc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n\n"); fprintf(fpout, "%s%8.4f\n", "Test statistic = ", w); fprintf(fpout, "%s%8.4f\n", "Normalized test statistic = ", z); fprintf(fpout, "%s%8ld\n", "Degrees of freedom = ", non_zero); fprintf(fpout, "%s%8.4f\n", "Two tail probability = ", p); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (data) NAG_FREE(data); return exit_status; }