Histogram for bins with different numbers of elements..
3 次查看(过去 30 天)
显示 更早的评论
Hi
I have the following problem:
I have data which I want to plot - but not every bin has the same number of datapoints. An example:
The values on the x-axis: 300 350 400 450 450 450 500 550 600 600
each of this values corresponds to a binary value: 0 0 0 1 1 0 0 0 1 1
Now careful - a zero means that the person has seen the stimuli with the intensity as defined on the x axis, but has not correctly recognized it - it does not mean that the value has not been sampled (or did not occur).
Hence the idea is the following, if I use linspace(min(speed),max(speed),3), each bin contains another number of stimuli shown, if I have 6 values in the first bin and 2 thereof are 1, this would mean that the subject could detect 2/6 of the stimuli, whereas if for the second bin 4 stimuli were shown and 2 answers correspond to a 1, here 50% of the stimuli were correctly detected - hence I need basically a percentage plotted per bin (not absolute numbers since as said the number of stimuli shown per bin varies).
How can I do that best - is there any standard way?
0 个评论
回答(2 个)
Chad Greene
2015-5-5
编辑:Chad Greene
2015-5-5
Perhaps I'm misunderstanding your question, but why not compare two separate histograms--one histogram for distribution of intensities for recognized stimuli, and one histogram for unrecognized stimuli.
I have an old version of Matlab, so I'm using histf (available on File Exchange) to format the histograms and legalpha to support he semitransparent objects:
intensity = [300 350 400 450 450 450 500 550 600 600];
recognized = logical([0 0 0 1 1 0 0 0 1 1]);
xbins = 200:50:700;
histf(intensity(recognized),xbins,'facecolor','b','facealpha',.5);
hold on
histf(intensity(~recognized),xbins,'facecolor','r','facealpha',.5);
box off
legalpha('recognized','unrecognized','location','northwest')
legend boxoff
xlabel('stimulus intensity')
2 个评论
Chad Greene
2015-5-6
What about normalizing your data? I can think of two ways. In one way, you could multiply the number of tests to get the same numbers of recognized vs unrecognized data. You have 4 recognized signals and 6 recognized signals, so you could multiply to get 24 of each:
intensity = [300 350 400 450 450 450 500 550 600 600];
recognized = logical([0 0 0 1 1 0 0 0 1 1]);
% intensities recognized vs unrecognized:
int_rec = intensity(recognized);
int_unr = intensity(~recognized);
% normalize data by multiplying number of trials:
norm_int_rec = repmat(int_rec,1,length(int_unr));
norm_int_unr = repmat(int_unr,1,length(int_rec));
xbins = 200:50:700;
histf(norm_int_rec,xbins,'facecolor','b','facealpha',.5);
hold on
histf(norm_int_unr,xbins,'facecolor','r','facealpha',.5);
box off
legalpha('recognized','unrecognized','location','northwest')
legend boxoff
xlabel('stimulus intensity')
But that approach is a bit strange. Can you forget the histogram entirely and simply plot the percent of respondents who recognize a signal as a function of stimulus intensity?
intensity = [300 350 400 450 450 450 500 550 600 600];
recognized = logical([0 0 0 1 1 0 0 0 1 1]);
xbins = unique(intensity);
pct_recognized = NaN(size(xbins));
for k = 1:length(xbins)
pct_recognized(k) = 100*sum(intensity(recognized)==xbins(k))/sum(intensity==xbins(k));
end
plot(xbins,pct_recognized,'bo-')
box off
xlabel 'stimulus intensity'
ylabel 'percent of respondents recognizing stimulus'
Walter Roberson
2015-5-6
binlocs = [300 350 400 450 450 450 500 550 600 600];
stimulus_locs = [.....]; %the time for each stimulus
was_recognized = [1 0 0 0 1 1 1....]; %recognized?
totalcounts = histc(stimulus_locs, binlocs);
recognizedcounts = histc( stimulus_locs(was_recognized>0), binlocs );
adjusted_totals = max(1, totalcounts);
recognized_fraction = recognizedcounts ./ adjusted_totals;
The adjusted_totals is there to handle the case that some bin has no entries, to avoid doing a 0 (recognized) divided by 0 (total)
4 个评论
Walter Roberson
2015-5-6
recognizedcounts = histc(stim_durations(was_recognized)>0, binlocs);
adjusted_totals = max(1, totalcounts);
recognized_fraction = recognizedcounts ./ adjusted_totals;
recognized_percent = recognized_fraction * 100;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graph and Network Algorithms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!