/* nag_tsa_multi_part_regsn (g13dpc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include static void zprint(Integer, Integer, double *, double *, double *,double *, double *); int main(void) { /* Scalars */ Integer exit_status, i, j, k, m, maxlag, n, tl, pdz; NagError fail; /* Arrays */ double *loglhd = 0, *parlag = 0, *pvalue = 0, *qq = 0, *se = 0, *z = 0, *x = 0; #define Z(I,J) z[(J-1)*pdz + I - 1] INIT_FAIL(fail); exit_status = 0; Vprintf("g13dpc Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%ld%*[^\n] ", &k, &n, &m); if (k > 0 && n >= 1 && m >= 1) { /* Allocate arrays */ tl = m*k+1; if ( !(loglhd = NAG_ALLOC(m, double)) || !(parlag = NAG_ALLOC(k * k * m, double)) || !(pvalue = NAG_ALLOC(m, double)) || !(qq = NAG_ALLOC(k * k * m, double)) || !(se = NAG_ALLOC(k * k * m, double)) || !(z = NAG_ALLOC(k * n, double)) || !(x = NAG_ALLOC(m, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } pdz = k; for (i = 1; i <= k; ++i) { for (j = 1; j <= n; ++j) Vscanf("%lf", &Z(i,j)); Vscanf("%*[^\n] "); } g13dpc(k, n, z, m, &maxlag, parlag, se, qq, x, pvalue, loglhd, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g13dpc.\n%s\n", fail.message); exit_status = 1; goto END; } zprint(k, maxlag, parlag, se, qq, x, pvalue); } END: if (loglhd) NAG_FREE(loglhd); if (parlag) NAG_FREE(parlag); if (pvalue) NAG_FREE(pvalue); if (qq) NAG_FREE(qq); if (se) NAG_FREE(se); if (z) NAG_FREE(z); if (x) NAG_FREE(x); return exit_status; } static void zprint(Integer k, Integer maxlag, double *parlag, double *se, double *qq, double *x, double *pvalue) { /* Scalars */ double sum; Integer i2, i, j, lf; /* Arrays */ char st[7]; #define SE(I,J,K) se[((K-1)*k + (J-1))*k + I - 1] #define QQ(I,J,K) qq[((K-1)*k + (J-1))*k + I - 1] #define PARLAG(I,J,K) parlag[((K-1)*k + (J-1))*k + I - 1] if (k > 1) { Vprintf("\n"); Vprintf(" Partial Autoregression Matrices Indicator" " Residual Chi-Square Pvalue\n"); Vprintf(" Symbols" " Variances Statistic\n"); Vprintf(" ------------------------------- ---------" " --------- ----------- ------\n"); } if (k == 1) { Vprintf("\n"); Vprintf(" Partial Autoregression Function Indicator" " Residual Chi-Square Pvalue\n"); Vprintf(" Symbols"); Vprintf(" Variances"); Vprintf(" Statistic\n"); Vprintf(" ------------------------------- ---------" " --------- ----------- ------\n"); } for (lf = 1; lf <= maxlag; ++lf) { for (j = 1; j <= k; ++j) { sum = PARLAG(1,j,lf); st[j] = '.'; if (sum > SE(1,j,lf) * 1.96) st[j] = '+'; if (sum < SE(1,j,lf) * -1.96) st[j] = '-'; } if (k == 1) { Vprintf("\n"); Vprintf(" Lag %2ld :", lf); for (j = 1; j <= k; ++j) { Vprintf("%6.3f", PARLAG(1,j,lf)); Vprintf("%14s", ""); } for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%14.3f%13.3f%9.3f\n", QQ(1,1,lf), x[lf-1], pvalue[lf-1]); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%6.3f ) ", SE(1,j,lf)); Vprintf("\n"); } else if (k == 2) { Vprintf("\n"); Vprintf(" Lag %2ld :", lf); for (j = 1; j <= k; ++j) Vprintf("%8.3f", PARLAG(1,j,lf)); Vprintf("%14s", ""); for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%13.3f %12.3f %8.3f\n", QQ(1,1,lf), x[lf-1], pvalue[lf-1]); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%5.3f) ", SE(1,j,lf)); Vprintf("\n"); } else if (k == 3) { Vprintf("\n"); Vprintf(" Lag %2ld :", lf); for (j = 1; j <= k; ++j) Vprintf("%8.3f ", PARLAG(1,j,lf)); for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%12.3f%13.3f%9.3f\n", QQ(1,1,lf), x[lf-1], pvalue[lf-1]); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%5.3f) ", SE(1,j,lf)); Vprintf("\n"); } else if (k == 4) { Vprintf("\n"); Vprintf(" Lag %2ld\n", lf); for (j = 1; j <= k; ++j) Vprintf("%8.3f ", PARLAG(1,j,lf)); for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%12.3f%13.3f%9.3f\n", QQ(1,1,lf), x[lf-1], pvalue[lf-1]); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%5.3f) ", SE(1,j,lf)); Vprintf("\n"); } for (i = 2; i <= k; ++i) { for (j = 1; j <= k; ++j) { sum = PARLAG(i,j,lf); st[j] = '.'; if (sum > SE(i,j,lf) * 1.96) st[j] = '+'; if (sum < SE(i,j,lf) * -1.96) st[j] = '-'; } if (k == 2) { Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("%8.3f", PARLAG(i,j,lf)); Vprintf(" "); for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%13.3f\n", QQ(i,i,lf)); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%5.3f) ", SE(i,j,lf)); Vprintf("\n"); } else if (k == 3) { Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("%8.3f ", PARLAG(i,j,lf)); for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%12.3f\n", QQ(i,i,lf)); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%5.3f) ", SE(i,j,lf)); Vprintf("\n"); } else if (k == 4) { for (j = 1; j <= k; ++j) Vprintf("%8.3f ", PARLAG(i,j,lf)); for (i2 = 1; i2 <= k; ++i2) Vprintf("%c", st[i2]); Vprintf("%12.3f\n", QQ(i,i,lf)); Vprintf(" "); for (j = 1; j <= k; ++j) Vprintf("(%5.3f) ", SE(i,j,lf)); Vprintf("\n"); } } } return; }