/* nag_prod_limit_surviv_fn (g12aac) Example Program. * * Copyright 1996 Numerical Algorithms Group. * * Mark 4, 1996. * Mark 8 revised, 2004. * */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; 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); /* Check for command-line IO options */ fpin = nag_example_file_io(argc, argv, "-data", NULL); fpout = nag_example_file_io(argc, argv, "-results", NULL); fprintf(fpout, "nag_prod_limit_surviv_fn (g12aac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%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))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; ++i) fscanf(fpin, "%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) { fprintf(fpout, "Error from nag_prod_limit_surviv_fn (g12aac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n Time Survival Standard\n"); fprintf(fpout, " probability deviation\n\n"); for (i = 0; i < nd; ++i) fprintf(fpout, " %6.1f%10.3f %10.3f\n", tp[i], p[i], psig[i]); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); 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; }