/* nag_kruskal_wallis_test (g08afc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { Integer count, exit_status=0, i, ii, k, *l=0, lx, nhi, ni, nlo; NagError fail; double h, p, *x=0; INIT_FAIL(fail); Vprintf("nag_kruskal_wallis_test (g08afc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); k=5; if (!(l =NAG_ALLOC(k, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i=1; i<=k; i++) Vscanf("%ld", &l[i-1]); Vprintf("\n"); Vprintf("%s\n", "Kruskal-Wallis test"); Vprintf("\n"); Vprintf("%s\n","Data values"); Vprintf("\n"); Vprintf("%s\n"," Group Observations"); lx = 0; for (i = 1; i <= 5; ++i) lx += l[i - 1]; if (!(x = NAG_ALLOC(lx, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= lx; ++i) Vscanf("%lf", &x[i - 1]); nlo = 1; for (i = 1; i <= k; ++i) { ni = l[i - 1]; nhi = nlo + ni - 1; Vprintf(" %5ld ", i); count = 1; for (ii = nlo; ii <= nhi; ++ii) { Vprintf("%4.0f%s", x[ii - 1], count%10?"":"\n"); count++; } nlo += ni; Vprintf("\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) { Vprintf("Error from nag_kruskal_wallis_test (g08afc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("%s%9.3f\n", "Test statistic ", h); Vprintf("%s%9ld\n", "Degrees of freedom ", k-1); Vprintf("%s%9.3f\n","Significance ", p); END: if (l) NAG_FREE(l); if (x) NAG_FREE(x); return exit_status; }