/* nag_tsa_varma_estimate (g13ddc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2004. */ #include #include #include #include int main(void) { /* Scalars */ double cgetol, rlogl; Integer exit_status, i, icm, ik, ip, iprint, iq, ishow, j, k, maxcal, n; Integer niter, npar; Nag_Boolean exact; Nag_IncludeMean mean; char meanc; /* Arrays */ char *outfile = 0; double *cm = 0, *g = 0, *par = 0, *qq = 0, *v = 0, *w = 0; /* Nag types */ Nag_Boolean *parhld = 0; NagError fail; #define W(I,J) w[(J - 1)*ik + I - 1] #define QQ(I,J) qq[(J - 1)*ik + I - 1] INIT_FAIL(fail); exit_status = 0; Vprintf("nag_tsa_varma_estimate (g13ddc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf("%ld%ld%ld%ld %c%*[^\n]", &k, &ip, &iq, &n, &meanc); mean = Nag_MeanZero; if (meanc == 'm' || meanc == 'M') { mean = Nag_MeanInclude; } if ( k >= 1 && ip >= 0 && iq >= 0 && n >= 3) { /* Allocate memory */ ik = k; if ( !(qq = NAG_ALLOC(k*ik, double)) || !(v = NAG_ALLOC(n*ik, double)) || !(w = NAG_ALLOC(n*ik, double)) ) { Vprintf("Allocation failure.\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid k, ip, iq or n.\n"); exit_status = 1; goto END; } npar = (ip + iq) * k * k; if (mean) { npar += k; } /* Allocate memory */ icm = npar; if ( !(cm = NAG_ALLOC(icm * npar, double)) || !(g = NAG_ALLOC(npar, double)) || !(par = NAG_ALLOC(npar, double)) || !(parhld = NAG_ALLOC(npar, Nag_Boolean)) ) { Vprintf("Allocation failure.\n"); exit_status = -1; goto END; } for (i = 1; i <= npar; ++i) { par[i-1] = 0.0; parhld[i-1] = Nag_FALSE; } parhld[2] = Nag_TRUE; /* Set all elements of Q to zero to use covariance matrix */ /* between the K time series as the initial estimate of the */ /* covariance matrix */ for (j = 1; j <= k; ++j) { for (i = j; i <= k; ++i) { QQ(i,j) = 0.0; } } for (i = 1; i <= k; ++i) { for (j = 1; j <= n; ++j) { Vscanf("%lf", &W(i,j)); } } exact = Nag_TRUE; /* ** Set iprint > 0 to obtain intermediate output */ iprint = -1; cgetol = 1.0e-4; maxcal = npar * 40 * (npar + 5); ishow = 2; /* nag_tsa_varma_estimate (g13ddc). * Multivariate time series, estimation of VARMA model */ nag_tsa_varma_estimate(k, n, ip, iq, mean, par, npar, qq, ik, w, parhld, exact, iprint, cgetol, maxcal, ishow, outfile, &niter, &rlogl, v, g, cm, icm, &fail); if (fail.code != NE_NOERROR) { Vprintf("\n nag_tsa_varma_estimate (g13ddc) message: %s\n\n", fail.message); } END: if (cm) NAG_FREE(cm); if (g) NAG_FREE(g); if (par) NAG_FREE(par); if (qq) NAG_FREE(qq); if (v) NAG_FREE(v); if (w) NAG_FREE(w); if (parhld) NAG_FREE(parhld); return exit_status; }