/* nag_estim_weibull (g07bec) Example Program. * * Copyright 2001 Numerical Algorithms Group. * * Mark 7, 2001. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; /* Scalars */ double beta, corr, dev, gamma, sebeta, segam, tol; Integer exit_status, i, maxit, n, nit; NagError fail; /* Arrays */ double *x = 0; Integer *ic = 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); exit_status = 0; fprintf(fpout, "nag_estim_weibull (g07bec) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n] "); fscanf(fpin, "%ld%*[^\n] ", &n); /* Allocate memory */ if (!(x = NAG_ALLOC(n, double)) || !(ic = NAG_ALLOC(n, Integer))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n; ++i) fscanf(fpin, "%lf", &x[i - 1]); fscanf(fpin, "%*[^\n] "); /* If data were censored then ic would also be read in. * Leave nag_estim_weibull (g07bec) to calculate initial values */ gamma = 0.0; /* Use default values for tol and maxit */ tol = 0.0; maxit = 0; /* nag_estim_weibull (g07bec). * Computes maximum likelihood estimates for parameters of * the Weibull distribution */ nag_estim_weibull(Nag_NoCensored, n, x, ic, &beta, &gamma, tol, maxit, &sebeta, &segam, &corr, &dev, &nit, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_estim_weibull (g07bec).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, "Beta = %10.4f Standard error = %10.4f\n", beta, sebeta); fprintf(fpout, "Gamma = %10.4f Standard error = %10.4f\n", gamma, segam); END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (ic) NAG_FREE(ic); return exit_status; }