How to use chi2gof to compare 2 histograms (no original vectors available)
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've been trying to use chi2gof to compare many component vectors of a dataset to the mean. As a toy example, say I only have three components, something like:
A1 = [1 2 3 4 5 6 7 8 9 10]
A2 = [10 9 8 7 6 5 4 3 2 1]
A3 = [5 5 5 5 5 5 5 5 5 5]
What I'd like to do is compare each of those to the mean [5.3 5.3 5.3 ...] to see whether they can be considered to come from the distribution of the mean (unlikely for A1,A2, more likely for A3).
I thought a chi-square test would be the way to do this, but I only have access to already-binned data (they're counts that I run in a different process and are very large numbers). And it seems from the documentation that you need to have the data you're looking at in vector form (where the chi2gof function will bin them).
Is there any way to get around this?
0 comentarios
Respuestas (1)
the cyclist
el 23 de Mayo de 2011
I ran across a similar issue when I was using the crosstab() function. I wrote a kludgy function that will, given the tabular output of crosstab, create X,Y vectors that would have resulted in that table. The code is below. You may be able to use it as a starting point.
Be warned that this code is BAD, and not actually ready for prime-time. It grows xVec and yVec, rather than preallocating, and is suitable only for small numbers (which is all I needed it for).
function [xVec,yVec] = inversecrosstab(tab)
% INVERSECROSSTAB takes table of values (as would be output by CROSSTAB) and creates
% X and Y vectors that would have led to that cross-tabulation table
[nxdim nydim] = size(tab);
[xVec,yVec] = deal([]);
val = 0;
for ix = 1:nxdim
val = val + 1;
for iy = 1:nydim
xVec = [xVec;repmat(val,[tab(ix,iy),1])];
yVec = [yVec;repmat(iy, [tab(ix,iy),1])];
end
end
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!