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