/* nag_shapiro_wilk_test (g01ddc) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Local variables */ Nag_Boolean calwts; Integer exit_status = 0, i, j, n; NagError fail; double *a = 0, pw, w, *x = 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_shapiro_wilk_test (g01ddc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); calwts = Nag_TRUE; fscanf(fpin, "%ld ", &n); if (n >= 3) { if (!(a = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(n, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (j = 1; j <= 2; ++j) { for (i = 1; i <= n; ++i) fscanf(fpin, "%lf ", &x[i - 1]); /* nag_double_sort (m01cac). * Quicksort of set of values of data type double */ nag_double_sort(x, (size_t) n, Nag_Ascending, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_double_sort (m01cac).\n%s\n", fail.message); exit_status = 1; goto END; } /* nag_shapiro_wilk_test (g01ddc). * Shapiro and Wilk's W test for Normality */ nag_shapiro_wilk_test(n, x, calwts, a, &w, &pw, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_shapiro_wilk_test (g01ddc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n For sample number %2ld, value of W statistic = " "%7.4f\n", j, w); fprintf(fpout, " Significance level is %8.4f\n", pw); calwts = Nag_FALSE; } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (a) NAG_FREE(a); if (x) NAG_FREE(x); return exit_status; }