r = circ_r(alpha, w, d) Computes mean resultant vector length for circular data. Input: alpha sample of angles in radians [w number of incidences in case of binned angle data] [d spacing of bin centers for binned data, if supplied correction factor is used to correct for bias in estimation of r, in radians (!)] [dim compute along this dimension, default is 1] If dim argument is specified, all other optional arguments can be left empty: circ_r(alpha, [], [], dim) Output: r mean resultant length PHB 7/6/2008 References: Statistical analysis of circular data, N.I. Fisher Topics in circular statistics, S.R. Jammalamadaka et al. Biostatistical Analysis, J. H. Zar Circular Statistics Toolbox for Matlab
0001 function r = circ_r(alpha, w, d, dim) 0002 % r = circ_r(alpha, w, d) 0003 % Computes mean resultant vector length for circular data. 0004 % 0005 % Input: 0006 % alpha sample of angles in radians 0007 % [w number of incidences in case of binned angle data] 0008 % [d spacing of bin centers for binned data, if supplied 0009 % correction factor is used to correct for bias in 0010 % estimation of r, in radians (!)] 0011 % [dim compute along this dimension, default is 1] 0012 % 0013 % If dim argument is specified, all other optional arguments can be 0014 % left empty: circ_r(alpha, [], [], dim) 0015 % 0016 % Output: 0017 % r mean resultant length 0018 % 0019 % PHB 7/6/2008 0020 % 0021 % References: 0022 % Statistical analysis of circular data, N.I. Fisher 0023 % Topics in circular statistics, S.R. Jammalamadaka et al. 0024 % Biostatistical Analysis, J. H. Zar 0025 % 0026 % Circular Statistics Toolbox for Matlab 0027 0028 % By Philipp Berens, 2009 0029 % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html 0030 0031 if nargin < 4 0032 dim = 1; 0033 end 0034 0035 if nargin < 2 || isempty(w) 0036 % if no specific weighting has been specified 0037 % assume no binning has taken place 0038 w = ones(size(alpha)); 0039 else 0040 if size(w,2) ~= size(alpha,2) || size(w,1) ~= size(alpha,1) 0041 error('Input dimensions do not match'); 0042 end 0043 end 0044 0045 if nargin < 3 || isempty(d) 0046 % per default do not apply correct for binned data 0047 d = 0; 0048 end 0049 0050 % compute weighted sum of cos and sin of angles 0051 r = sum(w.*exp(1i*alpha),dim); 0052 0053 % obtain length 0054 r = abs(r)./sum(w,dim); 0055 0056 % for data with known spacing, apply correction factor to correct for bias 0057 % in the estimation of r (see Zar, p. 601, equ. 26.16) 0058 if d ~= 0 0059 c = d/2/sin(d/2); 0060 r = c*r; 0061 end 0062