/* nag_1_sample_ks_test (g08cbc) 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; Integer i, n, np; double d, p, *par = 0, *x = 0, z; char nag_enum_arg[40]; Nag_TestStatistics ntype; NagError fail; 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_1_sample_ks_test (g08cbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld", &n); x = NAG_ALLOC(n, double); fprintf(fpout, "\n"); for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &x[i - 1]); fscanf(fpin, "%ld", &np); if (!(par = NAG_ALLOC(np, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= np; ++i) fscanf(fpin, "%lf", &par[i - 1]); fscanf(fpin, "%s", nag_enum_arg); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ ntype = (Nag_TestStatistics) nag_enum_name_to_value(nag_enum_arg); /* nag_1_sample_ks_test (g08cbc). * Performs the one-sample Kolmogorov-Smirnov test for * standard distributions */ nag_1_sample_ks_test(n, x, Nag_Uniform, par, Nag_ParaSupplied, ntype, &d, &z, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1_sample_ks_test (g08cbc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "Test against uniform distribution on (0,2)\n"); fprintf(fpout, "\n"); fprintf(fpout, "Test statistic D = %8.4f\n", d); fprintf(fpout, "Z statistic = %8.4f\n", z); fprintf(fpout, "Tail probability = %8.4f\n", p); fprintf(fpout, "\n"); fscanf(fpin, "%ld", &np); for (i = 1; i <= np; ++i) fscanf(fpin, "%lf", &par[i - 1]); fscanf(fpin, "%s", nag_enum_arg); ntype = (Nag_TestStatistics) nag_enum_name_to_value(nag_enum_arg); /* nag_1_sample_ks_test (g08cbc), see above. */ nag_1_sample_ks_test(n, x, Nag_Normal, par, Nag_ParaEstimated, ntype, &d, &z, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_1_sample_ks_test (g08cbc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "Test against Normal distribution with parameters estimated" " from the data\n\n"); fprintf(fpout, "Mean = %6.4f and variance = %6.4f\n", par[0], par[1]); fprintf(fpout, "Test statistic D = %8.4f\n", d); fprintf(fpout, "Z statistic = %8.4f\n", z); fprintf(fpout, "Tail probability = %8.4f\n", p); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (par) NAG_FREE(par); return exit_status; }