
C***********************************************************************
C                                                                      *
C     G O D D A R D  C O M P U T E R  S C I E N C E  I N S T I T U T E *
C                                                                      *
C     (1) PROGRAM NAME,          T - TEST FOR PAIRED OBSERVATIONS      *
C     (2) CALLING NAME,          PARTES                                *
C     (3) STATUS/CHANGE LEVEL,   PGM.= GCSL027, PCR.= 01-08-67         *
C     (4) PROGRAMMED BY,         CECIL GARRETT                         *
C         MODIFIED BY,           STEWART H. CROSSLAND                  *
C     (5) ADAPTED TO HP FORMAT   ROLAND JAHN 03-70                     *
C                                                                      *
C           SUPPORTED IN PART BY GRANT NO. FR00197 BY THE              *
C           SPECIAL RESEARCH RESOURCES BRANCH, NIH-USPHS.              *
C                                                                      *
C***********************************************************************
      PROGRAM GCS27
      DIMENSION   X1(600),X2(600),D(600),NCOM(36)
      EQUIVALENCE (N,NPRS),(SIG,SLVL)
C
C     INITIALIZE VARIABLES
C
   10 SUMX2=0.
      SUMX1=0.
      SMX12=0.
      SMX22=0.
      SUMD=0.
      SUMD2=0.
C
C     READ AND PRINT HEADER  AND PARAMETERS
C
      WRITE (6, 90) 
      READ (5, 100)  (NCOM(I),I=1,36)
      WRITE (6, 100)  (NCOM(I),I=1,36)
      READ (5, 110)  ISW2,NPRS,CLVL
      WRITE (6, 120)  ISW2,NPRS,CLVL
      WRITE (6, 150) 
      AN= N
      J=N-1
C
C     CALL READ SUBROUTINE
C
      CALL READ(X1,X2,N)
      DO  20  I=1,N
      SMX22=SMX22+X2(I)*X2(I)
      SMX12=SMX12+X1(I)*X1(I)
      SUMX1=SUMX1+X1(I)
      SUMX2=SUMX2+X2(I)
      D(I)=X1(I)-X2(I)
      SUMD=SUMD+D(I)
   20 SUMD2=SUMD2+D(I)*D(I)
      X1BAR= SUMX1/AN
      X2BAR = SUMX2/AN
      VARX1=(SMX12-(SUMX1*SUMX1/AN))/(AN-1.)
      VARX2=(SMX22-(SUMX2*SUMX2/AN))/(AN-1.)
      SDX1=SQRT(VARX1)
      SDX2=SQRT(VARX2)
      SEX1=SDX1/SQRT(AN)
      SEX2=SDX2/SQRT(AN)
      DBAR=SUMD/AN
      VAR=(SUMD2-( SUMD * SUMD /AN))/(AN-1.)
      SD=SQRT(VAR)
      SED=SD/SQRT(AN)
      T=ABS(DBAR/(SQRT(VAR/AN)))
      F=J
      DF       =  AN-1.0
      CALL        TDIST (DF,CLVL,TV)
   30 IQ=0
      IF (ABS(T)-TV)   50,  50, 40
   40 IQ=1414
C
C     PRINT RESULTS OF THE ANALYSIS
C
   50 WRITE (6, 220) 
      WRITE (6, 170)  J, J, J
      WRITE (6, 180)  X1BAR,X2BAR,DBAR
      WRITE (6, 190)  VARX1,VARX2,VAR
      WRITE (6, 200) SDX1, SDX2, SD
      WRITE (6, 210)  SEX1, SEX2,SED
      WRITE (6, 220) 
      WRITE (6, 230) T,IQ,TV
   60 WRITE (6, 150) 
   70 DO 80  I=1,N
   80 WRITE (6, 160) X1(I),X2(I),D(I)
C
C     FORMAT STATEMENTS
C
   90 FORMAT(30(/) 40HT-TEST FOR PAIRED OBSERVATIONS (GCSL027)/)
  100 FORMAT( 36A2 )
  110 FORMAT(I1,I3,F4.2)
  120 FORMAT(/ 16HINPUT PARAMETERS,4X,5HISW2=I1,3X,7HNPAIRS=I3,3X,7HSL
     1EVEL=F4.2//)
  130 FORMAT(11HMEAN OF D = F20.10/15HVARIANCE OF D =  F20.10/27HSTAN
     1DARD DEVIATION OF D =  F20.10/3HT =  F20.10)
  140 FORMAT(8HNO. D.F.  2X,I4)
  150 FORMAT(/ 24X,1HX,15X,1HY,13X,3HX-Y)
  160 FORMAT( 9X,3F16.8)
  170 FORMAT(4HD.F.,5X,3(12X,I4))
  180 FORMAT(4HMEAN,5X,3E16.8)
  190 FORMAT(8HVARIANCE ,1X,3E16.8)
  200 FORMAT(4HS.D.,5X,3E16.8)
  210 FORMAT(4HS.E.,5X,3E16.8)
  220 FORMAT ( / )
  230 FORMAT(3HT =E16.8,A2,2X,18HVALUE FROM TABLE = ,E16.8)
C
C     PROGRAM CONTROL LOGIC
C
  240 IF          (ISW2) 10,250,10
  250 CONTINUE
      END
      SUBROUTINE READ(X1,X2,N)
      DIMENSION X1(1),X2(1)
      READ (5, 100) (X1(I),X2(I),I=1,N)
  100 FORMAT(2F10.0)
      RETURN
      END
C********************************************************************
C
C     SUBROUTINE  TDIST (DF,CLVL,TVAL)
C
C     THIS SUBROUTINE WILL DETERMINE TABULAR VALUES OF THE STUDENTS-T
C     DISTRIBUTION FOR USE IN CONSTRUCTING TWO-SIDED CONFIDENCE
C     INTERVALS AND TESTS OF HYPOTHESIS. VALUES OF THE STUDENTS-T ARE
C     COMPUTED FOR A SPECIFIED DEGREE OF FREEDOM (DF) AND CONFIDENCE
C     INTERVAL (CLVL). THE TWO-SIDED T-VALUE IS COMPUTED FOR A SIG-
C     NIFICANCE LEVEL OF (1.0-CLVL)/2.0. COMPUTATIONAL METHOD IS
C     EXTRACTED FROM *APPROXIMATION TO STUDENTS-T* ,TECHNOMETRICS,
C     VOLUME 7, NO.1, 1965). THE CALCULATED VALUE OF T IS RETURNED VIA
C     THE ARGUMENT (TVAL)
C
C********************************************************************
      SUBROUTINE  TDIST (DF,CLVL,TVAL)
      TVAL   =  (1.649*DF+3.5283+.85602/DF)/(DF+1.2209-1.5162/DF)
      IF (ABS(CLVL-0.90)-0.005) 4,4,1
    1 IF (ABS(CLVL-0.95)-0.005) 2,2,3
    2 TVAL   =  (1.96*DF+.60033+.9591/DF)/(DF-.90259+.11588/DF)
      RETURN
    3 TVAL   = (2.5758*DF-.82847+1.8745/DF)/(DF-2.2311+1.5631/DF)
    4 RETURN
      END




*TEST DATA FOR PAIRED T - TEST
0015+.95
       73.       51.
       43.       41.
       47.       43.
       53.       41.
       58.       47.
       47.       32.
       52.       24.
       38.       43.
       61.       53.
       56.       52.
       56.       57.
       34.       44.
       55.       57.
       65.       40.
       75.       68.
