45 _(
"Discont algorithm currently not available because of bugs"));
66 step = (
max -
min) / (nbreaks + 1);
68 for (i = 0; i < nbreaks; i++)
69 classbreaks[i] =
min + (step * (i + 1));
83 nbclass = nbreaks + 1;
91 if (((stats.
mean + stats.
stdev * scale / 2) +
92 (stats.
stdev * scale * (nbclass / 2 - 1)) >
95 (stats.
stdev * scale * (nbclass / 2 - 1)) <
103 for (i = 0; i < nbreaks / 2; i++)
104 classbreaks[i] = (stats.
mean - stats.
stdev * scale / 2) -
105 stats.
stdev * scale * (nbreaks / 2 - (i + 1));
107 for (; i < nbreaks; i++)
108 classbreaks[i] = (stats.
mean + stats.
stdev * scale / 2) +
109 stats.
stdev * scale * (i - nbreaks / 2);
116 if (((stats.
mean) + (stats.
stdev * scale * (nbclass / 2 - 1)) >
118 ((stats.
mean) - (stats.
stdev * scale * (nbclass / 2 - 1)) <
126 for (i = 0; i <= nbreaks / 2; i++)
128 stats.
mean - stats.
stdev * scale * (nbreaks / 2 - i);
130 for (; i < nbreaks; i++)
132 stats.
mean + stats.
stdev * scale * (i - nbreaks / 2);
142 step =
count / (nbreaks + 1);
144 for (i = 0; i < nbreaks; i++)
145 classbreaks[i] = data[step * (i + 1)];
159 nbclass = *nbreaks + 1;
161 lequi =
G_malloc(*nbreaks *
sizeof(
double));
170 else if (nbclass == 3) {
174 else if (nbclass == 4) {
179 else if (nbclass == 5) {
185 else if (nbclass == 6) {
192 else if (nbclass == 7) {
200 else if (nbclass == 8) {
209 else if (nbclass == 9) {
219 else if (nbclass == 10) {
232 _(
"Equiprobable classbreaks currently limited to 10 classes"));
240 for (i = 0; i < *nbreaks; i++) {
241 if ((lequi[i] * stats.
stdev + stats.
mean) >= stats.
min &&
247 if (j < (*nbreaks)) {
249 _(
"There are classbreaks outside the range min-max. Number of "
250 "classes reduced to %i, but using probabilities for %i classes."),
251 j + 1, *nbreaks + 1);
252 G_realloc(classbreaks, j *
sizeof(
double));
253 for (i = 0; i < j; i++)
258 for (i = 0; i < *nbreaks; i++) {
259 if ((lequi[i] * stats.
stdev + stats.
mean) >= stats.
min &&
261 classbreaks[j] = lequi[i] * stats.
stdev + stats.
mean;
278 double *no, *zz, *xn, *co;
281 double min = 0,
max = 0, rangemax = 0;
283 double rangemin = 0, xlim = 0;
285 int nf = 0, nmax = 0;
288 double den = 0, d = 0;
291 int nff = 0, jj = 0, no1 = 0, no2 = 0;
292 double f = 0, xt1 = 0, xt2 = 0, chi2 = 1000.0, xnj_1 = 0, xj_1 = 0;
297 nbclass = nbreaks + 1;
299 num =
G_malloc((nbclass + 1) *
sizeof(
int));
300 no =
G_malloc((nbclass + 1) *
sizeof(
double));
301 zz =
G_malloc((nbclass + 1) *
sizeof(
double));
303 xn =
G_malloc((n + 1) *
sizeof(
double));
304 co =
G_malloc((nbclass + 1) *
sizeof(
double));
314 for (i = 1; i <= n; i++)
320 for (i = 2; i <= n; i++) {
321 if (
x[i] !=
x[i - 1] &&
x[i] -
x[i - 1] < rangemin)
322 rangemin =
x[i] -
x[i - 1];
328 for (i = 1; i <= n; i++) {
329 x[i] = (
x[i] -
min) / rangemax;
330 xn[i] = i / (double)n;
332 xlim = rangemin / rangemax;
333 rangemin = rangemin / 2.0;
340 for (i = 1; i <= nbclass; i++) {
347 for (j = 1; j <= i; j++) {
352 den = sqrt(pow(abc[1], 2) + 1.0);
355 for (k = nd; k <= nf; k++) {
357 d = fabs((-1.0 * abc[1] *
x[k]) + xn[k] - abc[0]) / den;
359 d = fabs(
x[k] - abc[2]);
361 if (
x[k] -
x[nd] < xlim)
363 if (
x[nf] -
x[k] < xlim)
371 if (
x[nf] !=
x[nd]) {
373 co[j] = (xn[nf] - xn[nd]) / (
x[nf] -
x[nd]);
375 co[j] = (xn[nf]) / (
x[nf]);
381 for (j = 1; j <= i; j++) {
383 zz[j] =
x[num[j]] * rangemax +
min;
386 if (co[j] > co[j + 1]) {
387 zz[j] = zz[j] + rangemin;
390 zz[j] = zz[j] - rangemin;
395 for (j = 1; j <= im; j++) {
397 no[ji] -= no[ji - 1];
405 for (j = 1; j <= i; j++) {
407 if (num[jj - 1] < nmax) {
412 num[jj] = num[jj - 1];
423 xnj_1 = xn[num[jj - 1]];
424 xj_1 =
x[num[jj - 1]];
426 no1 = (xn[num[jj]] - xnj_1) * n;
427 no2 = (xn[num[jj + 1]] - xn[num[jj]]) * n;
428 f = (xn[num[jj + 1]] - xnj_1) / (
x[num[jj + 1]] - xj_1);
430 xt1 = (
x[num[jj]] - xj_1) * f;
431 xt2 = (
x[num[jj + 1]] -
x[num[jj]]) * f;
433 xt2 = rangemin / 2.0 / rangemax * f;
436 else if (xt1 * xt2 == 0) {
437 xt1 = rangemin / 2.0 / rangemax * f;
444 if (chi2 > pow((
double)((no1 - no2) - (xt1 - xt2)), 2) / (xt1 + xt2))
445 chi2 = pow((
double)((no1 - no2) - (xt1 - xt2)), 2) / (xt1 + xt2);
449 for (j = 0; j <= (i - 1); j++)
450 classbreaks[j] = zz[j + 1];
456 double *classbreaks,
int *frequencies)
464 for (j = 0; j < nbreaks; j++) {
465 while (data[i] <= classbreaks[j]) {
472 for (; i <
count; i++) {
473 frequencies[nbreaks]++;
double AS_class_discont(double *data, int count, int nbreaks, double *classbreaks)
int AS_class_equiprob(double *data, int count, int *nbreaks, double *classbreaks)
int AS_class_quant(double *data, int count, int nbreaks, double *classbreaks)
double AS_class_apply_algorithm(int algo, double *data, int nrec, int *nbreaks, double *classbreaks)
int AS_class_frequencies(double *data, int count, int nbreaks, double *classbreaks, int *frequencies)
int AS_class_interval(double *data, int count, int nbreaks, double *classbreaks)
int AS_option_to_algorithm(const struct Option *option)
double AS_class_stdev(double *data, int count, int nbreaks, double *classbreaks)
void AS_eqdrt(double[], double[], int, int, double *)
void AS_basic_stats(double *, int, struct GASTATS *)
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
Structure that stores option information.