kotz.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <stdio.h>
  2. #include <math.h>
  3. double *Cdhc_kotz_families(double *x, int n)
  4. {
  5. static double y[2];
  6. int i;
  7. double a1, b1, a2, b3, c1, c2, c3, c4, c5, c6, lx;
  8. double sum1 = 0.0, sum2 = 0.0, sum4 = 0.0;
  9. for (i = 0; i < n; ++i) {
  10. sum1 += x[i];
  11. sum2 += log(x[i]);
  12. }
  13. b1 = sum1 / n;
  14. a1 = sum2 / n;
  15. for (i = 0; i < n; ++i) {
  16. lx = log(x[i]);
  17. sum4 += (lx - a1) * (lx - a1);
  18. }
  19. a2 = sum4 / n;
  20. b3 = exp(a1 * 2 + a2) * (exp(a2) - 1);
  21. c1 = log(a2 / b3);
  22. c2 = (exp(a2 * 4) + exp(a2 * 3) * 2 - 4) / 4 - a2 + exp(a2) * 0.75;
  23. c3 = a2 * (exp(a2) * 2 - 1) * (exp(a2) * 2 - 1);
  24. c4 = (exp(a2) - 1) * 2 * (exp(a2) - 1);
  25. c5 = c3 / c4;
  26. if (c2 < c5) {
  27. #ifdef NOISY
  28. fprintf(stdout, " WARNING!!! STATISTICS FOR THE NEXT TEST WILL\n");
  29. fprintf(stdout, " NOT BE CALCULATED DUE TO SMALL LOGVARIANCE\n");
  30. #endif /* NOISY */
  31. y[0] = 999999999.;
  32. }
  33. else {
  34. c6 = sqrt(c2 - c5) * 2.0 * sqrt((double)n);
  35. y[0] = c1 / c6;
  36. }
  37. #ifdef NOISY
  38. fprintf(stdout, " TEST24 KT(LN) =%10.4f\n", y[0]);
  39. #endif /* NOISY */
  40. return y;
  41. }