PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/MatlabToolbox/CircStat2010e/circ_otest.m

http://sqwang-matlab.googlecode.com/
MATLAB | 81 lines | 50 code | 3 blank | 28 comment | 1 complexity | f47ebfaff8a5ceb0b7fbe89d88e5167b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. function [pval m] = circ_otest(alpha, sz, w)
  2. %
  3. % [pval, m] = circ_otest(alpha,sz,w)
  4. % Computes Omnibus or Hodges-Ajne test for non-uniformity of circular data.
  5. % H0: the population is uniformly distributed around the circle
  6. % HA: the population is not distributed uniformly around the circle
  7. %
  8. % Alternative to the Rayleigh and Rao's test. Works well for unimodal,
  9. % bimodal or multimodal data. If requirements of the Rayleigh test are
  10. % met, the latter is more powerful.
  11. %
  12. % Input:
  13. % alpha sample of angles in radians
  14. % [sz step size for evaluating distribution, default 1 degree
  15. % [w number of incidences in case of binned angle data]
  16. % Output:
  17. % pval p-value
  18. % m minimum number of samples falling in one half of the circle
  19. %
  20. % PHB 3/16/2009
  21. %
  22. % References:
  23. % Biostatistical Analysis, J. H. Zar
  24. % A bivariate sign test, J. L. Hodges et al., 1955
  25. % A simple test for uniformity of a circular distribution, B. Ajne, 1968
  26. %
  27. % Circular Statistics Toolbox for Matlab
  28. % By Philipp Berens, 2009
  29. % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
  30. if size(alpha,2) > size(alpha,1)
  31. alpha = alpha';
  32. end
  33. if nargin < 2 || isempty(sz)
  34. sz = circ_ang2rad(1);
  35. end
  36. if nargin < 3
  37. w = ones(size(alpha));
  38. else
  39. if length(alpha)~=length(w)
  40. error('Input length does not match.')
  41. end
  42. w =w(:);
  43. end
  44. alpha = mod(alpha,2*pi);
  45. n = sum(w);
  46. dg = 0:sz:pi;
  47. m1 = zeros(size(dg));
  48. m2 = zeros(size(dg));
  49. for i=1:length(dg)
  50. m1(i) = sum((alpha > dg(i) & alpha < pi + dg(i)).*w);
  51. m2(i) = n - m1(i);
  52. end
  53. m = min(min([m1;m2]));
  54. if n > 50
  55. % approximation by Ajne (1968)
  56. A = pi*sqrt(n) / 2 / (n-2*m);
  57. pval = sqrt(2*pi) / A * exp(-pi^2/8/A^2);
  58. else
  59. % exact formula by Hodges (1955)
  60. pval = 2^(1-n) * (n-2*m) * nchoosek(n,m);
  61. end