Home > atmlab > circular > circ_corrcc.m

circ_corrcc

PURPOSE ^

SYNOPSIS ^

function [rho pval] = circ_corrcc(alpha1, alpha2)

DESCRIPTION ^

 [rho pval ts] = circ_corrcc(alpha1, alpha2)
   Circular correlation coefficient for two circular random variables.

   Input:
     alpha1    sample of angles in radians
     alpha2    sample of angles in radians

   Output:
     rho     correlation coefficient
     pval    p-value

 References:
   Topics in circular statistics, S.R. Jammalamadaka et al., p. 176

 PHB 6/7/2008

 Circular Statistics Toolbox for Matlab

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

circ_corrcc.m

SOURCE CODE ^

0001 function [rho pval] = circ_corrcc(alpha1, alpha2)
0002 %
0003 % [rho pval ts] = circ_corrcc(alpha1, alpha2)
0004 %   Circular correlation coefficient for two circular random variables.
0005 %
0006 %   Input:
0007 %     alpha1    sample of angles in radians
0008 %     alpha2    sample of angles in radians
0009 %
0010 %   Output:
0011 %     rho     correlation coefficient
0012 %     pval    p-value
0013 %
0014 % References:
0015 %   Topics in circular statistics, S.R. Jammalamadaka et al., p. 176
0016 %
0017 % PHB 6/7/2008
0018 %
0019 % Circular Statistics Toolbox for Matlab
0020 
0021 % By Philipp Berens, 2009
0022 % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
0023 
0024 if size(alpha1,2) > size(alpha1,1)
0025     alpha1 = alpha1';
0026 end
0027 
0028 if size(alpha2,2) > size(alpha2,1)
0029     alpha2 = alpha2';
0030 end
0031 
0032 if length(alpha1)~=length(alpha2)
0033   error('Input dimensions do not match.')
0034 end
0035 
0036 % compute mean directions
0037 n = length(alpha1);
0038 alpha1_bar = circ_mean(alpha1);
0039 alpha2_bar = circ_mean(alpha2);
0040 
0041 % compute correlation coeffcient from p. 176
0042 num = sum(sin(alpha1 - alpha1_bar) .* sin(alpha2 - alpha2_bar));
0043 den = sqrt(sum(sin(alpha1 - alpha1_bar).^2) .* sum(sin(alpha2 - alpha2_bar).^2));
0044 rho = num / den;    
0045 
0046 % compute pvalue
0047 l20 = mean(sin(alpha1 - alpha1_bar).^2);
0048 l02 = mean(sin(alpha2 - alpha2_bar).^2);
0049 l22 = mean((sin(alpha1 - alpha1_bar).^2) .* (sin(alpha2 - alpha2_bar).^2));
0050 
0051 ts = sqrt((n * l20 * l02)/l22) * rho;
0052 pval = 2 * (1 - normcdf(abs(ts)));
0053

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