comparison toolboxes/MIRtoolbox1.3.2/somtoolbox/som_stats_table.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function [sTstats,csThist] = som_stats_table(csS,histlabel)
2
3 %SOM_STATS_TABLE Statistics table.
4 %
5 % [sTstats,csThist] = som_stats_table(csS)
6 %
7 % sTstats = som_stats_table(csS);
8 % som_table_print(sTstats);
9 %
10 % Input and output arguments ([]'s are optional):
11 % csS (cell array) of statistics structs
12 % (struct) a statistics struct
13 %
14 % sTstats (struct) a table struct with basic descriptive
15 % statistics for each variable
16 % csThist (cell array) of table structs, with histograms for
17 % each variable
18 %
19 % See also SOM_STATS, SOM_STATS_PLOT, SOM_TABLE_PRINT, SOM_STATS_REPORT.
20
21 % Contributed to SOM Toolbox 2.0, December 31st, 2001 by Juha Vesanto
22 % Copyright (c) by Juha Vesanto
23 % http://www.cis.hut.fi/projects/somtoolbox/
24
25 % Version 2.0beta juuso 311201
26
27 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28 %% arguments
29
30 if isstruct(csS), csS = {csS}; end
31 dim = length(csS);
32
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
34 %% action
35
36 sTable = struct('colfmt','','headers',[],'values',[],'span',[]);
37
38 % summary table of all variables
39 sT = sTable;
40 sT.headers = {'name','min','mean','max','std','missing'};
41 if ~isnan(csS{1}.nunique), sT.headers{end+1} = 'unique'; end
42 %if length(col_values), sT.headers = [sT.headers, col_headers]; end
43 sT.values = cell(dim,length(sT.headers));
44 sT.span = ones([size(sT.values) 2]);
45
46 %if length(col_values), sT.values(:,end-size(col_values,2)+1:end) = col_values; end
47 %if length(col_spans), sT.span(:,end-size(col_spans,2)+1:end,:) = col_spans; end
48
49 for i=1:dim,
50 sT.values{i,1} = csS{i}.name;
51 v = [csS{i}.min,csS{i}.mean,csS{i}.max,csS{i}.std];
52 v = som_denormalize(v,csS{i}.normalization);
53 vstr = numtostring(v,6);
54 sT.values(i,2:5) = vstr';
55 sT.values{i,6} = c_and_p_str(csS{i}.ntotal-csS{i}.nvalid,csS{i}.ntotal);
56 if ~isnan(csS{1}.nunique),
57 sT.values{i,7} = c_and_p_str(csS{i}.nunique,csS{i}.nvalid);
58 end
59 end
60 sTstats = sT;
61
62 % histograms
63 csThist = cell(dim,1);
64 for i=1:dim,
65 sH = csS{i}.hist;
66 nvalid = csS{i}.nvalid;
67 nbins = length(sH.bins);
68 sT = sTable;
69 sT.headers = {[csS{i}.name ' values'],'frequency #','frequency %'};
70 sT.values = cell(nbins,length(sT.headers));
71 sT.span = ones(nbins,length(sT.headers),2);
72 for j=1:nbins,
73 if length(sH.bins) < csS{i}.nunique, sT.values{j,1} = sH.binlabels2{j};
74 else sT.values{j,1} = sH.binlabels{j}; end
75 sT.values{j,2} = sprintf('%d',round(sH.counts(j)));
76 sT.values{j,3} = p_str(sH.counts(j)/nvalid);
77 end
78 csThist{i} = sT;
79 end
80
81 return;
82
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
84 %% subfunctions
85
86 function vstr = numtostring(v,d)
87
88 tp = (size(v,2)>1);
89 if tp, v = v'; end
90 nearzero = (abs(v)/(max(v)-min(v)) < 10.^-d);
91 i1 = find(v > 0 & nearzero);
92 i2 = find(v < 0 & nearzero);
93 vstr = strrep(cellstr(num2str(v,d)),' ','');
94 vstr(i1) = {'0.0'};
95 vstr(i2) = {'-0.0'};
96 if tp, vstr = vstr'; end
97 return;
98
99 function str = c_and_p_str(n,m)
100 % return a string of form # (%), e.g. '23 (12%)'
101 if n==m, p = '100';
102 elseif n==0, p = '0';
103 else p = sprintf('%.2g',100*n/m);
104 end
105 str = sprintf('%d (%s%%)',round(n),p);
106 return;
107
108 function str = p_str(p)
109 % return a string of form %, e.g. '12%'
110 if round(p*100)>100, p = sprintf('%3g',100*p);
111 elseif p==1, p = '100';
112 elseif abs(p)<eps, p = '0';
113 else p = sprintf('%.2g',100*p);
114 end
115 str = sprintf('%s%%',p);
116 return;