C
C     ..................................................................
C
C        SUBROUTINE SIGNT
C
C        PURPOSE
C           TO PERFORM A NON-PARAMETRIC SIGN TEST, GIVEN TWO SETS OF
C           MATCHED OBSERVATIONS.  IT TESTS THE NULL HYPOTHESIS THAT THE
C           DIFFERENCES BETWEEN EACH PAIR OF MATCHED OBSERVATIONS HAS A
C           MEDIAN EQUAL TO ZERO.
C
C        USAGE
C           CALL SIGNT (N,A,B,K,M,P,IE)
C
C        DESCRIPTION OF PARAMETERS
C           N - NUMBER OF OBSERVATIONS IN SETS A AND B
C           A - INPUT VECTOR OF LENGTH N CONTAINING DATA FROM THE FIRST
C               SAMPLE, A
C           B - INPUT VECTOR OF LENGTH N CONTAINING DATA FROM THE SECOND
C               SAMPLE, B
C           K - OUTPUT VARIABLE CONTAINING THE NUMBER OF PAIRS OF
C               OBSERVATIONS FROM THE TWO SAMPLES WHOSE DIFFERENCES ARE
C               NON-ZERO
C           M - OUTPUT VARIABLE CONTAINING THE NUMBER OF PLUS OR MINUS
C               DIFFERENCES, WHICHEVER IS FEWER.
C           P - COMPUTED PROBABILITY OF AS FEW AS M NUMBER OF PAIRS
C               HAVING THE SAME SIGN, ASSUMING THAT THE SAMPLES CAME
C               FROM THE SAME POPULATION.
C           IE- 0, IF THERE IS NO ERROR.
C               1, IF K IS ZERO.  IN THIS CASE, P IS SET TO 1.0 AND
C               M TO 0.
C
C        REMARKS
C           IF K IS LESS THAN OR EQUAL TO 25, THE PROBABILITY WILL BE
C           COMPUTED USING THE BINOMIAL DISTRIBUTION.  IF K IS GREATER
C           THAN 25, THE PROBABILITY WILL BE COMPUTED USING THE NORMAL
C           APPROXIMATION TO THE BINOMIAL DISTRIBUTION.
C           P COMPUTED IS THE PROBABILITY FOR A ONE-TAILED TEST.  THUS,
C           FOR A TWO TAILED TEST, DOUBLE THE VALUE FOR P.
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           NDTR
C
C        METHOD
C           REFER TO DIXON AND MASSEY, INTRODUCTION TO STATISTICAL
C           ANALYSIS (MCGRAW-HILL, 1957).
C
C     ..................................................................
C
      SUBROUTINE SIGNT (N,A,B,K,M,P,IE)
C
      DIMENSION A(1),B(1)
      DOUBLE PRECISION FN,FD
C
C        INITIALIZATION
C
      IE=0
      K=0
      MPLUS=0
      MMINS=0
C
C        FIND (+) OR (-) DIFFERENCE
C
      DO 40 I=1,N
      D=A(I)-B(I)
      IF(D) 20, 40, 30
C
C        (-) DIFFERENCE
C
   20 K=K+1
      MMINS=MMINS+1
      GO TO 40
C
C        (+) DIFFERENCE
C
   30 K=K+1
      MPLUS=MPLUS+1
C
   40 CONTINUE
      IF(K) 41,41,42
   41 IE=1
      P=1.0
      M=0
      GO TO 95
   42 FK=K
C
C        FIND THE NUMBER OF FEWER SIGNS
C
      IF(MPLUS-MMINS) 45, 45, 50
   45 M=MPLUS
      GO TO 55
   50 M=MMINS
C
C        TEST WHETHER K IS GREATER THAN 25
C
   55 IF(K-25) 60, 60, 77
C
C        K IS LESS THAN OR EQUAL TO 25
C
   60 P=1.0
      IF(M) 75, 75, 65
   65 FN=1.0
      FD=1.0
      DO 70 I=1,M
      FI=I
      FN=FN*(FK-(FI-1.0))
      FD=FD*FI
   70 P=P+FN/FD
C
   75 P=P/(2.0**K)
      GO TO 95
C
C        K IS GREATER THAN 25.  COMPUTE MEAN, STANDARD DEVIATION, AND Z
C
   77 U=0.5*FK
      S=0.5*SQRT(FK)
      FM=M
      IF(FM-U) 80, 85, 85
   80 CON=0.5
      GO TO 90
   85 CON=0.0
   90 Z=(FM+CON-U)/S
C
C        COMPUTE P ASSOCIATED WITH THE VALUE AS EXTREME AS Z
C
      CALL NDTR (Z,P,D)
C
   95 RETURN
      END
