61 double *slope,
double *intercept,
double *variance) {
63 double x, y, sum_x2, sum_x, sum_xy, sum_y, D, residual1, nUsed;
74 sum_x = sum_x2 = sum_y = sum_xy = 0;
76 for (i = 0; i < nData; i++) {
77 if (!select || select[i]) {
79 sum_x += (x = xData[i]);
81 sum_y += (y = yData[i]);
88 if ((D = nUsed * sum_x2 - sum_x * sum_x)) {
89 *slope = (nUsed * sum_xy - sum_x * sum_y) / D;
90 *intercept = (sum_x2 * sum_y - sum_x * sum_xy) / D;
92 for (i = 0; i < nData; i++) {
93 if (!select || select[i]) {
94 residual1 = (yData[i] - (xData[i] * (*slope) + (*intercept)));
95 *variance += residual1 * residual1;
99 *variance /= (nUsed - 2);
long unweightedLinearFitSelect(double *xData, double *yData, short *select, long nData, double *slope, double *intercept, double *variance)
Performs an unweighted linear fit on the provided data with optional data point selection.
long unweightedLinearFit(double *xData, double *yData, long nData, double *slope, double *intercept, double *variance)
Performs an unweighted linear fit on the provided data.