-
Notifications
You must be signed in to change notification settings - Fork 3
/
circ_rtest2.m
74 lines (55 loc) · 1.89 KB
/
circ_rtest2.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
54
55
56
57
58
59
60
61
62
63
64
65
function [pval z] = circ_rtest2(varargin)
%
% [pval, z] = circ_rtest(alpha,w,d,dim)
% Computes Rayleigh test for non-uniformity of circular data.
% H0: the population is uniformly distributed around the circle
% HA: the populatoin is not distributed uniformly around the circle
% Assumption: the distribution has maximally one mode and the data is
% sampled from a von Mises distribution!
%
% 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 dimension along which to calculate the Rayleigh's Z test
%
% Output:
% pval p-value of Rayleigh's test
% z value of the z-statistic
%
% 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
% By Philipp Berens, 2009
% [email protected] - www.kyb.mpg.de/~berens/circStat.html
% BV: JUL-16-2014--> support for matrices
alpha=varargin{1};
if vararginchk(varargin,2); w=varargin{2}; else w=[]; end
if vararginchk(varargin,3); d=varargin{3}; else d=[]; end
if vararginchk(varargin,4); dim=varargin{4}; else dim=1; end
r = circ_r(alpha,w,d,dim);
if isempty(w)
n = size(alpha,dim);
else
n = sum(w);
end
% compute Rayleigh's R (equ. 27.1)
R = n*r;
% compute Rayleigh's z (equ. 27.2)
z = R.^2 / n;
% compute p value using approxation in Zar, p. 617
pval = exp(sqrt(1+4*n+4*(n^2-R.^2))-(1+2*n));
% outdated version:
% compute the p value using an approximation from Fisher, p. 70
% pval = exp(-z);
% if n < 50
% pval = pval * (1 + (2*z - z^2) / (4*n) - ...
% (24*z - 132*z^2 + 76*z^3 - 9*z^4) / (288*n^2));
% end