/* nag_prod_limit_surviv_fn (g12aac) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include int main(void) { Integer exit_status=0, i, *ic=0, *ifreq=0, n, nd; NagError fail; double *p=0, *psig=0, *t=0, *tp=0; INIT_FAIL(fail); Vprintf("nag_prod_limit_surviv_fn (g12aac) Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); Vscanf("%ld ", &n); if (n>=2) { if ( !( psig = NAG_ALLOC(n, double)) || !( p = NAG_ALLOC(n, double)) || !( t = NAG_ALLOC(n, double)) || !( tp = NAG_ALLOC(n, double)) || !( ifreq = NAG_ALLOC(n, Integer)) || !( ic = NAG_ALLOC(n, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) Vscanf("%lf %ld %ld ", &t[i], &ic[i], &ifreq[i]); /* nag_prod_limit_surviv_fn (g12aac). * Computes Kaplan-Meier (product-limit) estimates of * survival probabilities */ nag_prod_limit_surviv_fn(n, t, ic, ifreq, &nd, tp, p, psig, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_prod_limit_surviv_fn (g12aac).\n%s\n", fail.message); exit_status = 1; goto END; } Vprintf("\n Time Survival Standard\n"); Vprintf(" probability deviation\n\n"); for (i = 0; i < nd; ++i) Vprintf(" %6.1f%10.3f %10.3f\n", tp[i], p[i], psig[i]); END: if (psig) NAG_FREE(psig); if (p) NAG_FREE(p); if (t) NAG_FREE(t); if (tp) NAG_FREE(tp); if (ifreq) NAG_FREE(ifreq); if (ic) NAG_FREE(ic); return exit_status; }