/* nag_simple_linear_regression(g02cac) Example Program * * Copyright 1992 Numerical Algorithms Group. * * Mark 3, 1992. */ #include #include #include #include #define NMAX 10 int main(void) { Nag_SumSquare mean; char m, w; Integer i, n; double x[NMAX], y[NMAX], wt[NMAX]; double a, b, err_a, err_b, rsq, rss, df; double *wtptr; Vprintf("g02cac Example Program Results\n"); /* Skip heading in data file */ Vscanf("%*[^\n]"); Vscanf(" %c %c",&m, &w); Vscanf("%ld", &n); if (n>=1 && n<=NMAX) { if (m == 'M' || m == 'm') mean = Nag_AboutMean; else mean = Nag_AboutZero; if (w == 'W' || w == 'w') { wtptr = wt; for(i = 0; i < n; ++i) Vscanf("%lf%lf%lf", &x[i], &y[i], &wt[i]); } else { wtptr = (double *)0; for(i = 0; i < n; ++i) Vscanf("%lf%lf", &x[i], &y[i]); } g02cac(mean, n, x, y, wtptr, &a, &b, &err_a, &err_b, &rsq, &rss, &df, NAGERR_DEFAULT); if (mean == Nag_AboutMean) { Vprintf("\nRegression constant a = %6.4f\n\n", a); Vprintf("Standard error of the regression constant a = %6.4f\n\n", err_a); } Vprintf("Regression coefficient b = %6.4f\n\n", b); Vprintf("Standard error of the regression coefficient b = %6.4f\n\n", err_b); Vprintf("The regression coefficient of determination = %6.4f\n\n", rsq); Vprintf("The sum of squares of the residuals about the " "regression = %6.4f\n\n", rss); Vprintf("Number of degrees of freedom about the " "regression = %6.4f\n\n",df); } else { Vfprintf(stderr, "n is out of range:" " n = %-3ld\n",n); return EXIT_FAILURE; } return EXIT_SUCCESS; }