/* nag_surviv_risk_sets (g12zac) Example Program. * * Copyright 2002 Numerical Algorithms Group. * * Mark 7, 2002. */ #include #include #include #include #include int main(void) { /* Scalars */ double dev, tol; Integer exit_status, i, ifail, ip, iprint, j, lisi, m, maxit, mxn, n, nd, ns, num, nxs, pdx, pdz; NagError fail; Nag_OrderType order; /* Arrays */ double *b = 0, *cov = 0, *sc = 0, *se = 0, *t = 0, *tp = 0, *x = 0, *z = 0; Integer *ic = 0, *id = 0, *irs = 0, *isi = 0, *isz = 0, *ixs = 0, *nca = 0, *nct = 0; #ifdef NAG_COLUMN_MAJOR #define Z(I,J) z[(J-1)*pdz + I - 1] #define X(I,J) x[(J-1)*pdx + I - 1] order = Nag_ColMajor; #else #define Z(I,J) z[(I-1)*pdz + J - 1] #define X(I,J) x[(I-1)*pdx + J - 1] order = Nag_RowMajor; #endif INIT_FAIL(fail); exit_status = 0; Vprintf("g12zac Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld%ld%ld%ld%ld%*[^\n] ", &n, &m, &ns, &maxit, &iprint); /* Allocate arrays t, z, ic and isi */ if (ns > 0) lisi = n; else lisi = 1; if ( !(t = NAG_ALLOC(n, double)) || !(z = NAG_ALLOC(n * n, double)) || !(ic = NAG_ALLOC(n, Integer)) || !(isi = NAG_ALLOC(lisi, Integer)) || !(isz = NAG_ALLOC(m, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } if (order == Nag_ColMajor) { pdz = n; } else { pdz = m; } if (ns > 0) { for (i = 1; i <= n; ++i) { Vscanf("%lf", &t[i-1]); for (j = 1; j <= m; ++j) Vscanf("%lf", &Z(i,j)); Vscanf("%ld%ld%*[^\n] ", &ic[i-1], &isi[i-1]); } } else { for (i = 1; i <= n; ++i) { Vscanf("%lf", &t[i-1]); for (j = 1; j <= m; ++j) Vscanf("%lf", &Z(i,j)); Vscanf("%ld%*[^\n] ", &ic[i-1]); } } for (i = 1; i <= m; ++i) Vscanf("%ld", &isz[i-1]); Vscanf("%ld%*[^\n] ", &ip); /* Allocate other arrays for g12zac */ mxn = 1000; if (order == Nag_ColMajor) { pdx = mxn; } else { pdx = ip; } if ( !(cov = NAG_ALLOC(ip*(ip+1)/2, double)) || !(sc = NAG_ALLOC(ip, double)) || !(se = NAG_ALLOC(ip, double)) || !(tp = NAG_ALLOC(n, double)) || !(x = NAG_ALLOC(mxn * ip, double)) || !(id = NAG_ALLOC(mxn, Integer)) || !(irs = NAG_ALLOC(n, Integer)) || !(ixs = NAG_ALLOC(mxn, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } g12zac(order, n, m, ns, z, pdz, isz, ip, t, ic, isi, &num, ixs, &nxs, x, mxn, id, &nd, tp, irs, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g12zac.\n%s\n", fail.message); exit_status = 1; goto END; } /* Allocate arrays for g11cac */ if ( !(b = NAG_ALLOC(ip, double)) || !(nca = NAG_ALLOC(nxs, Integer)) || !(nct = NAG_ALLOC(nxs, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= ip; ++i) Vscanf("%lf", &b[i-1]); Vscanf("%*[^\n] "); tol = 1e-5; ifail = 0; g11cac(order, num, ip, nxs, x, pdx, isz, ip, id, ixs, &dev, b, se, sc, cov, nca, nct, tol, maxit, iprint, 0, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from g11cac.\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n"); Vprintf(" Parameter Estimate Standard Error\n"); Vprintf("\n"); for (i = 1; i <= ip; ++i) Vprintf("%5ld %8.4f %8.4f \n", i, b[i-1], se[i-1]); END: if (b) NAG_FREE(b); if (cov) NAG_FREE(cov); if (sc) NAG_FREE(sc); if (se) NAG_FREE(se); if (t) NAG_FREE(t); if (tp) NAG_FREE(tp); if (x) NAG_FREE(x); if (z) NAG_FREE(z); if (ic) NAG_FREE(ic); if (id) NAG_FREE(id); if (irs) NAG_FREE(irs); if (isi) NAG_FREE(isi); if (isz) NAG_FREE(isz); if (ixs) NAG_FREE(ixs); if (nca) NAG_FREE(nca); if (nct) NAG_FREE(nct); return exit_status; }