Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

circ_cmtest.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. function [pval med P] = circ_cmtest(varargin)
  2. %
  3. % [pval, med, P] = circ_cmtest(alpha, idx)
  4. % [pval, med, P] = circ_cmtest(alpha1, alpha2)
  5. % Non parametric multi-sample test for equal medians. Similar to a
  6. % Kruskal-Wallis test for linear data.
  7. %
  8. % H0: the s populations have equal medians
  9. % HA: the s populations have unequal medians
  10. %
  11. % Input:
  12. % alpha angles in radians
  13. % idx indicates which population the respective angle in alpha
  14. % comes from, 1:s
  15. %
  16. % Output:
  17. % pval p-value of the common median multi-sample test. Discard H0 if
  18. % pval is small.
  19. % med best estimate of shared population median if H0 is not
  20. % discarded at the 0.05 level and NaN otherwise.
  21. % P test statistic of the common median test.
  22. %
  23. %
  24. % PHB 7/19/2009
  25. %
  26. % References:
  27. % Fisher NI, 1995
  28. %
  29. % Circular Statistics Toolbox for Matlab
  30. % By Philipp Berens, 2009
  31. % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
  32. [alpha, idx] = processInput(varargin{:});
  33. % number of groups
  34. u = unique(idx);
  35. s = length(u);
  36. % number of samples
  37. N = length(idx);
  38. % total median
  39. med = circ_median(alpha);
  40. % compute relevant quantitites
  41. n = zeros(s,1); m = n;
  42. for t=1:s
  43. pidx = idx == u(t);
  44. n(t) = sum(pidx);
  45. d = circ_dist(alpha(pidx),med);
  46. m(t) = sum(d<0);
  47. end
  48. if any(n<10)
  49. warning('Test not applicable. Sample size in at least one group to small.') %#ok<WNTAG>
  50. end
  51. M = sum(m);
  52. P = (N^2/(M*(N-M))) * sum(m.^2 ./ n) - N*M/(N-M);
  53. pval = 1 - chi2cdf(P,s-1);
  54. if pval < 0.05
  55. med = NaN;
  56. end
  57. function [alpha, idx] = processInput(varargin)
  58. if nargin==2 && sum(abs(round(varargin{2})-varargin{2}))>1e-5
  59. alpha1 = varargin{1}(:);
  60. alpha2 = varargin{2}(:);
  61. alpha = [alpha1; alpha2];
  62. idx = [ones(size(alpha1)); 2*ones(size(alpha2))];
  63. elseif nargin==2
  64. alpha = varargin{1}(:);
  65. idx = varargin{2}(:);
  66. if ~(size(idx,1)==size(alpha,1))
  67. error('Input dimensions do not match.')
  68. end
  69. else
  70. error('Invalid use of circ_wwtest. Type help circ_wwtest.')
  71. end