/* nag_anova_confid_interval (g04dbc) 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, nt, i, ij, irdf, j, n, nblock; Integer *irep = 0, *isig = 0, *it = 0; const char *fmt_99998[] = { "%s", " %3.0f ", "%10.1f ", "%10.1f ", "%10.3f ", "%9.4f" }; char star[1*2+1]; char nag_enum_arg[40]; double clevel, gmean, rdf, tol; double *bmean = 0, *c = 0, *cil = 0, *ciu = 0, *ef = 0, *r = 0; double *table = 0, *tmean = 0, *y = 0; Nag_IntervalType type; NagError fail; #define TABLE(I, J) table[((I) -1)*5 + (J) -1] 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_anova_confid_interval (g04dbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%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))) { fprintf(fpout, "Allocation failure\n"); exit_status = 1; goto END; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf ", &y[i - 1]); for (i = 1; i <= n; ++i) fscanf(fpin, "%ld ", &it[i - 1]); tol = 5e-6; irdf = 0; nblock = 1; if (!(bmean = NAG_ALLOC(nblock, double))) { exit_status = -1; fprintf(fpout, "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) { fprintf(fpout, "Error from nag_anova_random (g04bbc).\n%s\n", fail.message); exit_status = -1; goto END; } fprintf(fpout, "\n%s\n\n", "ANOVA table"); fprintf(fpout, "%s\n\n", " Source df SS MS F Prob"); fprintf(fpout, " Treatments"); for (j = 1; j <= 5; ++j) fprintf(fpout, fmt_99998[j], TABLE(2, j)); fprintf(fpout, "\n"); fprintf(fpout, " Residual "); for (j = 1; j <= 3; ++j) fprintf(fpout, fmt_99998[j], TABLE(3, j)); fprintf(fpout, "\n"); fprintf(fpout, " Total "); for (j = 1; j <= 2; ++j) fprintf(fpout, fmt_99998[j], TABLE(4, j)); fprintf(fpout, "\n"); fprintf(fpout, "\n Treatment means\n"); fprintf(fpout, "\n"); for (j = 1; j <= nt; ++j) fprintf(fpout, "%8.3f%s", tmean[j - 1], j%8?"":"\n"); fprintf(fpout, "\n"); fprintf(fpout, "\n Simultaneous Confidence Intervals\n\n"); rdf = TABLE(3, 1); fscanf(fpin, " %s %lf", nag_enum_arg, &clevel); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ type = (Nag_IntervalType) nag_enum_name_to_value(nag_enum_arg); /* 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, nt, tmean, rdf, c, nt, clevel, cil, ciu, isig, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "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; fprintf(fpout, " %2ld%2ld %10.3f %10.3f %c\n", i, j, cil[ij - 1], ciu[ij - 1], star[isig[ij - 1]]); } } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); 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; }