0001 function fh = ensemble_enum_hist(subfunc_name)
0002
0003
0004
0005
0006
0007
0008
0009
0010 if nargin < 1
0011 subfunc_name = 'calc';
0012 end
0013
0014
0015 switch subfunc_name
0016 case 'summary'
0017 fh = {@calc,@total};
0018 case 'calc'
0019 fh = {@calc};
0020 case 'total'
0021 fh = {@total};
0022 case 'per_category'
0023 fh = {@per_category};
0024 case 'all'
0025 fh = {@calc,@total,@per_category};
0026 end
0027
0028 function out = calc(ds,params)
0029
0030 qids = params.qids;
0031 nqid = length(qids);
0032
0033
0034 FD = set_form_col_const(ds.vars);
0035
0036 for iqid = 1:nqid
0037
0038
0039
0040 end
0041 end
0042
0043
0044 if isfield(p,'queue')
0045 proc_queue = p.queue;
0046 else
0047 proc_queue = {'calc','report'};
0048 end
0049
0050 if isfield(p, 'is_bitmask')
0051 is_bitmask = p.is_bitmask;
0052 else
0053 is_bitmask = 0;
0054 end
0055
0056 pp = p.pp;
0057
0058 nq = length(proc_queue);
0059 for iq = 1:nq
0060 proc_str = proc_queue{iq};
0061
0062 switch proc_str
0063 case 'calc'
0064
0065 nsub = size(resp_data,1);
0066
0067
0068 idx = find(as.num.qid == p.qid);
0069
0070
0071 enum_cats = mysql_resolve_enum(as.num.dfid(idx),p.CONN_ID);
0072 enum_cats = enum_cats{1};
0073 ncat = length(enum_cats);
0074
0075
0076 tmpmtx = squeeze(resp_data(:,idx,:))';
0077
0078
0079
0080
0081
0082
0083 if is_bitmask
0084 catcnt = zeros(ncat,nsub);
0085
0086
0087
0088 nstim = zeros(1,nsub);
0089
0090 for isub = 1:nsub
0091 bitmask = data2bitmask(tmpmtx(:,isub),ncat);
0092 nstim(isub) = sum(any(bitmask,2));
0093
0094 catcnt(:,isub) = sum(bitmask)';
0095 end
0096 else
0097
0098
0099 catcnt = hist(tmpmtx,1:ncat);
0100 end
0101
0102
0103
0104
0105
0106
0107
0108 if is_bitmask
0109 catprop = catcnt./repmat(nstim,ncat,1);
0110 else
0111 catprop = catcnt./repmat(sum(catcnt),ncat,1);
0112 end
0113
0114
0115 catprop = catprop';
0116
0117 case 'report'
0118 p.nfig = p.nfig+1;
0119 figure(p.nfig), clf
0120 subplot(2,1,1)
0121 h = bar('v6',1:ncat,mean(catprop));
0122 add_errorbars(h,(std(catprop)/sqrt(size(catprop,1)))');
0123 set(gca,'xticklabel',enum_cats)
0124 title(as.num.qtxt{idx})
0125
0126 subplot(2,1,2)
0127 hist(tmpmtx(:),1:ncat)
0128 set(gca,'xticklabel',enum_cats)
0129 title('Overall counts within each category')
0130
0131 pp.pagehdr.title = 'Distributions of responses in each category';
0132 autobio_add_fighdr(pp);
0133
0134
0135 if pp.write2file
0136 fprintf('Printing figure to file: %s\n', pp.figfname);
0137 print(pp.figfname, pp.printargs{:})
0138 end
0139
0140
0141 p.nfig = p.nfig+1;
0142 figure(p.nfig), clf
0143 hist_scale = 0:0.1:1;
0144 for icat = 1:ncat
0145 subplot(ncat,1,icat)
0146 hist_vals = hist(catprop(:,icat),hist_scale);
0147 bar(hist_scale,hist_vals)
0148 set(gca,'xlim',[-0.05 1.05])
0149 title(enum_cats{icat})
0150
0151 if isfield(p,'add_nsub') && p.add_nsub
0152 text(0.9,0.8,sprintf('N=%d', nsub),'units','norm');
0153 end
0154 end
0155
0156 pp.pagehdr.title = sprintf('Distributions of responses to the question:\n%s', as.num.qtxt{idx});
0157 autobio_add_fighdr(pp);
0158
0159
0160 if pp.write2file
0161 fprintf('Printing figure to file: %s\n', pp.figfname);
0162 print(pp.figfname, pp.printargs{:})
0163 end
0164 end
0165 end
0166
0167 out.catprop = catprop;
0168 out.catcnt = catcnt;
0169 out.enum_cats = enum_cats;