forked from circstat/circstat-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circ_corrcl.m
50 lines (40 loc) · 1.08 KB
/
circ_corrcl.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
function [rho pval] = circ_corrcl(alpha, x)
%
% [rho pval ts] = circ_corrcc(alpha, x)
% Correlation coefficient between one circular and one linear random
% variable.
%
% Input:
% alpha sample of angles in radians
% x sample of linear random variable
%
% Output:
% rho correlation coefficient
% pval p-value
%
% References:
% Biostatistical Analysis, J. H. Zar, p. 651
%
% PHB 6/7/2008
%
% Circular Statistics Toolbox for Matlab
% By Philipp Berens, 2009
% [email protected] - www.kyb.mpg.de/~berens/circStat.html
if size(alpha,2) > size(alpha,1)
alpha = alpha';
end
if size(x,2) > size(x,1)
x = x';
end
if length(alpha)~=length(x)
error('Input dimensions do not match.')
end
n = length(alpha);
% compute correlation coefficent for sin and cos independently
rxs = corr(x,sin(alpha));
rxc = corr(x,cos(alpha));
rcs = corr(sin(alpha),cos(alpha));
% compute angular-linear correlation (equ. 27.47)
rho = sqrt((rxc^2 + rxs^2 - 2*rxc*rxs*rcs)/(1-rcs^2));
% compute pvalue
pval = 1 - chi2cdf(n*rho^2,2);