/* nag_kruskal_wallis_test (g08afc) 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 count, exit_status = 0, i, ii, k, *l = 0, lx, nhi, ni, nlo; NagError fail; double h, p, *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_kruskal_wallis_test (g08afc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); k = 5; if (!(l = NAG_ALLOC(k, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= k; i++) fscanf(fpin, "%ld", &l[i-1]); fprintf(fpout, "\n"); fprintf(fpout, "%s\n", "Kruskal-Wallis test"); fprintf(fpout, "\n"); fprintf(fpout, "%s\n", "Data values"); fprintf(fpout, "\n"); fprintf(fpout, "%s\n", " Group Observations"); lx = 0; for (i = 1; i <= 5; ++i) lx += l[i - 1]; if (!(x = NAG_ALLOC(lx, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= lx; ++i) fscanf(fpin, "%lf", &x[i - 1]); nlo = 1; for (i = 1; i <= k; ++i) { ni = l[i - 1]; nhi = nlo + ni - 1; fprintf(fpout, " %5ld ", i); count = 1; for (ii = nlo; ii <= nhi; ++ii) { fprintf(fpout, "%4.0f%s", x[ii - 1], count%10?"":"\n"); count++; } nlo += ni; fprintf(fpout, "\n"); } /* nag_kruskal_wallis_test (g08afc). * Kruskal-Wallis one-way analysis of variance on k samples * of unequal size */ nag_kruskal_wallis_test(k, l, x, lx, &h, &p, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_kruskal_wallis_test (g08afc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, "%s%9.3f\n", "Test statistic ", h); fprintf(fpout, "%s%9ld\n", "Degrees of freedom ", k-1); fprintf(fpout, "%s%9.3f\n", "Significance ", p); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (l) NAG_FREE(l); if (x) NAG_FREE(x); return exit_status; }