/* nag_anova_row_col (g04bcc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { 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, *rmean=0, *rpmean=0; double *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); Vprintf("nag_anova_row_col (g04bcc) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%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))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } n = nrep * nrow * ncol; for (i = 1; i <= n; ++i) Vscanf("%lf", &y[i - 1]); for (i = 1; i <= n; ++i) Vscanf("%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) { Vprintf("Error from nag_anova_row_col (g04bcc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf("%s\n"," ANOVA TABLE"); Vprintf("\n"); if (nrep > 1) { Vprintf("\n%s", " Reps "); for (j = 1; j <= 5; ++j) Vprintf(fmt_99999[j-1], TABLE(1,j)); } Vprintf("\n%s"," Rows "); for (j = 1; j <= 5; ++j) Vprintf(fmt_99999[j-1], TABLE(2,j)); Vprintf("\n%s", " Columns "); for (j = 1; j <= 5; ++j) Vprintf(fmt_99999[j-1], TABLE(3,j)); Vprintf("\n\n%s", " Treatments "); for (j = 1; j <= 5; ++j) Vprintf(fmt_99999[j-1], TABLE(4,j)); Vprintf("\n%s", " Residual "); for (j = 1; j <= 3; ++j) Vprintf(fmt_99999[j-1], TABLE(5,j)); Vprintf("\n%s", " Total "); for (j = 1; j <= 2; ++j) Vprintf(fmt_99999[j-1], TABLE(6,j)); Vprintf("\n%s\n\n", " Treatment means"); for (i = 1; i <= nt; ++i) Vprintf("%10.4f%s", tmean[i - 1], i%6?"":"\n"); Vprintf("\n\n%s%10.4f\n", " S.E. of difference (orthogonal design) = ", C(2,1)); END: 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; }