-
Notifications
You must be signed in to change notification settings - Fork 41
/
circ_stats.m
63 lines (53 loc) · 1.33 KB
/
circ_stats.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
function stats = circ_stats(alpha, w, d)
%
% stats = circ_stats(alpha, w, d)
% Computes descriptive statistics for circular data.
%
% Input:
% alpha sample of angles in radians
% [w weightings 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]
%
% Output:
% stats structure containing descriptive statistics
%
% 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
alpha = alpha(:);
if nargin<2
w = ones(size(alpha));
end
if nargin < 3
d = 0;
end
% mean
stats.mean = circ_mean(alpha,w);
% median
if sum(w)==length(alpha)
if numel(alpha) > 1000
idx = randperm(numel(alpha));
idx = idx(1:1000);
else
idx = 1:numel(alpha);
end
stats.median = circ_median(alpha(idx));
else
stats.median = NaN;
end
% variance
stats.var = circ_var(alpha,w,d);
% standard deviation
[stats.std, stats.std0] = circ_std(alpha,w,d);
% skewness
[stats.skewness, stats.skewness0] = circ_skewness(alpha,w);
% kurtosis
[stats.kurtosis, stats.kurtosis0] = circ_kurtosis(alpha,w);
end