Chi-square test with 2 bins, why do I get P = nan ?

8 次查看(过去 30 天)
I would like to use chi-square statistical test with just two bins. Everything seems fine in the table, but the p value is nana and degree of freedom is 0. p value is different from nan when the number of bins is hgher than 3. For bins=4 degree of freedom is 1. Why is it so?
e.g. [h,p,stats] = chi2gof(rand(1,1000),'nbins',2)
chi2stat: 0.0130
df: 0
edges: [0.0012 0.5003 0.9995]
O: [489 511]
E: [490.8038 509.1962]
thanks

回答(1 个)

Tom Lane
Tom Lane 2012-11-28
The default for chi2gof is to test against the normal distribution, estimate the parameters, and deduct the number of estimated parameters from the degrees of freedom.
Compare these:
x = randn(100,1);
[h,p,stats] = chi2gof(x,'nbins',2)
[h,p,stats] = chi2gof(x,'nbins',2,'cdf',@normcdf)
The first is what you tried. The second tests against the standard normal distribution (parameters fixed at mu=0 and sigma=1), so it doesn't lose any degrees of freedom by estimating the parameters. You will probably see that the chi-square statistic is higher for the latter, because the estimation process tends to reduce the statistic compared with pre-specified values.

类别

Help CenterFile Exchange 中查找有关 Hypothesis Tests 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by