forked from circstat/circstat-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circ_corrcc.m
53 lines (44 loc) · 1.37 KB
/
circ_corrcc.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function [rho pval] = circ_corrcc(alpha1, alpha2)
%
% [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
% By Philipp Berens, 2009
% [email protected] - www.kyb.mpg.de/~berens/circStat.html
if size(alpha1,2) > size(alpha1,1)
alpha1 = alpha1';
end
if size(alpha2,2) > size(alpha2,1)
alpha2 = alpha2';
end
if length(alpha1)~=length(alpha2)
error('Input dimensions do not match.')
end
% compute mean directions
n = length(alpha1);
alpha1_bar = circ_mean(alpha1);
alpha2_bar = circ_mean(alpha2);
% compute correlation coeffcient from p. 176
num = sum(sin(alpha1 - alpha1_bar) .* sin(alpha2 - alpha2_bar));
den = sqrt(sum(sin(alpha1 - alpha1_bar).^2) .* sum(sin(alpha2 - alpha2_bar).^2));
rho = num / den;
% compute pvalue
l20 = mean(sin(alpha1 - alpha1_bar).^2);
l02 = mean(sin(alpha2 - alpha2_bar).^2);
l22 = mean((sin(alpha1 - alpha1_bar).^2) .* (sin(alpha2 - alpha2_bar).^2));
ts = sqrt((n * l20 * l02)/l22) * rho;
pval = 2 * (1 - normcdf(abs(ts)));