/* nag_regress_confid_interval (g02cbc) Example Program. * * Copyright 1992 Numerical Algorithms Group. * * Mark 3, 1992. * Mark 8 revised, 2004. */ #include #include #include #include #include int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, n; double clm, clp; double *h = 0, *res = 0, rms, *wt = 0, *x = 0, *y = 0, *yhat = 0; double *yl = 0, *yml = 0, *ymu = 0, *yu = 0; char nag_enum_arg[40]; Nag_SumSquare mean; Nag_Boolean weight; 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); fprintf(fpout, "nag_regress_confid_interval (g02cbc) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld\n", &n); fscanf(fpin, "%lf%lf\n", &clm, &clp); fscanf(fpin, " %s", nag_enum_arg); /* nag_enum_name_to_value(x04nac). * Converts NAG enum member name to value */ mean = (Nag_SumSquare) nag_enum_name_to_value(nag_enum_arg); fscanf(fpin, " %s", nag_enum_arg); weight = (Nag_Boolean) nag_enum_name_to_value(nag_enum_arg); if (n >= (mean == Nag_AboutMean?2:1)) { if (!(x = NAG_ALLOC(n, double)) || !(y = NAG_ALLOC(n, double)) || !(wt = NAG_ALLOC(n, double)) || !(yhat = NAG_ALLOC(n, double)) || !(yml = NAG_ALLOC(n, double)) || !(ymu = NAG_ALLOC(n, double)) || !(yl = NAG_ALLOC(n, double)) || !(yu = NAG_ALLOC(n, double)) || !(h = NAG_ALLOC(n, double)) || !(res = NAG_ALLOC(n, double)) ) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } } else { fprintf(fpout, "Invalid n.\n"); exit_status = 1; return exit_status; } if (weight) for (i = 0; i < n; i++) fscanf(fpin, "%lf%lf%lf\n", &x[i], &y[i], &wt[i]); else for (i = 0; i < n; ++i) fscanf(fpin, "%lf%lf\n", &x[i], &y[i]); /* nag_regress_confid_interval (g02cbc). * Simple linear regression confidence intervals for the * regression line and individual points */ nag_regress_confid_interval(mean, n, x, y, wt, clm, clp, yhat, yml, ymu, yl, yu, h, res, &rms, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_regress_confid_interval (g02cbc).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\ni yhat[i] yml[i] ymu[i] yl[i] yu[i]" " \n\n"); for (i = 0; i < n; ++i) { fprintf(fpout, "%ld %10.2f %10.2f", i, yhat[i], yml[i]); fprintf(fpout, "%10.2f %10.2f %10.2f\n", ymu[i], yl[i], yu[i]); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (x) NAG_FREE(x); if (y) NAG_FREE(y); if (wt) NAG_FREE(wt); if (yhat) NAG_FREE(yhat); if (yml) NAG_FREE(yml); if (ymu) NAG_FREE(ymu); if (yl) NAG_FREE(yl); if (yu) NAG_FREE(yu); if (h) NAG_FREE(h); if (res) NAG_FREE(res); return exit_status; }