Home > atmlab > circular > circ_cmtest.m

circ_cmtest

PURPOSE ^

SYNOPSIS ^

function [pval med P] = circ_cmtest(varargin)

DESCRIPTION ^

 [pval, med, P] = circ_cmtest(alpha, idx)
 [pval, med, P] = circ_cmtest(alpha1, alpha2)
   Non parametric multi-sample test for equal medians. Similar to a
   Kruskal-Wallis test for linear data.

   H0: the s populations have equal medians
   HA: the s populations have unequal medians

   Input:
     alpha   angles in radians
     idx     indicates which population the respective angle in alpha
             comes from, 1:s

   Output:
     pval    p-value of the common median multi-sample test. Discard H0 if
             pval is small.
     med     best estimate of shared population median if H0 is not
             discarded at the 0.05 level and NaN otherwise.
     P       test statistic of the common median test.


 PHB 7/19/2009

 References:
   Fisher NI, 1995

 Circular Statistics Toolbox for Matlab

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

circ_cmtest.m

SOURCE CODE ^

0001 function [pval med P] = circ_cmtest(varargin)
0002 %
0003 % [pval, med, P] = circ_cmtest(alpha, idx)
0004 % [pval, med, P] = circ_cmtest(alpha1, alpha2)
0005 %   Non parametric multi-sample test for equal medians. Similar to a
0006 %   Kruskal-Wallis test for linear data.
0007 %
0008 %   H0: the s populations have equal medians
0009 %   HA: the s populations have unequal medians
0010 %
0011 %   Input:
0012 %     alpha   angles in radians
0013 %     idx     indicates which population the respective angle in alpha
0014 %             comes from, 1:s
0015 %
0016 %   Output:
0017 %     pval    p-value of the common median multi-sample test. Discard H0 if
0018 %             pval is small.
0019 %     med     best estimate of shared population median if H0 is not
0020 %             discarded at the 0.05 level and NaN otherwise.
0021 %     P       test statistic of the common median test.
0022 %
0023 %
0024 % PHB 7/19/2009
0025 %
0026 % References:
0027 %   Fisher NI, 1995
0028 %
0029 % Circular Statistics Toolbox for Matlab
0030 
0031 % By Philipp Berens, 2009
0032 % berens@tuebingen.mpg.de - www.kyb.mpg.de/~berens/circStat.html
0033 
0034 [alpha, idx] = processInput(varargin{:});
0035 
0036 % number of groups
0037 u = unique(idx);
0038 s = length(u);
0039 
0040 % number of samples
0041 N = length(idx);
0042 
0043 % total median
0044 med = circ_median(alpha);
0045 
0046 % compute relevant quantitites
0047 n = zeros(s,1); m = n;
0048 for t=1:s
0049   pidx = idx == u(t);
0050   n(t) = sum(pidx);
0051   
0052   d = circ_dist(alpha(pidx),med);
0053   
0054   m(t) = sum(d<0); 
0055 end
0056 
0057 if any(n<10)
0058   warning('Test not applicable. Sample size in at least one group to small.') %#ok<WNTAG>
0059 end
0060   
0061 
0062 M = sum(m);
0063 P = (N^2/(M*(N-M))) * sum(m.^2 ./ n) - N*M/(N-M);
0064 
0065 pval = 1 - chi2cdf(P,s-1);
0066 
0067 if pval < 0.05
0068   med = NaN;
0069 end
0070 
0071 
0072 
0073 
0074 function [alpha, idx] = processInput(varargin)
0075 
0076 if nargin==2 && sum(abs(round(varargin{2})-varargin{2}))>1e-5
0077   alpha1 = varargin{1}(:);
0078   alpha2 = varargin{2}(:);
0079   alpha = [alpha1; alpha2];
0080   idx = [ones(size(alpha1)); 2*ones(size(alpha2))];
0081 elseif nargin==2
0082   alpha = varargin{1}(:);
0083   idx = varargin{2}(:);
0084   if ~(size(idx,1)==size(alpha,1))
0085     error('Input dimensions do not match.')
0086   end
0087 else
0088   error('Invalid use of circ_wwtest. Type help circ_wwtest.')
0089 end
0090

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005