%
load('C:\BESTAT\Goodness\Goodnessdat\neuronfires.mat')
[f]  = hist(Y, 2.5:5:997.5 )
[ni x]=hist(f,unique(f))
 %ni = 6   18   21   45   39   25   25   11    6    3    1}
 %x  = 1    2    3    4    5    6    7    8    9   10   12}

ni=[ni(1:9) ni(10)+ni(11)]  %join the last two cells 

 %ni = 6   18   21   45   39   25   25   11    6    4 

npi= 200 * [poisscdf(1,mean(f))...
    poisspdf(2:9,mean(f)) 1-poisscdf(9,mean(f))]
 % note that the first probability includes 0 and 1. 
 %npi = 8.4644  17.4079  28.6940  35.4730  35.0828  
 %     28.9141  20.4257  12.6256   6.9371   5.9754  

ch2 = sum((ni-npi).^2./npi)
 %ch2 = 8.3400 
pval = 1-chi2cdf(ch2, 10-1-1) %estimated mean, -1 df
 %pval = 0.4010 
 
% 
close all
figure(1)
f = poissrnd(5, 1, 20)
f=f';
lam = mean(f)
[h p stats]= kstest(f, [f poisscdf(f, 5)],0.05, 0)
% h = 0;  p = 0.2676;  stats = 0.2160

xx = 0:0.1:15;
plot(xx, poisscdf(xx, lam),'r-')
hold on
cdfplot(f)


