4 #include <grass/raster.h> 14 static void regression(DCELL * result, DCELL * values,
int n,
int which)
18 DCELL numer, denom, denom2;
26 for (i = 0; i < n; i++) {
27 if (Rast_is_d_null_value(&values[i]))
36 Rast_set_d_null_value(result, 1);
44 for (i = 0; i < n; i++)
45 if (!Rast_is_d_null_value(&values[i]))
46 numer += i * values[i];
47 numer -= count * xbar * ybar;
50 for (i = 0; i < n; i++)
51 if (!Rast_is_d_null_value(&values[i]))
52 denom += (DCELL) i * i;
53 denom -= count * xbar * xbar;
57 for (i = 0; i < n; i++)
58 if (!Rast_is_d_null_value(&values[i]))
59 denom2 += values[i] * values[i];
60 denom2 -= count * ybar * ybar;
61 Rsq = (numer * numer) / (denom * denom2);
66 *result = numer / denom;
69 *result = ybar - xbar * numer / denom;
75 *result = sqrt(Rsq * (count - 2) / (1 - Rsq));
78 Rast_set_d_null_value(result, 1);
83 if (*result != *result)
84 Rast_set_d_null_value(result, 1);
87 void c_reg_m(DCELL * result, DCELL * values,
int n,
const void *closure)
92 void c_reg_c(DCELL * result, DCELL * values,
int n,
const void *closure)
97 void c_reg_r2(DCELL * result, DCELL * values,
int n,
const void *closure)
102 void c_reg_t(DCELL * result, DCELL * values,
int n,
const void *closure)
107 static void regression_w(DCELL * result, DCELL(*values)[2],
int n,
int which)
111 DCELL numer, denom, denom2;
119 for (i = 0; i < n; i++) {
120 if (Rast_is_d_null_value(&values[i][0]))
123 xsum += i * values[i][1];
124 ysum += values[i][0] * values[i][1];
125 count += values[i][1];
129 Rast_set_d_null_value(result, 1);
137 for (i = 0; i < n; i++)
138 if (!Rast_is_d_null_value(&values[i][0]))
139 numer += i * values[i][0] * values[i][1];
140 numer -= count * xbar * ybar;
143 for (i = 0; i < n; i++)
144 if (!Rast_is_d_null_value(&values[i][0]))
145 denom += (DCELL) i * i * values[i][1];
147 denom -= count * xbar * xbar;
151 for (i = 0; i < n; i++)
152 if (!Rast_is_d_null_value(&values[i][0]))
153 denom2 += values[i][0] * values[i][0] * values[i][1];
154 denom2 -= count * ybar * ybar;
155 Rsq = (numer * numer) / (denom * denom2);
160 *result = numer / denom;
163 *result = ybar - xbar * numer / denom;
169 *result = sqrt(Rsq * (count - 2) / (1 - Rsq));
172 Rast_set_d_null_value(result, 1);
177 if (*result != *result)
178 Rast_set_d_null_value(result, 1);
181 void w_reg_m(DCELL * result, DCELL(*values)[2],
int n,
const void *closure)
186 void w_reg_c(DCELL * result, DCELL(*values)[2],
int n,
const void *closure)
191 void w_reg_r2(DCELL * result, DCELL(*values)[2],
int n,
const void *closure)
196 void w_reg_t(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 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)
void w_reg_t(DCELL *result, DCELL(*values)[2], int n, const void *closure)
void c_reg_t(DCELL *result, DCELL *values, int n, const void *closure)
void c_reg_m(DCELL *result, DCELL *values, int n, const void *closure)