chi2gof two sample test for integer arrays of different sizes?

27 views (last 30 days)
Hey all,
I have 2 integer arrays, one of size 1x25 and the other of 1x26. I have been told to use the chi squared test in order to find how statistically different my data is. But I don't know how to do this, with ttest you could just do ttest2(Arr1, Arr2). Can someone please help me out, thanks!

Answers (5)

Wayne King
Wayne King on 21 Jun 2012
chi2gof is for one sample. You can test each vector separately against a specific distribution, but not against each other.
x = randn(100,1);
[h,p] = chi2gof(x,'cdf',@normcdf)
y = rand(100,1);
[h1,p1] = chi2gof(y,'cdf',@normcdf)
You see in the second case you reject the null hypothesis.
Are you just looking for a nonparametric two-sample test? How about ranksum()?

Annick van der Hoest
Annick van der Hoest on 21 Jun 2012
Well, I did user experience testing. And I want to compare the answers from one solution to the answers from another solution. I had tried using the ttest2, but due to the answer being Likert scale I was told to use chi2.. by my supervisor.. In the documentation about chi2gof it says:
"The null distribution can be changed from a normal distribution to an arbitrary discrete or continuous distribution. See the syntax for specifying optional argument name/value pairs below."
from which i concluded that it should be possible... but i don't know how to :(
I'm not so familiar with statistics, so I have no idea if I am looking for a two-sample test , or ranksum... thanks for your help btw!

Wayne King
Wayne King on 21 Jun 2012
You can certainly specifiy a discrete distribution to use with chi2gof, by specifing the bins (edges) and expected counts.
Now that you have described your use case more, it sounds to me like you may want crosstab() . crosstab() uses a chi-square test for independence of two samples.
For example:
x1 = unidrnd(3,50,1);
x2 = unidrnd(3,50,1);
[table,chi2,p] = crosstab(x1,x2)
See:
for example.

Annick van der Hoest
Annick van der Hoest on 21 Jun 2012
yes that looks good! the problem is though that in crosstab is says the vectors need to be of the same size :( mine are 1x25 and 1x26.. do you maybe also know how to do this? it seems to be in the right direction though! thanks!
  2 Comments
Wayne King
Wayne King on 21 Jun 2012
yes, I think you need to use equal sample sizes. I don't know your data, so I can't suggest a principled way to make the sample sizes equal.
Annick van der Hoest
Annick van der Hoest on 21 Jun 2012
my data is as follows:
I have 25 participants testing one solution, and 26 testing the other solution..
i ask 9 questions about it, that they answer with a rank from 1 to 5.
for each question, i want to compare the answers to one solution and to the other. so i have two arrays, one is 1x25 (namely for one question 25 answers where they are all 1 ,2 , 3, 4 or 5)
and one is 1x26 (for the same question but answers from participants testing the other solution and those were 26 people).
and i am not in the position to merely disregard the answers from one participant.. which would be the easiest.. would be great if you know how to!

Sign in to comment.


Lucjan
Lucjan on 4 Dec 2014
It is not correct direction. Crosstab assumes there is a meaning for a pair (x,y) that is why it needs the same number of samples. You are calling for two sample chi-square distribution, which, as far as I chucked, is not implemented in MATLAB. But you should be able to implement it by yourself based on: http://www.itl.nist.gov/div898/software/dataplot/refman1/auxillar/chi2samp.htm

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!