Home > atmlab > circular > circ_mean.m

circ_mean

PURPOSE ^

SYNOPSIS ^

function [mu ul ll] = circ_mean(alpha, w, dim)

DESCRIPTION ^

 mu = circ_mean(alpha, w)
   Computes the mean direction for circular data.

   Input:
     alpha    sample of angles in radians
     [w        weightings in case of binned angle data]
     [dim  compute along this dimension, default is 1]

     If dim argument is specified, all other optional arguments can be
     left empty: circ_mean(alpha, [], dim)

   Output:
     mu        mean direction
     ul    upper 95% confidence limit
     ll    lower 95% confidence limit 

 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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

circ_mean.m

SOURCE CODE ^

0001 function [mu ul ll] = circ_mean(alpha, w, dim)
0002 %
0003 % mu = circ_mean(alpha, w)
0004 %   Computes the mean direction for circular data.
0005 %
0006 %   Input:
0007 %     alpha    sample of angles in radians
0008 %     [w        weightings in case of binned angle data]
0009 %     [dim  compute along this dimension, default is 1]
0010 %
0011 %     If dim argument is specified, all other optional arguments can be
0012 %     left empty: circ_mean(alpha, [], dim)
0013 %
0014 %   Output:
0015 %     mu        mean direction
0016 %     ul    upper 95% confidence limit
0017 %     ll    lower 95% confidence limit
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 < 3
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 % compute weighted sum of cos and sin of angles
0046 r = sum(w.*exp(1i*alpha),dim);
0047 
0048 % obtain mean by
0049 mu = angle(r);
0050 
0051 % confidence limits if desired
0052 if nargout > 1
0053   t = circ_confmean(alpha,0.05,w, [], dim);
0054   ul = mu + t;
0055   ll = mu - t;
0056 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005