circ_kappa.m 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function kappa = circ_kappa(alpha,w)
  2. %
  3. % kappa = circ_kappa(alpha,[w])
  4. % Computes an approximation to the ML estimate of the concentration
  5. % parameter kappa of the von Mises distribution.
  6. %
  7. % Input:
  8. % alpha angles in radians OR alpha is length resultant
  9. % [w number of incidences in case of binned angle data]
  10. %
  11. % Output:
  12. % kappa estimated value of kappa
  13. %
  14. % References:
  15. % Statistical analysis of circular data, Fisher, equation p. 88
  16. %
  17. % Circular Statistics Toolbox for Matlab
  18. % By Philipp Berens, 2009
  19. % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
  20. alpha = alpha(:);
  21. if nargin<2
  22. % if no specific weighting has been specified
  23. % assume no binning has taken place
  24. w = ones(size(alpha));
  25. else
  26. if size(w,2) > size(w,1)
  27. w = w';
  28. end
  29. end
  30. N = length(alpha);
  31. if N>1
  32. R = circ_r(alpha,w);
  33. else
  34. R = alpha;
  35. end
  36. if R < 0.53
  37. kappa = 2*R + R^3 + 5*R^5/6;
  38. elseif R>=0.53 && R<0.85
  39. kappa = -.4 + 1.39*R + 0.43/(1-R);
  40. else
  41. kappa = 1/(R^3 - 4*R^2 + 3*R);
  42. end
  43. if N<15 && N>1
  44. if kappa < 2
  45. kappa = max(kappa-2*(N*kappa)^-1,0);
  46. else
  47. kappa = (N-1)^3*kappa/(N^3+N);
  48. end
  49. end