/* nag_sign_test (g08aac) 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_tied, s; 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_sign_test (g08aac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); n = 17; if (!(x = NAG_ALLOC(n, double)) || !(y = 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%s\n\n", "Sign test"); fprintf(fpout, "%s\n\n", "Data values"); for (i = 1; i <= n; i++) fprintf(fpout, "%3.0f%s", x[i-1], i%n?"":"\n"); fprintf(fpout, "\n"); for (i = 1; i <= n; i++) fprintf(fpout, "%3.0f%s", y[i-1], i%n?"":"\n"); fprintf(fpout, "\n"); /* nag_sign_test (g08aac). * Sign test on two paired samples */ nag_sign_test(n, x, y, &s, &p, &non_tied, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_sign_test (g08aac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "%s%5ld\n", "Test statistic ", s); fprintf(fpout, "%s%5ld\n", "Observations ", non_tied); fprintf(fpout, "%s%5.3f\n", "Lower tail prob. ", 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; }