watsonue.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "local_proto.h"
  5. double *watson_u2_exp (double *x, int n)
  6. {
  7. double *xcopy, mean = 0.0, zbar = 0.0, fn2, fx, sum4 = 0.0;
  8. static double y[2];
  9. int i;
  10. if ((xcopy = (double *) malloc (n * sizeof (double))) == NULL)
  11. {
  12. fprintf (stderr, "Memory error in watson_u2_exp\n");
  13. exit (EXIT_FAILURE);
  14. }
  15. for (i = 0; i < n; ++i)
  16. {
  17. xcopy[i] = x[i];
  18. mean += x[i];
  19. }
  20. mean /= n;
  21. qsort (xcopy, n, sizeof (double), dcmp);
  22. for (i = 0; i < n; ++i)
  23. {
  24. fx = 1 - exp (-xcopy[i] / mean);
  25. if (fx <= 1e-5)
  26. fx = 1e-5;
  27. if (fx >= 0.99999)
  28. fx = 0.99999;
  29. /* sum3 += 2 * (i + 1) * (log (fx) + log (1.0 - fx[n - i - 1])); */
  30. fn2 = (2.0 * i + 1.0) / (2.0 * n);
  31. sum4 += (fx - fn2) * (fx - fn2);
  32. fn2 = (2.0 * (i + 1) - 1.0) / (2.0 * n);
  33. zbar += fx;
  34. }
  35. zbar /= n;
  36. y[0] = (1.0 / (n * 12) + sum4) - n * (zbar - .5) * (zbar - .5);
  37. y[0] *= 1.0 + 0.16 / n;
  38. #ifdef NOISY
  39. fprintf (stdout," TEST19 WU2(E) =%10.4f\n", y[0]);
  40. #endif /* NOISY */
  41. free (xcopy);
  42. return y;
  43. }