Skip to content

Commit

Permalink
Merge pull request #17 from adehad/master
Browse files Browse the repository at this point in the history
Compiling fixes from other forks
  • Loading branch information
philippberens authored May 24, 2019
2 parents cdbb5ca + 43f1bcf commit be5b62c
Show file tree
Hide file tree
Showing 39 changed files with 267 additions and 199 deletions.
1 change: 0 additions & 1 deletion Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,3 @@
%
% Author:
% Philipp Berens & Marc J. Velasco, 2009

88 changes: 85 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,86 @@
circstat-matlab
===============
CircStat for Matlab
=======================

Matlab Circular Statistics Toolbox
Toolbox for circular statistics with Matlab.

## Authors:
Philipp Berens & Marc J. Velasco

*Email*: [email protected]

*Homepage*: http://www.kyb.tuebingen.mpg.de/~berens/circStat.html

## Contributors:
Tal Krasovsky

## Reference:
P. Berens, CircStat: A Matlab Toolbox for Circular Statistics, Journal of Statistical Software, Volume 31, Issue 10, 2009
http://www.jstatsoft.org/v31/i10

Please cite this paper when the provided code is used. See licensing terms for details.

## Contents:
- `circ_r` Resultant vector length
- `circ_mean` Mean direction of a sample of circular data
- `circ_axial` Mean direction for axial data
- `circ_median` Median direction of a sample of circular data
- `circ_std` Dispersion around the mean direction (std, mardia)
- `circ_var` Circular variance
- `circ_skewness` Circular skewness
- `circ_kurtosis` Circular kurtosis
- `circ_moment` Circular p-th moment
- `circ_dist` Distances around a circle
- `circ_dist2` Pairwise distances around a circle
- `circ_confmean` Confidence intervals for mean direction
- `circ_stats` Summary statistics

 
- `circ_rtest` Rayleigh's test for nonuniformity
- `circ_otest` Hodges-Ajne test (omnibus test) for nonuniformity
- `circ_raotest` Rao's spacing test for nonuniformity
- `circ_vtest` V-Test for nonuniformity with known mean direction
- `circ_medtest` Test for median angle
- `circ_mtest` One-sample test for specified mean direction
- `circ_wwtest` Multi-sample test for equal means, one-factor ANOVA
- `circ_hktest` Two-factor ANOVA
- `circ_ktest` Test for equal concentration parameter
- `circ_symtest` Test for symmetry around median angle
- `circ_kuipertest` Test whether two distributions are identical (like KS test)

 
- `circ_corrcc` Circular-circular correlation coefficient
- `circ_corrcl` Circular-linear correlation coefficient

 
- `circ_kappa` Compute concentration parameter of a von Mises distribution
- `circ_plot` Visualization for circular data
- `circ_clust` Simple clustering for circular data
- `circ_samplecdf` Evaluate CDF of a sample of angles

 
- `rad2ang` Convert radian to angular values
- `ang2rad` Convert angular to radian values

All functions take arguments in radians (expect for `ang2rad`). For a detailed description of arguments and outputs consult the help text in the files.

Since 2010, most functions for descriptive statistics can be used in Matlab style matrix computations. As a last argument, add the dimension along which you want to average. This changes the behavior slightly from previous relaeses, in that input is not reshaped anymore into vector format. Per default, all computations are performed columnwise (along dimension 1). If you prefer to use the old functions, for now they are contained in the subdirectory 'old'.

## References:
- E. Batschelet, Circular Statistics in Biology, Academic Press, 1981
- N.I. Fisher, Statistical analysis of circular data, Cambridge University Press, 1996
- S.R. Jammalamadaka et al., Topics in circular statistics, World Scientific, 2001
- J.H. Zar, Biostatistical Analysis, Prentice Hall, 1999


The implementation follows in most cases 'Biostatistical Analysis' and all referenced equations and tables are taken from this book, if not otherwise noted. In some cases, the other books were preferred for implementation was more straightforward for solutions presented there.

If you have suggestions, bugs or feature requests or want to contribute code, please email us.

## Disclaimer:
All functions in this toolbox were implemented with care and tested on the examples presented in 'Biostatistical Analysis' were possible. Nevertheless, they may contain errors or bugs, which may affect the outcome of your analysis. We do not take responsibility for any harm coming from using this toolbox, neither if it is caused by errors in the software nor if it is caused by its improper application. Please email us any bugs you find.

By Philipp Berens and Marc J. Velasco, 2009

[email protected] , [email protected] - www.kyb.mpg.de/~berens/circStat.html

Distributed under Open Source BSD License
3 changes: 2 additions & 1 deletion circ_ang2rad.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
% By Philipp Berens, 2009
% [email protected] - www.kyb.mpg.de/~berens/circStat.html

alpha = alpha * pi /180;
alpha = alpha * pi /180;
end
3 changes: 2 additions & 1 deletion circ_axial.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
% By Philipp Berens, 2009
% [email protected] - www.kyb.mpg.de/~berens/circStat.html

% TESTING GIT


if nargin < 2
p = 1;
end

alpha = mod(alpha*p,2*pi);
end
11 changes: 7 additions & 4 deletions circ_axialmean.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [r mu] = circ_axialmean(alphas, m, dim)
function [r, mu] = circ_axialmean(alphas, m, dim)
%
% mu = circ_axialmean(alpha, w)
% Computes the mean direction for circular data with axial
Expand All @@ -7,7 +7,7 @@
% Input:
% alpha sample of angles in radians
% [m axial correction (2,3,4,...)]
% [dim statistic computed along this dimension, 1]
% [dim statistic computed along this dimension, default: 1st non-singular dimension]
%
% Output:
% r mean resultant length
Expand All @@ -27,7 +27,10 @@
% Distributed under Open Source BSD License

