circ_ktest.m 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. function [pval, f] = circ_ktest(alpha1, alpha2)
  2. % [pval, f] = circ_ktest(alpha1, alpha2)
  3. %
  4. % A parametric two-sample test to determine whether two concentration
  5. % parameters are different.
  6. %
  7. % H0: The two concentration parameters are equal.
  8. % HA: The two concentration parameters are different.
  9. %
  10. % Input:
  11. % alpha1 fist sample (in radians)
  12. % alpha2 second sample (in radians)
  13. %
  14. % Output:
  15. % pval p-value that samples have different concentrations
  16. % f f-statistic calculated
  17. %
  18. % Assumptions: both samples are drawn from von Mises type distributions
  19. % and their joint resultant vector length should be > .7
  20. %
  21. % References:
  22. % Batschelet, 1980, section 6.9, pg 122-124
  23. %
  24. % Circular Statistics Toolbox for Matlab
  25. % By Marc J. Velasco, 2009
  26. % velasco@ccs.fau.edu
  27. alpha1 = alpha1(:);
  28. alpha2 = alpha2(:);
  29. n1 = length(alpha1);
  30. n2 = length(alpha2);
  31. R1 = n1*circ_r(alpha1);
  32. R2 = n2*circ_r(alpha2);
  33. % make sure that rbar > .7
  34. rbar = (R1+R2)/(n1+n2);
  35. if rbar < .7
  36. warning('resultant vector length should be > 0.7') %#ok<WNTAG>
  37. end
  38. % calculate test statistic
  39. f = ((n2-1)*(n1-R1))/((n1-1)*(n2-R2));
  40. if f > 1
  41. pval = 2*(1-fcdf(f, n1, n2));
  42. else
  43. f = 1/f;
  44. pval = 2*(1-fcdf(f, n2, n1));
  45. end