/* nag_regsn_std_resid_influence (g02fac) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include #include #define SRES(I, J) sres[(I) *tdsres + J] int main(int argc, char *argv[]) { FILE *fpin, *fpout; Integer exit_status = 0, i, ip, j, n, nres, tdsres; double *h = 0, *res = 0, rms, *sres = 0; 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_regsn_std_resid_influence (g02fac) Example Program Results\n"); /* Skip heading in data file */ fscanf(fpin, "%*[^\n]"); fscanf(fpin, "%ld %ld %ld %lf", &n, &ip, &nres, &rms); if (nres <= n && n > ip+1) { if (!(h = NAG_ALLOC(n, double)) || !(res = NAG_ALLOC(n, double)) || !(sres = NAG_ALLOC(n*4, double))) { fprintf(fpout, "Allocation failure\n"); exit_status = -1; goto END; } tdsres = 4; } else { fprintf(fpout, "Invalid nres or n or ip.\n"); exit_status = 1; return exit_status; } for (i = 0; i < n; i++) fscanf(fpin, "%lf%lf", &res[i], &h[i]); /* nag_regsn_std_resid_influence (g02fac). * Calculates standardized residuals and influence * statistics */ nag_regsn_std_resid_influence(n, ip, nres, res, h, rms, sres, &fail); if (fail.code != NE_NOERROR) { fprintf(fpout, "Error from nag_regsn_std_resid_influence (g02fac).\n%s\n", fail.message); exit_status = 1; goto END; } fprintf(fpout, "\n"); fprintf(fpout, " Internally Externally\n"); fprintf(fpout, " Obs. studentized studentized Cook's D Atkinson's T\n"); fprintf(fpout, " residuals residuals\n\n"); for (i = 0; i < nres; i++) { fprintf(fpout, "%2ld", i+1); for (j = 0; j < 4; j++) fprintf(fpout, "%14.3f", SRES(i, j)); fprintf(fpout, "\n"); } END: if (fpin != stdin) fclose(fpin); if (fpout != stdout) fclose(fpout); if (h) NAG_FREE(h); if (res) NAG_FREE(res); if (sres) NAG_FREE(sres); return exit_status; }