%
%  macm 202 -- 04 mar 03 -- djm
%
%  w9edf1.m:  exponential distribution
%     - simple EDF

%  exponential data

mu = 1.0;  Nrand = 25;  rand('state',1234567);
xdata = -log(rand(1,Nrand))/mu;

i_hi = 1:Nrand  ;  frac_hi = i_hi/Nrand;
i_lo = 0:Nrand-1;  frac_lo = i_lo/Nrand;

xsort = sort(xdata);

%  plot data

figure(1);  clf
plot(i_hi,xdata,'o')
hold on
plot(i_hi,xsort,'r*')
title([num2str(Nrand) '\bf random points'])
xlabel('\bf index: i')
ylabel('\bf random data: x_i (blue o),x_{(i)} (ordered, red *)')

mean(xsort)

%  plot EDF for data

figure(2);  clf
plot(xsort,frac_hi,'k*')
hold on
plot(xsort,frac_lo,'k.')
title(['\bf EDF of ordered randoms'])
ylabel('\bf fraction of empirical data below x')
xlabel('\bf ordered random data: x_{(i)}')

%  connect the dots!
edfx = [xsort ; xsort];
edfy = [frac_lo ; frac_hi];
plot(edfx(:),edfy(:),'b')

%  theoretical EDF
plot(xsort,1-exp(-mu*xsort),'r')

