/* nag_tsa_cross_corr (g13bcc) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include int main(void) { /* Scalars */ double r0xy, r0yx, statxy, statyx, sxy, syx; Integer exit_status, i, nl, nxy; NagError fail; /* Arrays */ double *rxy = 0, *ryx = 0, *x = 0, *y = 0; INIT_FAIL(fail); exit_status = 0; printf("nag_tsa_cross_corr (g13bcc) Example Program Results\n"); /* Skip heading in data file */ scanf("%*[^\n] "); /* Read series length and number of lags */ scanf("%ld%ld%*[^\n] ", &nxy, &nl); /* Allocate memory */ if (!(rxy = NAG_ALLOC(nl, double)) || !(ryx = NAG_ALLOC(nl, double)) || !(x = NAG_ALLOC(nxy, double)) || !(y = NAG_ALLOC(nxy, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } /* Read series */ for (i = 1; i <= nxy; ++i) scanf("%lf", &x[i-1]); scanf("%*[^\n] "); for (i = 1; i <= nxy; ++i) scanf("%lf", &y[i-1]); scanf("%*[^\n] "); /* Call routine to calculate cross correlations between X and Y */ /* nag_tsa_cross_corr (g13bcc). * Multivariate time series, cross-correlations */ nag_tsa_cross_corr(x, y, nxy, nl, &sxy, &r0xy, rxy, &statxy, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_tsa_cross_corr (g13bcc), 1st call.\n%s\n", fail.message); exit_status = 1; goto END; } /* Call routine to calculate cross correlations between Y and X */ /* nag_tsa_cross_corr (g13bcc), see above. */ nag_tsa_cross_corr(y, x, nxy, nl, &syx, &r0yx, ryx, &statyx, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_tsa_cross_corr (g13bcc), 2nd call.\n%s\n", fail.message); exit_status = 1; goto END; } printf("\n"); printf(" Between Between\n"); printf(" X and Y Y and X\n"); printf("\n"); printf("Standard deviation ratio%10.4f%15.4f\n", sxy, syx); printf("\n"); printf("Cross correlation at lag\n"); printf(" 0"); printf("%10.4f%15.4f\n", r0xy, r0yx); for (i = 1; i <= nl; ++i) printf(" %4ld%10.4f%15.4f\n", i, rxy[i-1], ryx[i-1]); printf("\n"); printf("Test statistic %10.4f%15.4f\n", statxy, statyx); END: NAG_FREE(rxy); NAG_FREE(ryx); NAG_FREE(x); NAG_FREE(y); return exit_status; }