# Kolmogorov

5 views (last 30 days)
MArghe on 26 May 2011
Hy, i'm trying to perform the Kolmogorov-Smirnov test by using the function h = kstest(x,CDF). I have to use this test to verify the good agreement of my data set (matrix (20,6545)) to the Cumulative GEV distribution but i can't build the CDF matrix. This is the program that i wrote:
E=patterns_EOBS(:,6545); %dataset
M=6545;
N=20;
x=[-5:3:55]';
parmhat_EOBS=zeros(M,3);
P=zeros(N,M);
CDF=zeros(N,2);
h=zeros(M);
p=zeros(M);
kstat=zeros(M);
cv=zeros(M);
for j=1:M
parmhat_EOBS(j,:)=gevfit(E(:,j));
for i=1:N
P(i,j)=gevcdf(x(i),parmhat_EOBS(j,1),parmhat_EOBS(j,2),parmhat_EOBS(j,3));
end
CDF(:,j)=horzcat(E(:,j),P(:,j));
[h(j),p(j),kstat(j),cv(j)]=kstest(E(:,j),CDF(:,j));
end
And this is the error that mathlab returns to me:
??? Subscripted assignment dimension mismatch.
Error in ==> KolmoEOBS at 22 CDF(:,j)=horzcat(E(:,j),P(:,j));
CAn you help me?
MArghe
Andrew Newell on 30 May 2011
Since you don't know the parameters of your distribution in advance, you should be using lillietest.

Ivan van der Kroon on 26 May 2011
Matlab is very clear here; your dimensions mitmatch: size(CDF(:,j))=[20,1] while size(horzcat(E(:,j),P(:,j)))=[20,2].
Another problem that will occur is that j will be greater than 2 at some point while size(CDF)=[20,2].
From this I think you are looking for
CDF=zeros(N,2,M);
CDF(:,:,j)=horzcat(E(:,j),P(:,j));

MArghe on 30 May 2011
First of all, thank you for answering me.
To perform the test, the matrix CDF has to be a two columns matrix:
the first column comprises the data set that i want to analyze (that is every column of the matrix E [size (20,6545)]), the second column comprises the Cumulative Density Function chosen (In this case the GEV). That is, i want a two column matrix at each cycle, to perform the test. I've tried to execute your suggest, but now the error is of the type OUT OF MEMORY at the line 8 of the program i wrote above.
MArgheirta
Oleg Komarov on 30 May 2011
Line 8: zeros(M) = zeros(M,M) --> zeros(6545) ~ 2.6 Gb = (6545^2) * 8 bytes

Ivan van der Kroon on 30 May 2011
I know that CDF has to be of size Nx2, but you want to have M of those in your for-loop. So you have to use CDF(:,:,j), which is a Nx2 again. If you are not interested in it, you should overwrite it every iteration, i.e. no preallocation fod CDF and no indexes:
CDF=horzcat(E(:,j),P(:,j));
[h(j),p(j),kstat(j),cv(j)]=kstest(E(:,j),CDF);
This way you save considerable memory. But working with a 6545x6545 system is hard as Oleg commented. It checked and it worked for me (on my 64bits version).

### Categories

Find more on Hypothesis Tests in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!