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