circ_raotest.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. function [p U UC] = circ_raotest(alpha)
  2. % [p U UC] = circ_raotest(alpha)
  3. % Calculates Rao's spacing test by comparing distances between points on
  4. % a circle to those expected from a uniform distribution.
  5. %
  6. % H0: Data is distributed uniformly around the circle.
  7. % H1: Data is not uniformly distributed around the circle.
  8. %
  9. % Alternative to the Rayleigh test and the Omnibus test. Less powerful
  10. % than the Rayleigh test when the distribution is unimodal on a global
  11. % scale but uniform locally.
  12. %
  13. % Due to the complexity of the distributioin of the test statistic, we
  14. % resort to the tables published by
  15. % Russell, Gerald S. and Levitin, Daniel J.(1995)
  16. % 'An expanded table of probability values for rao's spacing test'
  17. % Communications in Statistics - Simulation and Computation
  18. % Therefore the reported p-value is the smallest alpha level at which the
  19. % test would still be significant. If the test is not significant at the
  20. % alpha=0.1 level, we return the critical value for alpha = 0.05 and p =
  21. % 0.5.
  22. %
  23. % Input:
  24. % alpha sample of angles
  25. %
  26. % Output:
  27. % p smallest p-value at which test would be significant
  28. % U computed value of the test-statistic u
  29. % UC critical value of the test statistic at sig-level
  30. %
  31. %
  32. % References:
  33. % Batschelet, 1981, Sec 4.6
  34. %
  35. % Circular Statistics Toolbox for Matlab
  36. % By Philipp Berens, 2009
  37. % berens@tuebingen.mpg.de
  38. alpha = alpha(:);
  39. % for the purpose of the test, convert to angles
  40. alpha = circ_rad2ang(alpha);
  41. n = length(alpha);
  42. alpha = sort(alpha);
  43. % compute test statistic
  44. U = 0;
  45. lambda = 360/n;
  46. for j = 1:n-1
  47. ti = alpha(j+1) - alpha(j);
  48. U = U + abs(ti - lambda);
  49. end
  50. tn = (360 - alpha(n) + alpha(1));
  51. U = U + abs(tn-lambda);
  52. U = (1/2)*U;
  53. % get critical value from table
  54. [p UC] = getVal(n,U);
  55. function [p UC] = getVal(N, U)
  56. % Table II from Russel and Levitin, 1995
  57. alpha = [0.001, .01, .05, .10];
  58. table = [ 4 247.32, 221.14, 186.45, 168.02;
  59. 5 245.19, 211.93, 183.44, 168.66;
  60. 6 236.81, 206.79, 180.65, 166.30;
  61. 7 229.46, 202.55, 177.83, 165.05;
  62. 8 224.41, 198.46, 175.68, 163.56;
  63. 9 219.52, 195.27, 173.68, 162.36;
  64. 10 215.44, 192.37, 171.98, 161.23;
  65. 11 211.87, 189.88, 170.45, 160.24;
  66. 12 208.69, 187.66, 169.09, 159.33;
  67. 13 205.87, 185.68, 167.87, 158.50;
  68. 14 203.33, 183.90, 166.76, 157.75;
  69. 15 201.04, 182.28, 165.75, 157.06;
  70. 16 198.96, 180.81, 164.83, 156.43;
  71. 17 197.05, 179.46, 163.98, 155.84;
  72. 18 195.29, 178.22, 163.20, 155.29;
  73. 19 193.67, 177.08, 162.47, 154.78;
  74. 20 192.17, 176.01, 161.79, 154.31;
  75. 21 190.78, 175.02, 161.16, 153.86;
  76. 22 189.47, 174.10, 160.56, 153.44;
  77. 23 188.25, 173.23, 160.01, 153.05;
  78. 24 187.11, 172.41, 159.48, 152.68;
  79. 25 186.03, 171.64, 158.99, 152.32;
  80. 26 185.01, 170.92, 158.52, 151.99;
  81. 27 184.05, 170.23, 158.07, 151.67;
  82. 28 183.14, 169.58, 157.65, 151.37;
  83. 29 182.28, 168.96, 157.25, 151.08;
  84. 30 181.45, 168.38, 156.87, 150.80;
  85. 35 177.88, 165.81, 155.19, 149.59;
  86. 40 174.99, 163.73, 153.82, 148.60;
  87. 45 172.58, 162.00, 152.68, 147.76;
  88. 50 170.54, 160.53, 151.70, 147.05;
  89. 75 163.60, 155.49, 148.34, 144.56;
  90. 100 159.45, 152.46, 146.29, 143.03;
  91. 150 154.51, 148.84, 143.83, 141.18;
  92. 200 151.56, 146.67, 142.35, 140.06;
  93. 300 148.06, 144.09, 140.57, 138.71;
  94. 400 145.96, 142.54, 139.50, 137.89;
  95. 500 144.54, 141.48, 138.77, 137.33;
  96. 600 143.48, 140.70, 138.23, 136.91;
  97. 700 142.66, 140.09, 137.80, 136.59;
  98. 800 142.00, 139.60, 137.46, 136.33;
  99. 900 141.45, 139.19, 137.18, 136.11;
  100. 1000 140.99, 138.84, 136.94, 135.92 ];
  101. ridx = find(table(:,1)>=N,1);
  102. cidx = find(table(ridx,2:end)<U,1);
  103. if ~isempty(cidx)
  104. UC = table(ridx,cidx+1);
  105. p = alpha(cidx);
  106. else
  107. UC = table(ridx,end-1);
  108. p = .5;
  109. end