How to carry out a chi-squared distribution fit?

11 views (last 30 days)
  I want to use central chi-squared distribution to fit a set of data (in order to get its degree of freedom, goodness of fit, etc..). However, in the distribution fitting toolbox, there is no options for chi-squared distribution. I wonder how to solve this problem...

Answers (1)

Wayne King
Wayne King on 23 Nov 2011
How about using mle() with the distribution 'gamma' since the chisquare distribution is just a gamma with alpha parameter nu/2 (nu = dof) and beta parameter = 2
r = chi2rnd(2,100,1);
[phat,pci] = mle(r,'distribution','gamma');
Alternatively, you can do:
[h,p] = chi2gof(r,'cdf',@(x)chi2cdf(x,2),'nparams',1);
which gives you a goodness of fit test on whether the data vector is compatible with the chisquare 2-dof distribution in this case.
Note that with:
[h,p] = chi2gof(r,'cdf',@(x)chi2cdf(x,2),'nparams',1);
you do not reject the null hypothesis (h=0), while with
[h,p] = chi2gof(r,'cdf',@(x)chi2cdf(x,5),'nparams',1);
you do (h=1).
Finally, there is the good old qqplot() to visually assess your fit:
pd = ProbDistUnivParam('gamma',[1 2]);
qqplot(r,pd);you do.

Community Treasure Hunt

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

Start Hunting!