if nargin < 3
dim = 1;
dim = find(size(alphas) > 1, 1, 'first');
if isempty(dim)
dim = 1;
end
end

if nargin < 2 || isempty(m)
Expand All @@ -38,4 +41,4 @@

r = abs(zbarm);
mu = angle(zbarm)/m;

end
7 changes: 3 additions & 4 deletions circ_clust.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,13 @@ function plotColor(x, y, c, varargin)
colors={'y', 'b', 'r', 'g', 'c', 'k', 'm'};

hold on;
for j=1:length(csmall);
for j=1:length(csmall)

ci = (c == csmall(j));
plot(x(ci), y(ci), strcat(pstring, colors{mod(j, length(colors))+1}), 'MarkerSize', ms);

end
if ~overlay, hold off; end
figure(figurenum)



end
end
9 changes: 5 additions & 4 deletions circ_cmtest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [pval med P] = circ_cmtest(varargin)
function [pval, med, P] = circ_cmtest(varargin)
%
% [pval, med, P] = circ_cmtest(alpha, idx)
% [pval, med, P] = circ_cmtest(alpha1, alpha2)
Expand Down Expand Up @@ -55,7 +55,8 @@
end

if any(n<10)
warning('Test not applicable. Sample size in at least one group to small.') %#ok<WNTAG>
warning('CIRCSTAT:circ_cmtest:sampleSizeTooSmall', ...
'Test not applicable. Sample size in at least one group too small.') %#ok<WNTAG>
end


Expand All @@ -67,7 +68,7 @@
if pval < 0.05
med = NaN;
end

end



Expand All @@ -87,4 +88,4 @@
else
error('Invalid use of circ_wwtest. Type help circ_wwtest.')
end

end
15 changes: 8 additions & 7 deletions circ_confmean.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
% [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]
% [dim compute along this dimension, default: 1st non-singular dimension]
%
% Output:
% t mean +- d yields upper/lower (1-xi)% confidence limit
Expand All @@ -28,7 +28,10 @@
% [email protected] - www.kyb.mpg.de/~berens/circStat.html

if nargin < 5
dim = 1;
dim = find(size(alpha) > 1, 1, 'first');
if isempty(dim)
dim = 1;
end
end

if nargin < 4 || isempty(d)
Expand Down Expand Up @@ -67,13 +70,11 @@
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.');
warning('CIRCSTAT:circ_confmean:requirementsNotMet', ...
'Requirements for confidence levels not met.');
end
end

% apply final transform
t = acos(t./R);




end
6 changes: 3 additions & 3 deletions circ_corrcc.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [rho pval] = circ_corrcc(alpha1, alpha2)
function [rho, pval] = circ_corrcc(alpha1, alpha2)
%
% [rho pval ts] = circ_corrcc(alpha1, alpha2)
% [rho pval] = circ_corrcc(alpha1, alpha2)
% Circular correlation coefficient for two circular random variables.
%
% Input:
Expand Down Expand Up @@ -50,4 +50,4 @@

ts = sqrt((n * l20 * l02)/l22) * rho;
pval = 2 * (1 - normcdf(abs(ts)));

end
6 changes: 3 additions & 3 deletions circ_corrcl.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function [rho pval] = circ_corrcl(alpha, x)
function [rho, pval] = circ_corrcl(alpha, x)
%
% [rho pval ts] = circ_corrcc(alpha, x)
% [rho pval] = circ_corrcc(alpha, x)
% Correlation coefficient between one circular and one linear random
% variable.
%
Expand Down Expand Up @@ -47,4 +47,4 @@

% compute pvalue
pval = 1 - chi2cdf(n*rho^2,2);

end
3 changes: 2 additions & 1 deletion circ_dist.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
error('Input dimensions do not match.')
end

r = angle(exp(1i*x)./exp(1i*y));
r = angle(exp(1i*x)./exp(1i*y));
end
5 changes: 3 additions & 2 deletions circ_dist2.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function r = circ_dist2(x,y)
%
% r = circ_dist(alpha, beta)
% r = circ_dist2(alpha, beta)
% All pairwise difference x_i-y_j around the circle computed efficiently.
%
% Input:
Expand Down Expand Up @@ -33,4 +33,5 @@
end

r = angle(repmat(exp(1i*x),1,length(y)) ...
./ repmat(exp(1i*y'),length(x),1));
./ repmat(exp(1i*y'),length(x),1));
end
14 changes: 1 addition & 13 deletions circ_hktest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function [pval table] = circ_hktest(alpha, idp, idq, inter, fn)
function [pval, table] = circ_hktest(alpha, idp, idq, inter, fn)

%
% [pval, stats] = circ_hktest(alpha, idp, idq, inter, fn)
Expand Down Expand Up @@ -238,16 +238,4 @@
end

end


end










1 change: 1 addition & 0 deletions circ_kappa.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@
kappa = (N-1)^3*kappa/(N^3+N);
end
end
end
11 changes: 3 additions & 8 deletions circ_ktest.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
rbar = (R1+R2)/(n1+n2);

if rbar < .7
warning('resultant vector length should be > 0.7') %#ok<WNTAG>
warning('CIRCSTAT:circ_ktest:vectorTooShort', ...
'Resultant vector length should be > 0.7') %#ok<WNTAG>
end

% calculate test statistic
Expand All @@ -50,10 +51,4 @@
f = 1/f;
pval = 2*(1-fcdf(f, n2, n1));
end







end
Loading

0 comments on commit be5b62c

Please sign in to comment.