3 #define REGRESSION_SLOPE 0
4 #define REGRESSION_OFFSET 1
5 #define REGRESSION_COEFF_DET 2
7 static void regression(DCELL * result, DCELL * values,
int n,
int which)
11 DCELL numer, denom, denom2;
18 for (i = 0; i <
n; i++) {
36 for (i = 0; i <
n; i++)
38 numer += i * values[i];
39 numer -= count * xbar * ybar;
42 for (i = 0; i <
n; i++)
44 denom += (DCELL) i *i;
46 denom -= count * xbar * xbar;
50 for (i = 0; i <
n; i++)
52 denom2 += values[i] * values[i];
53 denom2 -= count * ybar * ybar;
58 *result = numer / denom;
61 *result = ybar - xbar * numer / denom;
64 *result = (numer * numer) / (denom * denom2);
72 if (*result != *result)
76 void c_reg_m(DCELL * result, DCELL * values,
int n,
const void *closure)
81 void c_reg_c(DCELL * result, DCELL * values,
int n,
const void *closure)
86 void c_reg_r2(DCELL * result, DCELL * values,
int n,
const void *closure)
91 static void regression_w(DCELL * result, DCELL(*values)[2],
int n,
int which)
95 DCELL numer, denom, denom2;
102 for (i = 0; i <
n; i++) {
106 xsum += i * values[i][1];
107 ysum += values[i][0] * values[i][1];
108 count += values[i][1];
120 for (i = 0; i <
n; i++)
122 numer += i * values[i][0] * values[i][1];
123 numer -= count * xbar * ybar;
126 for (i = 0; i <
n; i++)
128 denom += (DCELL) i *i * values[i][1];
130 denom -= count * xbar * xbar;
134 for (i = 0; i <
n; i++)
136 denom2 += values[i][0] * values[i][0] * values[i][1];
137 denom2 -= count * ybar * ybar;
142 *result = numer / denom;
145 *result = ybar - xbar * numer / denom;
148 *result = (numer * numer) / (denom * denom2);
156 if (*result != *result)
160 void w_reg_m(DCELL * result, DCELL(*values)[2],
int n,
const void *closure)
165 void w_reg_c(DCELL * result, DCELL(*values)[2],
int n,
const void *closure)
170 void w_reg_r2(DCELL * result, DCELL(*values)[2],
int n,
const void *closure)
void w_reg_c(DCELL *result, DCELL(*values)[2], int n, const void *closure)
void c_reg_r2(DCELL *result, DCELL *values, int n, const void *closure)
void G_set_d_null_value(DCELL *dcellVals, int numVals)
void w_reg_m(DCELL *result, DCELL(*values)[2], int n, const void *closure)
void c_reg_c(DCELL *result, DCELL *values, int n, const void *closure)
void w_reg_r2(DCELL *result, DCELL(*values)[2], int n, const void *closure)
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
#define REGRESSION_OFFSET
void c_reg_m(DCELL *result, DCELL *values, int n, const void *closure)
#define REGRESSION_COEFF_DET