circ_medtest.m 918 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function pval = circ_medtest(alpha,md)
  2. %
  3. % [pval, z] = circ_medtest(alpha,w)
  4. % Tests for significance of the median.
  5. % H0: the population has median angle md
  6. % HA: the population has not median angle md
  7. %
  8. % Input:
  9. % alpha sample of angles in radians
  10. % md median to test for
  11. %
  12. % Output:
  13. % pval p-value
  14. %
  15. % PHB 3/19/2009
  16. %
  17. % References:
  18. % Biostatistical Analysis, J. H. Zar, 27.4
  19. %
  20. % Circular Statistics Toolbox for Matlab
  21. % By Philipp Berens, 2009
  22. % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
  23. if size(alpha,2) > size(alpha,1)
  24. alpha = alpha';
  25. end
  26. if length(md)>1
  27. error('Median can only be a single value.')
  28. end
  29. n = length(alpha);
  30. % compute deviations from median
  31. d = circ_dist(alpha,md);
  32. n1 = sum(d<0);
  33. n2 = sum(d>0);
  34. % compute p-value with binomial test
  35. pval = sum(binopdf([0:min(n1,n2) max(n1,n2):n],n,0.5));