Home > database > incomplete > ensemble_enum_hist_as_fh.m

# ensemble_enum_hist_as_fh

## PURPOSE

fh = quest_resp_dist(subfunc_name)

## SYNOPSIS

function fh = ensemble_enum_hist(subfunc_name)

## DESCRIPTION

``` fh = quest_resp_dist(subfunc_name)

Calculates and plots the distributions of the response tallies in the
different categories of an enum.```

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

## SOURCE CODE

```0001 function fh = ensemble_enum_hist(subfunc_name)
0002 % fh = quest_resp_dist(subfunc_name)
0003 %
0004 % Calculates and plots the distributions of the response tallies in the
0005 % different categories of an enum.
0006 %
0007
0008 % 01/24/07 Petr Janata - adapted from quest_resp_dist.m
0009
0010 if nargin < 1
0011   subfunc_name = 'calc';
0012 end
0013
0014 % Return a function handle to the nested function that we are going to use
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   % Figure out how many question IDs we are dealing with
0030   qids = params.qids;
0031   nqid = length(qids);
0032
0033   % Get the column constants
0034   FD = set_form_col_const(ds.vars);
0035
0036   for iqid = 1:nqid
0037     % Make the mask for the qid
0038
0039
0040   end % for iqid
0041 end  % calc()
0042
0043
0044 if isfield(p,'queue')
0045  proc_queue = p.queue;
0046 else
0047   proc_queue = {'calc','report'};
0048 end
0049
0052 else
0054 end
0055
0056 pp = p.pp;  % Printing parameters
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       % Find the index into the data matrix which corresponds to this question ID
0068       idx = find(as.num.qid == p.qid);
0069
0070       % Extract information about the response categories
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       % Extract the relevant data and arrange such that subjects are in columns
0076       tmpmtx = squeeze(resp_data(:,idx,:))';
0077
0078       % If we are dealing with bitmask data, we have to do something a bit
0079       % different because the categories are represented directly by category
0080       % bits being turned off and on, rather than by the number that
0081       % corresponds to the category.  Thus, we arrive at catcnt in different
0082       % ways.
0084     catcnt = zeros(ncat,nsub);
0085
0086     % Replace NaNs with zeros
0087
0088     nstim = zeros(1,nsub);
0089     % Loop over subjects
0090     for isub = 1:nsub
0093
0095     end
0096       else
0097     % For each subject, determine the number of stimuli that fall into each enum
0098     % category.
0099     catcnt = hist(tmpmtx,1:ncat);
0100       end
0101
0102       % For each subject, determine the proportion of stims that the subject heard
0103       % that fell into each category. If we are dealing with a bitmask question
0104       % in which multiple responses are possible, divide by the number of stims
0105       % rather than the number of responses so that the proportions reflect the
0106       % number of stims rather than the number of responses.
0107
0109     catprop = catcnt./repmat(nstim,ncat,1);
0110       else
0111     catprop = catcnt./repmat(sum(catcnt),ncat,1);
0112       end
0113
0114       % Summary statistics
0115       catprop = catprop';  % subjects in rows
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));
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';
0133
0134       % Print the figure to a file
0135       if pp.write2file
0136     fprintf('Printing figure to file: %s\n', pp.figfname);
0137     print(pp.figfname, pp.printargs{:})
0138       end
0139
0140       % Plot subject distributions of observed proportions
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
0152       text(0.9,0.8,sprintf('N=%d', nsub),'units','norm');
0153     end
0154       end % for icat=
0155
0156       pp.pagehdr.title = sprintf('Distributions of responses to the question:\n%s', as.num.qtxt{idx});
0158
0159       % Print the figure to a file
0160       if pp.write2file
0161     fprintf('Printing figure to file: %s\n', pp.figfname);
0162     print(pp.figfname, pp.printargs{:})
0163       end
0164   end % switch proc_str
0165 end % for iq
0166
0167 out.catprop = catprop;
0168 out.catcnt = catcnt;
0169 out.enum_cats = enum_cats;```

Generated on Sun 19-May-2019 04:00:51 by m2html © 2003