test.c 2.7 KB

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