test.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <grass/gis.h>
  4. #include <grass/cdhc.h>
  5. #include "local_proto.h"
  6. int main(int argc, char **argv)
  7. {
  8. double z[1000];
  9. double *w;
  10. int n = 0;
  11. while (scanf("%lf", &z[n++]) != EOF) ;
  12. n--;
  13. fprintf(stdout, "TESTS:\n");
  14. fprintf(stdout, "N: %d\n", n);
  15. fprintf(stdout, "Moments \\sqrt{b_1} and b_2: ");
  16. w = Cdhc_omnibus_moments(z, n);
  17. fprintf(stdout, "%g %g\n", w[0], w[1]);
  18. fprintf(stdout, "Geary's a-statistic & an approx. normal: ");
  19. w = Cdhc_geary_test(z, n);
  20. fprintf(stdout, "%g %g\n", w[0], w[1]);
  21. fprintf(stdout, "Cdhc_extreme normal deviates: ");
  22. w = Cdhc_extreme(z, n);
  23. fprintf(stdout, "%g %g\n", w[0], w[1]);
  24. fprintf(stdout, "D'Agostino's D & an approx. normal: ");
  25. w = Cdhc_dagostino_d(z, n);
  26. fprintf(stdout, "%g %g\n", w[0], w[1]);
  27. fprintf(stdout, "Kuiper's V (regular & modified for normality): ");
  28. w = Cdhc_kuipers_v(z, n);
  29. fprintf(stdout, "%g %g\n", w[1], w[0]);
  30. fprintf(stdout, "Watson's U^2 (regular & modified for normality): ");
  31. w = Cdhc_watson_u2(z, n);
  32. fprintf(stdout, "%g %g\n", w[1], w[0]);
  33. fprintf(stdout, "Durbin's Exact Test (modified Kolmogorov): ");
  34. w = Cdhc_durbins_exact(z, n);
  35. fprintf(stdout, "%g\n", w[0]);
  36. fprintf(stdout,
  37. "Anderson-Darling's A^2 (regular & modified for normality): ");
  38. w = Cdhc_anderson_darling(z, n);
  39. fprintf(stdout, "%g %g\n", w[1], w[0]);
  40. fprintf(stdout,
  41. "Cramer-Von Mises W^2(regular & modified for normality): ");
  42. w = Cdhc_cramer_von_mises(z, n);
  43. fprintf(stdout, "%g %g\n", w[1], w[0]);
  44. fprintf(stdout,
  45. "Kolmogorov-Smirnov's D (regular & modified for normality): ");
  46. w = Cdhc_kolmogorov_smirnov(z, n);
  47. fprintf(stdout, "%g %g\n", w[1], w[0]);
  48. fprintf(stdout, "Chi-Square stat (equal probability classes) and d.f.: ");
  49. w = Cdhc_chi_square(z, n);
  50. fprintf(stdout, "%g %d\n", w[0], (int)w[1]);
  51. if (n > 50) {
  52. G_warning("Shapiro-Wilk's W cannot be used for n > 50");
  53. if (n < 99)
  54. G_message("Use Weisberg-Binghams's W''");
  55. }
  56. else {
  57. fprintf(stdout, "Shapiro-Wilk W: ");
  58. w = Cdhc_shapiro_wilk(z, n);
  59. fprintf(stdout, "%g\n", w[0]);
  60. }
  61. if (n > 99 || n < 50)
  62. G_warning
  63. ("Weisberg-Bingham's W'' cannot be used for n < 50 or n > 99");
  64. else {
  65. fprintf(stdout, "Weisberg-Bingham's W'': ");
  66. w = Cdhc_weisberg_bingham(z, n);
  67. fprintf(stdout, "%g\n", w[0]);
  68. }
  69. if (n > 2000)
  70. G_warning("Royston only extended Shapiro-Wilk's W up to n = 2000");
  71. else {
  72. fprintf(stdout, "Shapiro-Wilk W'': ");
  73. w = Cdhc_royston(z, n);
  74. fprintf(stdout, "%g\n", w[0]);
  75. }
  76. fprintf(stdout, "Kotz' T'_f (Lognormality vs. Normality): ");
  77. w = Cdhc_kotz_families(z, n);
  78. fprintf(stdout, "%g\n", w[0]);
  79. return EXIT_SUCCESS;
  80. }