shapiro2.c 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "local_proto.h"
  5. /* this is actually the Weisberg-Bingham stat. I need to
  6. OCR the constants and implement this Cdhc_correctly */
  7. double *Cdhc_shapiro_francia(double *x, int n)
  8. {
  9. static double y[2];
  10. double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
  11. int i;
  12. if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
  13. fprintf(stderr, "Memory error in Cdhc_shapiro_francia\n");
  14. exit(EXIT_FAILURE);
  15. }
  16. for (i = 0; i < n; ++i)
  17. xcopy[i] = x[i];
  18. qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
  19. for (i = 0; i < n; ++i) {
  20. z = Cdhc_xinormal((i + 1 - 0.375) / (n + 0.25));
  21. suma += z * xcopy[i];
  22. sumb += z * z;
  23. sumc += xcopy[i];
  24. sumd += xcopy[i] * xcopy[i];
  25. }
  26. y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
  27. #ifdef NOISY
  28. fprintf(stdout, " TEST14 SF(N) =%10.4f\n", y[0]);
  29. #endif /* NOISY */
  30. free(xcopy);
  31. return y;
  32. } /* test14_ */