close all
stream = RandStream('mrg32k3a');
RandStream.setDefaultStream(stream);
n=200;
pvalmoran =[]; pvalks=[];
for i = 1:1000
x =  trnd(4,[n 1]);
y=normcdf(x,0,1); 
yy =[0; sort(y); 1];
Sd = sum(diff(yy,1).^2); 
M  = sqrt(n)*(n * Sd/2 - 1);%Moran's Stat
p = 1-normcdf(M);
pvalmoran = [pvalmoran p];
[h pv dn] = kstest(x, [x normcdf(x, 0, 1)]);
pvalks = [pvalks pv];
end
sum(pvalmoran < 0.05)  %201
sum(pvalks < 0.05)     %116



