/* nag_anova_confid_interval (g04dbc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { #define TABLE(I,J) table[((I)-1)*5 + (J)-1] Integer exit_status=0, i, ij, irdf, *irep=0, *isig=0, *it=0, j, n, nblock; Integer nt; NagError fail; Nag_IntervalType type_enum; const char *fmt_99998[] = {"%s", " %3.0f ", "%10.1f ", "%10.1f ", "%10.3f ", "%9.4f"}; char star[1*2+1], type[2]; double *bmean=0, *c=0, *cil=0, *ciu=0, clevel, *ef=0, gmean, *r=0, rdf; double *table=0, *tmean=0, tol, *y=0; INIT_FAIL(fail); Vprintf("nag_anova_confid_interval (g04dbc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld %ld ", &n, &nt); if (!(y = NAG_ALLOC(n, double)) || !(it = NAG_ALLOC(n, Integer)) || !(tmean = NAG_ALLOC(nt, double)) || !(table = NAG_ALLOC(4*5, double)) || !(c = NAG_ALLOC(nt*nt, double)) || !(irep = NAG_ALLOC(nt, Integer)) || !(r = NAG_ALLOC(n, double)) || !(ef = NAG_ALLOC(nt, double)) || !(isig = NAG_ALLOC(nt*(nt-1)/2, Integer)) || !(cil = NAG_ALLOC(nt*(nt-1)/2, double)) || !(ciu = NAG_ALLOC(nt*(nt-1)/2, double))) { Vprintf("Allocation failure\n"); exit_status = 1; goto END; } for (i = 1; i <= n; ++i) Vscanf("%lf ", &y[i - 1]); for (i = 1; i <= n; ++i) Vscanf("%ld ", &it[i - 1]); tol = 5e-6; irdf = 0; nblock = 1; if (!(bmean = NAG_ALLOC(nblock, double))) { exit_status = -1; Vprintf("Allocation failure\n"); goto END; } /* nag_anova_random (g04bbc). * General block design or completely randomized design */ nag_anova_random(n, y, Nag_NoBlocks, nblock, nt, it, &gmean, bmean, tmean, table, c, nt, irep, r, ef, tol, irdf, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_anova_random (g04bbc).\n%s\n", fail.message); exit_status = -1; goto END; } Vprintf("\n%s\n\n", "ANOVA table"); Vprintf("%s\n\n", " Source df SS MS F Prob"); Vprintf(" Treatments"); for (j = 1; j <= 5; ++j) Vprintf(fmt_99998[j], TABLE(2,j)); Vprintf("\n"); Vprintf(" Residual "); for (j = 1; j <= 3; ++j) Vprintf(fmt_99998[j], TABLE(3,j)); Vprintf("\n"); Vprintf(" Total "); for (j = 1; j <= 2; ++j) Vprintf(fmt_99998[j], TABLE(4,j)); Vprintf("\n"); Vprintf("\n Treatment means\n"); Vprintf("\n"); for (j = 1; j <= nt; ++j) Vprintf("%8.3f%s", tmean[j - 1],j%8?"":"\n"); Vprintf("\n"); Vprintf("\n Simultaneous Confidence Intervals\n\n"); rdf = TABLE(3,1); Vscanf(" '%c' %lf", type, &clevel); if (*type == 'T') type_enum = Nag_TukeyInterval; else if (*type == 'B') type_enum = Nag_BonferroniInterval; else if (*type == 'D') type_enum = Nag_DunnInterval; else if (*type == 'L') type_enum = Nag_FisherInterval; else if (*type == 'S') type_enum = Nag_ScheffeInterval; else type_enum = (Nag_IntervalType)-999; /* nag_anova_confid_interval (g04dbc). * Computes confidence intervals for differences between * means computed by nag_anova_random (g04bbc) or * nag_anova_row_col (g04bcc) */ nag_anova_confid_interval(type_enum, nt, tmean, rdf, c, nt, clevel, cil, ciu, isig, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_anova_confid_interval (g04dbc).\n%s\n", fail.message); exit_status=1; goto END; } star[1] = '*'; star[0] = ' '; star[2] = '\0'; ij = 0; for (i = 1; i <= nt; ++i) { for (j = 1; j <= i - 1; ++j) { ++ij; Vprintf(" %2ld%2ld %10.3f %10.3f %c\n", i, j, cil[ij - 1], ciu[ij - 1], star[isig[ij - 1]]); } } END: if (y) NAG_FREE(y); if (it) NAG_FREE(it); if (tmean) NAG_FREE(tmean); if (table) NAG_FREE(table); if (c) NAG_FREE(c); if (irep) NAG_FREE(irep); if (r) NAG_FREE(r); if (ef) NAG_FREE(ef); if (isig) NAG_FREE(isig); if (cil) NAG_FREE(cil); if (ciu) NAG_FREE(ciu); if (bmean) NAG_FREE(bmean); return exit_status; }