/* nag_censored_normal (g07bbc) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double corr, dev, sexmu, sexsig, tol, xmu, xsig; Integer exit_status, i, maxit, n, nit; /* Arrays */ char nag_enum_arg[40]; double *x = 0, *xc = 0; Integer *ic = 0, *nobs = 0; Nag_CEMethod method; NagError fail; 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); exit_status = 0; fprintf(fpout, "nag_censored_normal (g07bbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld %s %lf%lf%lf%ld%*[^\n] ", &n, nag_enum_arg, &xmu, &xsig, &tol, &maxit); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ method = (Nag_CEMethod) nag_enum_name_to_value(nag_enum_arg); /* Allocate memory */ if (!(x = NAG_ALLOC(n, double)) || !(xc = NAG_ALLOC(n, double)) || !(ic = NAG_ALLOC(n, Integer)) || !(nobs = NAG_ALLOC(4, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf%lf%ld", &x[i - 1], &xc[i - 1], &ic[i - 1]); fscanf(fpin, "%*[^\n] "); /* nag_censored_normal (g07bbc). * Computes maximum likelihood estimates for parameters of * the Normal distribution from grouped and/or censored data */ nag_censored_normal(method, n, x, xc, ic, &xmu, &xsig, tol, maxit, &sexmu, &sexsig, &corr, &dev, nobs, &nit, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_censored_normal (g07bbc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " Mean = %8.4f\n", xmu); fprintf(fpout, " Standard deviation = %8.4f\n", xsig); fprintf(fpout, " Standard error of mean = %8.4f\n", sexmu); fprintf(fpout, " Standard error of sigma = %8.4f\n", sexsig); fprintf(fpout, " Correlation coefficient = %8.4f\n", corr); fprintf(fpout, " Number of right censored observations = %2ld\n", nobs[0]); fprintf(fpout, " Number of left censored observations = %2ld\n", nobs[1]); fprintf(fpout, " Number of interval censored observations = %2ld\n", nobs[2]); fprintf(fpout, " Number of exactly specified observations = %2ld\n", nobs[3]); fprintf(fpout, " Number of iterations = %2ld\n", nit); fprintf(fpout, " Log-likelihood = %8.4f\n", dev); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (xc) NAG_FREE(xc); if (ic) NAG_FREE(ic); if (nobs) NAG_FREE(nobs); return exit_status; }