IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
report_sovalues_comparison.m
Go to the documentation of this file.
1 %> @brief Comparison and p-values tables
3  properties
4  %> ={[Inf, 0, 0], [1, 2]}
5  %> @sa sovalues.m
6  dimspec = {[0, 0], [1, 2]};
7 
8  %> =1. Whether to generate the p-values tables
9  flag_ptable = 1;
10 
11  %> ={'rates', 'times3'}
12  %>
13  %> The first element will be assumed to be the classification rate and used to choose one row as best
14  names = {'rates', 'times3'};
15 
16  %> vectorcomp_ttest_right() with no logtake. vectorcomp object used tor the p-values tables
17  vectorcomp = [];
18 
19  %> Maximum number of table rows
20  maxrows = 20;
21  end;
22 
23  methods
24  function o = report_sovalues_comparison()
25  o.classtitle = 'Flat comparison table';
26  o.inputclass = 'sovalues';
27  o.flag_params = 1;
28  end;
29  end;
30 
31  methods(Access=protected)
32  function out = do_use(o, sov)
33  out = log_html();
34  out.html = ['<h1>', sov.title, '</h1>', 10, o.get_html_tables(sov)];
35  out.title = sov.get_description();
36  end;
37  end;
38 
39 
40  methods
41  %> Generates a table with the best in each architecture, with its respective time and confidence interval
42  %> @param sov sovalues object
43  function s = get_html_tables(o, sov)
44  s = '';
45  if isempty(sov)
46  return;
47  end;
48 
49  if isempty(o.vectorcomp)
50  o.vectorcomp = vectorcomp_ttest_right();
51  o.vectorcomp.flag_logtake = 0;
52  end;
53 
54  [values, ax] = sovalues.get_vv_aa(sov.values, sov.ax, o.dimspec);
55 
56  flag_rejected = isfield(values(1), 'oc') && values(1).oc.flag_rejected;
57  ratess = sovalues.getYY(values, o.names{1});
58  if size(ratess, 2) > 1
59  irerror('I cannot handle results that have more than one column!', 2);
60  end;
61 
62  temp = permute(ratess, [3, 1, 2]);
63  rates = mean(temp, 1);
64  if isfield(values, 'times3')
65  ratessort = rates-std(temp)/1e7-mean(permute(sovalues.getYY(values, 'times3'), [3, 1, 2]), 1)/1e10; % Just to solve ties: if the rate is the same, chooses one with lower standard deviation
66  else
67  ratessort = rates-std(temp)/1e7; % Just to solve ties: if the rate is the same, chooses one with lower standard deviation
68  end;
69  [vv, ii] = sort(ratessort, 'descend'); %#ok<ASGLU>
70  values = values(ii);
71  if isempty(sov.chooser)
72  choiceidx = [];
73  else
74  idxs = sov.chooser.use(values);
75  choiceidx = idxs{1};
76  end;
77  nnames = numel(o.names);
78  nar = numel(values);
79  R = permute(squeeze(sovalues.getYY(values, o.names{1})), [2, 1]);
80  if nar > o.maxrows
81  ii = o.some_items(nar, choiceidx);
82  else
83  ii = 1:nar;
84  end;
85 
86  R = R(:, ii);
87  Mp = o.vectorcomp.crosstest(R); % Matrix for the p-values (last column) of the firts table
88 
89  flag_choice = ~isempty(choiceidx);
90  choiceheader = '';
91  if flag_choice
92  choiceheader = ['<td class="bob">&nbsp;</td>', 10];
93  end;
94 
95  %>>>>> HTML
96 
97  %>>> Table header
98  s0 = '';
99  s0 = cat(2, s0, '<center><table class=bo>', 10, '<tr>', 10, choiceheader, ...
100  '<td class="bob"><div class="hel">#</div></td>', 10, ...
101  '<td class="bob"><div class="hel">System</div></td>', 10);
102 
103  for i = 1:nnames
104  s0 = cat(2, s0, '<td class="bob"><div class="hec">', labeldict(o.names{i}), '</div></td>', 10);
105  end;
106 % (04/07/2013) Examiners didn't like this column s0 = cat(2, s0, '<td class="bob"><div class="hec"><em>p</em>-values', '</div></td>', 10);
107  if flag_rejected
108  s0 = cat(2, s0, '<td class="bob"><div class="hec">Refused (%)</div></td>', 10);
109  end;
110  s0 = cat(2, s0, '</tr>', 10);
111 
112 
113  %>>> Table Body
114  ni = min(o.maxrows, nar);
115  for i = 1:ni
116  s0 = cat(2, s0, '<tr>', 10);
117 
118  clad = '';
119  if flag_choice
120  flag_chosen = ~isempty(choiceidx) && choiceidx == ii(i);
121  clad = iif(flag_chosen, 'choa', '');
122 
123  s0 = cat(2, s0, sprintf('<td class="hel%s">', clad), iif(flag_chosen, '&raquo;', '&nbsp;'), '</td>', 10);
124  end;
125 
126  s0 = cat(2, s0, sprintf('<td class="hel%s">', clad), int2str(ii(i)), '</td>', 10);
127  if isfield(values, 'spec')
128  s0 = cat(2, s0, sprintf('<td class="hel%s">', clad), values(ii(i)).spec, '</td>', 10);
129  else
130  s0 = cat(2, s0, sprintf('<td class="hel%s">', clad), 'spec?', '</td>', 10);
131  end;
132 
133  for j = 1:nnames
134  v = values(ii(i)).(o.names{j});
135 
136 
137  mv = mean(v);
138 % civ = confint(v);
139 % civ = civ(end)-mv;
140  civ = std(v); % Let's make standard deviation the standard for +- specifications
141 
142  s0 = cat(2, s0, sprintf('<td class="nu%s">', clad), sprintf('%.2f &plusmn; %.2f', mv, civ), '</td>', 10);
143  end;
144 
145 
146 % (04/07/2013) Examiners didn't like this column
147 % % P-value column
148 % if i == ni
149 % stemp = '-';
150 % else
151 % x = Mp(i, i+1);
152 % stemp = iif(x < 0.001, '< 0.001', sprintf('%.3f', x));
153 % end;
154 % s0 = cat(2, s0, sprintf('<td class="nu%s">', clad), stemp, '</td>', 10);
155 
156  % Rejected column
157  if flag_rejected
158  s0 = cat(2, s0, sprintf('<td class="nu%s">%.2f</td>', clad, 100*mean(values(ii(i)).oc.C(:, 1))), 10);
159  end;
160 
161  s0 = cat(2, s0, '</tr>', 10);
162  end;
163  s0 = cat(2, s0, '</table></center>', 10);
164 
165 
166  s1 = '';
167  if o.flag_ptable
168  s1 = cat(2, s1, '<h4><em>p</em>-values tables</h4>', 10, '<p>Vector comparer object: <b>', ...
169  o.vectorcomp.get_description(0), ' (<a href="matlab:edit(''', class(o.vectorcomp), '.m'')">', class(o.vectorcomp), '</a>)</b></p>');
170  for i = 1:nnames
171  R = permute(squeeze(sovalues.getYY(values, o.names{i})), [2, 1]);
172  R = R(:, ii);
173  M = o.vectorcomp.crosstest(R);
174 
175  if ~labeldict(o.names{i}, 1)
176  % Higher is better
177  B = M < M';
178  B = B + (B & M < 0.05)*2;
179  else
180  % Lower is better
181  B = M > M';
182  B = B + (B & M > 0.95)*2;
183  end;
184 
185  M = arrayfun(@(x) iif(x == 0, '-', iif(x < 0.001, '< 0.001', sprintf('%.3f', x))), M, 'UniformOutput', 0);
186 
187  s1 = cat(2, s1, '<h5><em>p</em>-values for ', labeldict(o.names{i}), '</h5>', 10, '<center>', ...
188  html_comparison(M, arrayfun(@int2str, ii, 'UniformOutput', 0), B), '</center>', 10);
189  end;
190  end;
191 
192  s = '';
193  s = cat(2, s, '<h4>Comparison table</h5>', 10, s0, 10, s1, 10);
194  end;
195  end;
196 
197  methods
198  %> @return Indexes of some elements
199  %>
200  %> The number of elements that will figure in the tables is limited by the @c maxrows property. This function returns the indexes of some elements
201  %> around the chosen one (if any was chosen), otherwise returns maxrows elements, starting at the first.
202  function v = some_items(o, nar, choiceidx)
203  if isempty(choiceidx)
204  v = 1:o.maxrows;
205  else
206  A = .4;
207 % share1 = A;
208  share2 = 1-A; % percentages of items destinated for the first items and items around choiceidx respectively
209 
210  nit = min(o.maxrows, nar);
211 
212  i1 = floor(choiceidx-share2/2*nit);
213  i2 = ceil(choiceidx+share2/2*nit);
214  i0 = nit-((i2-i1)+1);
215 
216  if i1 <= i0
217  dif = i0-i1+1;
218  i1 = i1+dif;
219  i2 = i2+dif;
220  end;
221 
222  if i2 > nar;
223  dif = i2-nar;
224  i1 = i1-dif;
225  i2 = i2-dif;
226  end;
227 
228  v = [1:i0, i1:i2];
229  end;
230  end;
231  end;
232 end
function irerror(in s)
Comparison and p-values tables.
Generated by irreport, carries HTML contents.
Definition: log_html.m:2
Paired Vector Comparer base class.
Definition: vectorcomp.m:9
Vector Comparer - paired t-test right tail.
Analysis Session (AS) base class.
Definition: as.m:6
Report base class.
Definition: irreport.m:8