/* nag_anova_row_col (g04bcc) 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 c__0 = 0, exit_status = 0, i, *irep, *it, j, n, ncol, nrep, nrow, nt; NagError fail; const char *fmt_99999[] = { "%3.0f ", "%10.4f ", "%10.4f ", "%10.4f ", "%8.4f" }; double *c = 0, c_b20 = 1e-5, *cmean = 0, *ef = 0, gmean, *r = 0; double *rmean = 0, *rpmean = 0, *table = 0, *tmean = 0, *y = 0; #define TABLE(I, J) table[((I) -1)*5 + (J) -1] #define C(I, J) c[((I) -1)*nt + (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_row_col (g04bcc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld %ld %ld %ld", &nrep, &nrow, &ncol, &nt); if (!(c = NAG_ALLOC(nt*nt, double)) || !(cmean = NAG_ALLOC(nrep*ncol, double)) || !(ef = NAG_ALLOC(nt, double)) || !(r = NAG_ALLOC(nrep*nrow*ncol, double)) || !(y = NAG_ALLOC(nrep*nrow*ncol, double)) || !(rmean = NAG_ALLOC(nrep*nrow, double)) || !(rpmean = NAG_ALLOC(nrep, double)) || !(tmean = NAG_ALLOC(nt, double)) || !(table = NAG_ALLOC(30, double)) || !(irep = NAG_ALLOC(nt, Integer)) || !(it = NAG_ALLOC(nrep*nrow*ncol, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } n = nrep * nrow * ncol; for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &y[i - 1]); for (i = 1; i <= n; ++i) fscanf(fpin, "%ld", &it[i - 1]); /* nag_anova_row_col (g04bcc). * Analysis of variance, general row and column design, * treatment means and standard errors */ nag_anova_row_col(nrep, nrow, ncol, y, nt, it, &gmean, tmean, table, c, nt, irep, rpmean, rmean, cmean, r, ef, c_b20, c__0, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_anova_row_col (g04bcc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n ANOVA TABLE\n\n"); if (nrep > 1) { fprintf(fpout, "\n Reps "); for (j = 1; j <= 5; ++j) fprintf(fpout, fmt_99999[j-1], TABLE(1, j)); } fprintf(fpout, "\n Rows "); for (j = 1; j <= 5; ++j) fprintf(fpout, fmt_99999[j-1], TABLE(2, j)); fprintf(fpout, "\n Columns "); for (j = 1; j <= 5; ++j) fprintf(fpout, fmt_99999[j-1], TABLE(3, j)); fprintf(fpout, "\n\n Treatments "); for (j = 1; j <= 5; ++j) fprintf(fpout, fmt_99999[j-1], TABLE(4, j)); fprintf(fpout, "\n Residual "); for (j = 1; j <= 3; ++j) fprintf(fpout, fmt_99999[j-1], TABLE(5, j)); fprintf(fpout, "\n Total "); for (j = 1; j <= 2; ++j) fprintf(fpout, fmt_99999[j-1], TABLE(6, j)); fprintf(fpout, "\n Treatment means\n\n"); for (i = 1; i <= nt; ++i) fprintf(fpout, "%10.4f%s", tmean[i - 1], i%6?"":"\n"); fprintf(fpout, "\n\n S.E. of difference (orthogonal design) = %10.4f\n", C(2, 1)); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (c) NAG_FREE(c); if (cmean) NAG_FREE(cmean); if (ef) NAG_FREE(ef); if (r) NAG_FREE(r); if (y) NAG_FREE(y); if (rmean) NAG_FREE(rmean); if (rpmean) NAG_FREE(rpmean); if (tmean) NAG_FREE(tmean); if (table) NAG_FREE(table); if (irep) NAG_FREE(irep); if (it) NAG_FREE(it); return exit_status; }