# matlab – Statistical test gives result different than reality?

Let’s define X as : and objects releated to it: I want to calculation value of function following, and plot it on the same graph with histogram eigenvalues of Y. After that I want to perform chi2gof test to judge weather those two distributions converge to each other or not. I want to use parameter expected with is designed to compare distributions of function and histogram.

My work so far

``````clf;
m=8000;
n=10000;
X=randn(m,n);
Y=X*X'/n;
sd=std(X(:));
l=m/n;
eigs=eig(Y);
lp=sd^2*(1+sqrt(l))^2;
lm=sd^2*(1-sqrt(l))^2;
x=linspace(0.00000001,lp,n);
for i = 1:length(x)
if (and(x(i) <= lp, x(i) >= lm))
dv(i) = sqrt((lp-x(i)).*(x(i)-lm))./(2*pi*sd^2*l.*x(i));
else
dv(i) = 0;
end
end
``````

This code fully calculates my function dv. Now to plot it on histogram, and to add sens to it I normalized histogram to have unit area.

``````hold on;
[h, centres] = hist(eigs, 50);
% normalise to unit area
norm_h = h / (numel(eigs) * (centres(2)-centres(1)));
bar(centres, norm_h);
plot(x, dv, "r");
hold off;
``````

The result from this code is image following: As we can see the dv line really nicely fits the histogram. We can be almost sure that chi square test for same distribution should output p value very close to 1 (it means that samples are from the same distribution). However code

``````[h,p,stats] = chi2gof(dv,'Expected',norm_h);
``````

outputs

`````` p =

0
``````

It means that null hypothesis of the same distributions were rejected. My question is – how ? Am I using something incorrectly, or this pvalue is really 0 ?