comparison m-toolbox/classes/@ao/spcorr.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % SPCORR calculate Spearman Rank-Order Correlation Coefficient
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % Description:
4 %
5 % SPCORR calculates Spearman Rank-Order Correlation Coefficient
6 %
7 % CALL: b = spcorr(a, pl)
8 %
9 % INPUT: a: are real valued AO. Number of input AOs should be >= 2.
10 % All the input AOs from the second are compared with the
11 % first one.
12 %
13 % OUTPUT: b: Spearman rank-order correlation coefficients. The
14 % procinfo of b contain further information as:
15 % - pValue: Probability associated with the calculated rs
16 % in the hypothesis that the correlation between the
17 % objects is zero.
18 % - TestRes: True or false on the basis of the test
19 % results. The null hypothesis for the test is that the two
20 % series are uncorrelated.
21 % TestRes = 0 => Do not reject the null hypothesis at
22 % significance level alpha. (pValue >= alpha)
23 % TestRes = 1 => Reject the null hypothesis at significance
24 % level alpha. (pValue < alpha)
25 %
26 % PARAMETERS:
27 %
28 % - ALPHA is the desired significance level. It represents the
29 % probability of rejecting the null hypothesis when it is true. The
30 % error done if the null hypothesis is rejected when it is true is
31 % called a Type I Error. Therefore, if the null hypothesis is true,
32 % alpha is the probability of a type I error. Default [0.05].
33 %
34 % NOTE:
35 % The statistic of Spearman rank-order correlation coefficient is
36 % well approximated by a Student t distribution. Hypothesis test is
37 % then based on such statistic.
38 %
39 % References:
40 % [1] W. H. Press, S. A. Teukolsky, W. T. Vetterling, B. P. Flannery,
41 % Numerical Recipes 3rd Edition: The Art of Scientific Computing,
42 % Cambridge University Press; 3 edition (September 10, 2007).
43 %
44 %
45 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'spcorr')">Parameters Description</a>
46 %
47 % VERSION: $Id: spcorr.m,v 1.5 2011/07/06 15:41:31 luigi Exp $
48 %
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50
51 function varargout = spcorr(varargin)
52
53 % Check if this is a call for parameters
54 if utils.helper.isinfocall(varargin{:})
55 varargout{1} = getInfo(varargin{3});
56 return
57 end
58
59 import utils.const.*
60 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
61
62 % Collect input variable names
63 in_names = cell(size(varargin));
64 for ii = 1:nargin,in_names{ii} = inputname(ii);end
65
66 % Collect all AOs and plists
67 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
68
69 if nargout == 0
70 error('### SPCORR cannot be used as a modifier. Please give an output variable.');
71 end
72
73 % check input
74 if numel(as)<2
75 error('### Number of input AOs must be larger or equal to two.')
76 end
77
78 % Collect input histories
79 inhists = [as.hist];
80
81 % Apply defaults to plist
82 pl = applyDefaults(getDefaultPlist, varargin{:});
83
84 % get parameters
85 alpha = find(pl, 'ALPHA');
86 if isa(alpha, 'ao')
87 alpha = alpha.y;
88 end
89
90 y1 = as(1).y;
91 bs = ao.initObjectWithSize(1, numel(as)-1);
92 % run over input aos
93 for ii=1:numel(bs)
94
95 y2 = as(ii+1).y;
96 if size(y1,1)~=size(y2,1)
97 % reshape
98 y2 = y2.';
99 end
100 [rs,pValue,TestRes] =...
101 utils.math.spcorr(y1, y2, alpha);
102
103 bs(ii) = ao(rs);
104 bs(ii).setName(sprintf('SpCorr(%s,%s)', as(1).name, as(ii+1).name));
105 plproc = plist(...
106 'TestRes',TestRes,...
107 'pValue',pValue);
108 bs(ii).setProcinfo(plproc);
109 bs(ii).addHistory(getInfo('None'), pl, [ao_invars(1) ao_invars(ii+1)], [inhists(1) inhists(ii+1)]);
110 end
111
112 % Set output
113 varargout = utils.helper.setoutputs(nargout, bs);
114
115 end
116
117
118 %--------------------------------------------------------------------------
119 % Get Info Object
120 %--------------------------------------------------------------------------
121 function ii = getInfo(varargin)
122 if nargin == 1 && strcmpi(varargin{1}, 'None')
123 sets = {};
124 pl = [];
125 else
126 sets = {'Default'};
127 pl = getDefaultPlist();
128 end
129 % Build info object
130 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: spcorr.m,v 1.5 2011/07/06 15:41:31 luigi Exp $', sets, pl);
131 end
132
133 %--------------------------------------------------------------------------
134 % Get Default Plist
135 %--------------------------------------------------------------------------
136 function plout = getDefaultPlist()
137 persistent pl;
138 if ~exist('pl', 'var') || isempty(pl)
139 pl = buildplist();
140 end
141 plout = pl;
142 end
143
144 function plo = buildplist()
145 plo = plist();
146
147 p = param({'ALPHA', ['ALPHA is the desired significance level. It represents'...
148 'the probability of rejecting the null hypothesis when it is true.'...
149 'The error done if the null hypothesis is rejected when it is true is'...
150 'called a Type I Error. Therefore, if the null hypothesis is true, alpha'...
151 'is the probability of a type I error.']}, paramValue.DOUBLE_VALUE(0.05));
152 plo.append(p);
153
154 end