home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
DOOG
/
PCSSP2.ZIP
/
STATNONP.ZIP
/
KOLMO.FOR
< prev
next >
Wrap
Text File
|
1985-11-29
|
7KB
|
176 lines
C
C ..................................................................
C
C SUBROUTINE KOLMO
C
C PURPOSE
C TESTS THE DIFFERENCE BETWEEN EMPIRICAL AND THEORETICAL
C DISTRIBUTIONS USING THE KOLMOGOROV-SMIRNOV TEST
C
C USAGE
C CALL KOLMO(X,N,Z,PROB,IFCOD,U,S,IER)
C
C DESCRIPTION OF PARAMETERS
C X - INPUT VECTOR OF N INDEPENDENT OBSERVATIONS. ON
C RETURN FROM KOLMO, X HAS BEEN SORTED INTO A
C MONOTONIC NON-DECREASING SEQUENCE.
C N - NUMBER OF OBSERVATIONS IN X
C Z - OUTPUT VARIABLE CONTAINING THE GREATEST VALUE WITH
C RESPECT TO X OF SQRT(N)*ABS(FN(X)-F(X)) WHERE
C F(X) IS A THEORETICAL DISTRIBUTION FUNCTION AND
C FN(X) AN EMPIRICAL DISTRIBUTION FUNCTION.
C PROB - OUTPUT VARIABLE CONTAINING THE PROBABILITY OF
C THE STATISTIC BEING GREATER THAN OR EQUAL TO Z IF
C THE HYPOTHESIS THAT X IS FROM THE DENSITY UNDER
C CONSIDERATION IS TRUE. E.G., PROB = 0.05 IMPLIES
C THAT ONE CAN REJECT THE NULL HYPOTHESIS THAT THE SET
C X IS FROM THE DENSITY UNDER CONSIDERATION WITH 5 PER
C CENT PROBABILITY OF BEING INCORRECT. PROB = 1. -
C SMIRN(Z).
C IFCOD- A CODE DENOTING THE PARTICULAR THEORETICAL
C PROBABILITY DISTRIBUTION FUNCTION BEING CONSIDERED.
C = 1---F(X) IS THE NORMAL PDF.
C = 2---F(X) IS THE EXPONENTIAL PDF.
C = 3---F(X) IS THE CAUCHY PDF.
C = 4---F(X) IS THE UNIFORM PDF.
C = 5---F(X) IS USER SUPPLIED.
C U - WHEN IFCOD IS 1 OR 2, U IS THE MEAN OF THE DENSITY
C GIVEN ABOVE.
C WHEN IFCOD IS 3, U IS THE MEDIAN OF THE CAUCHY
C DENSITY.
C WHEN IFCOD IS 4, U IS THE LEFT ENDPOINT OF THE
C UNIFORM DENSITY.
C WHEN IFCOD IS 5, U IS USER SPECIFIED.
C S - WHEN IFCOD IS 1 OR 2, S IS THE STANDARD DEVIATION OF
C DENSITY GIVEN ABOVE, AND SHOULD BE POSITIVE.
C WHEN IFCOD IS 3, U - S SPECIFIES THE FIRST QUARTILE
C OF THE CAUCHY DENSITY. S SHOULD BE NON-ZERO.
C IF IFCOD IS 4, S IS THE RIGHT ENDPOINT OF THE UNIFORM
C DENSITY. S SHOULD BE GREATER THAN U.
C IF IFCOD IS 5, S IS USER SPECIFIED.
C IER - ERROR INDICATOR WHICH IS NON-ZERO IF S VIOLATES ABOVE
C CONVENTIONS. ON RETURN NO TEST HAS BEEN MADE, AND X
C AND Y HAVE BEEN SORTED INTO MONOTONIC NON-DECREASING
C SEQUENCES. IER IS SET TO ZERO ON ENTRY TO KOLMO.
C IER IS CURRENTLY SET TO ONE IF THE USER-SUPPLIED PDF
C IS REQUESTED FOR TESTING. THIS SHOULD BE CHANGED
C (SEE REMARKS) WHEN SOME PDF IS SUPPLIED BY THE USER.
C
C REMARKS
C N SHOULD BE GREATER THAN OR EQUAL TO 100. (SEE THE
C MATHEMATICAL DESCRIPTION GIVEN FOR THE PROGRAM SMIRN,
C CONCERNING ASYMPTOTIC FORMULAE) ALSO, PROBABILITY LEVELS
C DETERMINED BY THIS PROGRAM WILL NOT BE CORRECT IF THE
C SAME SAMPLES ARE USED TO ESTIMATE PARAMETERS FOR THE
C CONTINUOUS DISTRIBUTIONS WHICH ARE USED IN THIS TEST.
C (SEE THE MATHEMATICAL DESCRIPTION FOR THIS PROGRAM)
C F(X) SHOULD BE A CONTINUOUS FUNCTION.
C ANY USER SUPPLIED CUMULATIVE PROBABILITY DISTRIBUTION
C FUNCTION SHOULD BE CODED BEGINNING WITH STATEMENT 26 BELOW,
C AND SHOULD RETURN TO STATEMENT 27.
C
C DOUBLE PRECISION USAGE---IT IS DOUBTFUL THAT THE USER WILL
C WISH TO PERFORM THIS TEST USING DOUBLE PRECISION ACCURACY.
C IF ONE WISHES TO COMMUNICATE WITH KOLMO IN A DOUBLE
C PRECISION PROGRAM, HE SHOULD CALL THE FORTRAN SUPPLIED
C PROGRAM SNGL(X) PRIOR TO CALLING KOLMO, AND CALL THE
C FORTRAN SUPPLIED PROGRAM DBLE(X) AFTER EXITING FROM KOLMO.
C (NOTE THAT SUBROUTINE SMIRN DOES HAVE DOUBLE PRECISION
C CAPABILITY AS SUPPLIED BY THIS PACKAGE.)
C
C
C SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C SMIRN, NDTR, AND ANY USER SUPPLIED SUBROUTINES REQUIRED.
C
C METHOD
C FOR REFERENCE, SEE (1) W. FELLER--ON THE KOLMOGOROV-SMIRNOV
C LIMIT THEOREMS FOR EMPIRICAL DISTRIBUTIONS--
C ANNALS OF MATH. STAT., 19, 1948. 177-189,
C (2) N. SMIRNOV--TABLE FOR ESTIMATING THE GOODNESS OF FIT
C OF EMPIRICAL DISTRIBUTIONS--ANNALS OF MATH. STAT., 19,
C 1948. 279-281.
C (3) R. VON MISES--MATHEMATICAL THEORY OF PROBABILITY AND
C STATISTICS--ACADEMIC PRESS, NEW YORK, 1964. 490-493,
C (4) B.V. GNEDENKO--THE THEORY OF PROBABILITY--CHELSEA
C PUBLISHING COMPANY, NEW YORK, 1962. 384-401.
C
C ..................................................................
C
SUBROUTINE KOLMO(X,N,Z,PROB,IFCOD,U,S,IER)
DIMENSION X(1)
C
C NON DECREASING ORDERING OF X(I)'S (DUBY METHOD)
C
IER=0
DO 5 I=2,N
IF(X(I)-X(I-1))1,5,5
1 TEMP=X(I)
IM=I-1
DO 3 J=1,IM
L=I-J
IF(TEMP-X(L))2,4,4
2 X(L+1)=X(L)
3 CONTINUE
X(1)=TEMP
GO TO 5
4 X(L+1)=TEMP
5 CONTINUE
C
C COMPUTES MAXIMUM DEVIATION DN IN ABSOLUTE VALUE BETWEEN
C EMPIRICAL AND THEORETICAL DISTRIBUTIONS
C
NM1=N-1
XN=N
DN=0.0
FS=0.0
IL=1
6 DO 7 I=IL,NM1
J=I
IF(X(J)-X(J+1))9,7,9
7 CONTINUE
8 J=N
9 IL=J+1
FI=FS
FS=FLOAT(J)/XN
IF(IFCOD-2)10,13,17
10 IF(S)11,11,12
11 IER=1
GO TO 29
12 Z =(X(J)-U)/S
CALL NDTR(Z,Y,D)
GO TO 27
13 IF(S)11,11,14
14 Z=(X(J)-U)/S+1.0
IF(Z)15,15,16
15 Y=0.0
GO TO 27
16 Y=1.-EXP(-Z)
GO TO 27
17 IF(IFCOD-4)18,20,26
18 IF(S)19,11,19
19 Y=ATAN((X(J)-U)/S)*0.3183099+0.5
GO TO 27
20 IF(S-U)11,11,21
21 IF(X(J)-U)22,22,23
22 Y=0.0
GO TO 27
23 IF(X(J)-S)25,25,24
24 Y=1.0
GO TO 27
25 Y=(X(J)-U)/(S-U)
GO TO 27
26 IER=1
GO TO 29
27 EI=ABS(Y-FI)
ES=ABS(Y-FS)
DN=AMAX1(DN,EI,ES)
IF(IL-N)6,8,28
C
C COMPUTES Z=DN*SQRT(N) AND PROBABILITY
C
28 Z=DN*SQRT(XN)
CALL SMIRN(Z,PROB)
PROB=1.0-PROB
29 RETURN
END