GRASS Programmer's Manual  6.4.2(2012)
kotz.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <math.h>
00003 
00004 
00005 double *kotz_families(double *x, int n)
00006 {
00007     static double y[2];
00008     int i;
00009     double a1, b1, a2, b3, c1, c2, c3, c4, c5, c6, lx;
00010     double sum1 = 0.0, sum2 = 0.0, sum4 = 0.0;
00011 
00012     for (i = 0; i < n; ++i) {
00013         sum1 += x[i];
00014         sum2 += log(x[i]);
00015     }
00016 
00017     b1 = sum1 / n;
00018     a1 = sum2 / n;
00019 
00020     for (i = 0; i < n; ++i) {
00021         lx = log(x[i]);
00022         sum4 += (lx - a1) * (lx - a1);
00023     }
00024 
00025     a2 = sum4 / n;
00026     b3 = exp(a1 * 2 + a2) * (exp(a2) - 1);
00027     c1 = log(a2 / b3);
00028     c2 = (exp(a2 * 4) + exp(a2 * 3) * 2 - 4) / 4 - a2 + exp(a2) * 0.75;
00029     c3 = a2 * (exp(a2) * 2 - 1) * (exp(a2) * 2 - 1);
00030     c4 = (exp(a2) - 1) * 2 * (exp(a2) - 1);
00031     c5 = c3 / c4;
00032 
00033     if (c2 < c5) {
00034 #ifdef NOISY
00035         fprintf(stdout, "  WARNING!!! STATISTICS FOR THE NEXT TEST WILL\n");
00036         fprintf(stdout, "  NOT BE CALCULATED DUE TO SMALL LOGVARIANCE\n");
00037 #endif /* NOISY */
00038         y[0] = 999999999.;
00039     }
00040     else {
00041         c6 = sqrt(c2 - c5) * 2.0 * sqrt((double)n);
00042         y[0] = c1 / c6;
00043     }
00044 
00045 #ifdef NOISY
00046     fprintf(stdout, "  TEST24 KT(LN) =%10.4f\n", y[0]);
00047 #endif /* NOISY */
00048 
00049     return y;
00050 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines