This program can easily be modified to derive critical values for the Kolmogorov-Smirnov D statistic for other distributions. Note that you can generate random numbers following any other distribution by using:
x:=vdistrib(rnd(1),p1,p2,...);
where vdistrib stands for the respective inverse distribution function
[e.g., vWeibull(alpha, x, b, theta)], and rnd(1) stands for the random
number function that will produce values for a unit rectangular variate
(see Evans, Hastings, & Peacock, 1993).
References:
Evans, M., Hastings, N., & Peacock, B. (1993).Statistical distributions. New York: Wiley.
Lilliefors, H. W. (1967) "On the Kolmogorov-Smirnov test for normality with mean and variance unknown." ASA Journal, June, 399-402.
NOTE: For large numbers of replications, and for large samples, this program may require some time to complete the compuations.
Program written, modified, or edited at StatSoft, Inc.}
randomaccess;
NoDataFileVariableNames;
Sub DisplayHistogramOfD(Dvalues,samplesize,nreplications)
{make a histogram of the D values}
begin
dim dvalues(nreplications);
VectorSort (dvalues, SORT_ASCENDING);
xmax:=dvalues(nreplications);
xmin:=0;
xstep:=.05;
ncats:=0;
ncats:=xmax/xstep;
if ncats<8 then xstep:=.01;
ncats:=xmax/xstep+2;
redim xvals(ncats),yvals(ncats);
MatrixSetToZero (xvals);
MatrixSetToZero (yvals);
k:=1;
for i:=1 to ncats do begin
x:=i*xstep;
xvals(i):=x;
nextcase:
if dvalues(k)<=x then begin
yvals(i):=yvals(i)+1;
k:=k+1;
if k>nreplications then goto makegraph;
goto nextcase;
end;
end;
makegraph:;
Graph:=NewGraph (BARPLOT,
'Distribution of K-S D|Samplesize='+str(samplesize,4,0)+
', Replications='+str(nreplications,6,0),
'Frequencies',
'D<=x',ncats, xvals, yvals);
GraphSetPlot2DLayout (Graph, 1, BARPLOT,
?DataLabels, ?BarStyle,
xstep, ?DevLevel, ?IsRightAxis);
end;
Sub DisplayResults(dvalues,samplesize,nreplications)
begin
dim dvalues(nreplications);
redim cutoffs(1,5);
ValPercentile (dvalues, 1, nreplications, 80, cutoffs(1,1));
ValPercentile (dvalues, 1, nreplications, 85, cutoffs(1,2));
ValPercentile (dvalues, 1, nreplications, 90, cutoffs(1,3));
ValPercentile (dvalues, 1, nreplications, 95, cutoffs(1,4));
ValPercentile (dvalues, 1, nreplications, 99, cutoffs(1,5));
NewScrollsheet (?NoOfRows, ?NoOfColumns, cutoffs,
'Table of Critical Values of K-S D',
'N='+Str (samplesize, 3, 0),
' .20 | .15 | .10 | .05 | .01 ');
end;
Function GetParameters(byref samplesize,byref nreplications)
begin;
redim params(2);
params(1):=samplesize;
params(2):=nreplications;
GetParameters:=DisplayNumericInputBox (
'Enter the sample size and number of replications:',
'Sample size:|Replications:',
params);
samplesize:=params(1);
nreplications:=params(2);
end;
Sub GenerateNormalSample(d, n);
begin
dim d(n);
for i:=1 to n do d(i):=normal(1);
end;
Function ComputeKSDStatistic(d, n);
begin
dim d(n);
ValMean (d, 1, n, ex);
ValStDeviation (d, 1, n, xt);
VectorSort(d, SORT_ASCENDING);
f0:=0.0;
fn:=0;ff:=0;en:=0;dt:=0;x8:=0;
f0:=0;
en:=n;
ComputeKSDStatistic:=0.0;
for j:=1 to n do begin
fn:=j/en;
ff:=INormal (d(j), ex, xt);
dt:=MAX(abs(f0-ff),abs(fn-ff));
if dt > ComputeKSDStatistic then
ComputeKSDStatistic:=dt;
f0:=fn;
end;
end;
{ Start of main program }
{ Get sample size and number of replications}
samplesize:=5;
nreplications:=1000;
if not GetParameters(samplesize,nreplications)
then goto thatsit;
redim d(samplesize);
redim dvalues(nreplications);
for i:=1 to nreplications do begin
{ generate the data}
GenerateNormalSample(d,samplesize);
{compute d statistic}
dvalues(i):=ComputeKSDStatistic(d,samplesize);
end;
{prepare results}
DisplayResults(dvalues,samplesize,nreplications);
{make histogram of dvalues}
DisplayHistogramOfD(Dvalues,samplesize,nreplications);
thatsit:;
stop;
| Back to List of Programs |
![[StatSoft]](../../../images/sssmall.gif)
2300 East 14th Street, Tulsa, OK 74104
Phone: (918) 749-1119; Fax: (918) 749-2217
e-mail: info@statsoft.com
©Copyright StatSoft, Inc., 1984-2004.
StatSoft, StatSoft logo, STATISTICA, SEWSS, SEDAS, Data Miner, SEPATH and GTrees are trademarks of StatSoft, Inc.