forked from circstat/circstat-matlab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
circ_confmean.m
79 lines (66 loc) · 2.04 KB
/
circ_confmean.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function t = circ_confmean(alpha, xi, w, d, dim)
%
% t = circ_mean(alpha, xi, w, d, dim)
% Computes the confidence limits on the mean for circular data.
%
% Input:
% alpha sample of angles in radians
% [xi (1-xi)-confidence limits are computed, default 0.05]
% [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 compute along this dimension, default is 1]
%
% Output:
% t mean +- d yields upper/lower (1-xi)% confidence limit
%
% 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
if nargin < 5
dim = 1;
end
if nargin < 4 || isempty(d)
% per default do not apply correct for binned data
d = 0;
end
if nargin < 3 || isempty(w)
% if no specific weighting has been specified
% assume no binning has taken place
w = ones(size(alpha));
else
if size(w,2) ~= size(alpha,2) || size(w,1) ~= size(alpha,1)
error('Input dimensions do not match');
end
end
% set confidence limit size to default
if nargin < 2 || isempty(xi)
xi = 0.05;
end
% compute ingredients for conf. lim.
r = circ_r(alpha,w,d,dim);
n = sum(w,dim);
R = n.*r;
c2 = chi2inv((1-xi),1);
% check for resultant vector length and select appropriate formula
t = zeros(size(r));
for i = 1:numel(r)
if r(i) < .9 && r(i) > sqrt(c2/2/n(i))
t(i) = sqrt((2*n(i)*(2*R(i)^2-n(i)*c2))/(4*n(i)-c2)); % equ. 26.24
elseif r(i) >= .9
t(i) = sqrt(n(i)^2-(n(i)^2-R(i)^2)*exp(c2/n(i))); % equ. 26.25
else
t(i) = NaN;
warning('Requirements for confidence levels not met.');
end
end
% apply final transform
t = acos(t./R);