/* nag_tsa_resid_corr (g13asc) Example Program. * * Copyright 2000 Numerical Algorithms Group. * * Mark 6, 2000. */ #include #include #include #include int main (void) { Integer exit_status=0, i, idf, j, m, *mr=0, narma, ni, npar, nres, nseries; Integer nx; NagError fail; Nag_ArimaOrder arimav; Nag_G13_Opt options; Nag_TransfOrder transfv; double chi, df, objf, *par=0, *r=0, *rc=0, *res, s, *sd=0, siglev, *x=0; INIT_FAIL(fail); Vprintf("nag_tsa_resid_corr (g13asc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld%*[^\n]", &nx); if (!(x = NAG_ALLOC(nx, double)) || !(mr = NAG_ALLOC(7, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nx; ++i) Vscanf("%lf", &x[i - 1]); Vscanf("%*[^\n]"); for (i = 1; i <= 7; ++i) Vscanf("%ld", &mr[i - 1]); Vscanf("%*[^\n]"); npar = mr[0] + mr[2] + mr[3] + mr[5] + 1; if (!(par = NAG_ALLOC(npar, double)) || !(sd = NAG_ALLOC(npar, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= npar; ++i) par[i - 1] = 0.0; nseries = 1; arimav.p = mr[0]; arimav.d = mr[1]; arimav.q = mr[2]; arimav.bigp = mr[3] ; arimav.bigd = mr[4] ; arimav.bigq = mr[5] ; arimav.s = mr[6] ; /* nag_tsa_options_init (g13bxc). * Initialization function for option setting */ nag_tsa_options_init(&options); /* nag_tsa_transf_orders (g13byc). * Allocates memory to transfer function model orders */ nag_tsa_transf_orders(nseries, &transfv, &fail); /* nag_tsa_multi_inp_model_estim (g13bec). * Estimation for time series models */ nag_tsa_multi_inp_model_estim(&arimav, nseries, &transfv, par, npar, nx, x, nseries, sd, &s, &objf, &df, &options, &fail); nres = options.lenres; res = options.res; if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_multi_inp_model_estim (g13bec).\n%s\n", fail.message); exit_status = 1; goto END; } m = 10; if (!(r = NAG_ALLOC(m, double)) || !(rc = NAG_ALLOC(m*m, double))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } narma = mr[0] + mr[2] + mr[3] + mr[5]; /* nag_tsa_resid_corr (g13asc). * Univariate time series, diagnostic checking of residuals, * following nag_tsa_multi_inp_model_estim (g13bec) */ nag_tsa_resid_corr(&arimav, nres, res, m, par, narma, r, rc, m, &chi, &idf, &siglev, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_tsa_resid_corr (g13asc).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\nRESIDUAL AUTOCORRELATION FUNCTION"); Vprintf("\n---------------------------------\n\n"); for (j=0; j<=(m-1)/7; j++) { ni = MIN(7,m - j*7); Vprintf("LAG K "); for (i=0; i