forked from circstat/circstat-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcirc_medtest.m
43 lines (36 loc) · 969 Bytes
/
circ_medtest.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
function pval = circ_medtest(alpha,md)
%
% pval = circ_medtest(alpha, md)
% Tests for significance of the median.
% H0: the population has median angle md
% HA: the population has not median angle md
%
% Input:
% alpha sample of angles in radians
% md median to test for
%
% Output:
% pval p-value
%
% PHB 3/19/2009
%
% References:
% Biostatistical Analysis, J. H. Zar, 27.4
%
% 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 length(md)>1
error('CIRCSTATS:circ_medtest:inputType', 'The hypothesized median md can only be a single value.');
end
n = length(alpha);
% compute deviations from median
d = circ_dist(alpha,md);
n1 = sum(d<0);
n2 = sum(d>0);
% compute p-value with binomial test
pval = sum(binopdf([0:min(n1,n2) max(n1,n2):n],n,0.5));
end