home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
fortran
/
library
/
ssp
/
statcorr
/
misr.for
< prev
next >
Wrap
Text File
|
1985-12-26
|
7KB
|
231 lines
C
C ..................................................................
C
C SUBROUTINE MISR
C
C PURPOSE
C COMPUTE MEANS, STANDARD DEVIATIONS, SKEWNESS AND KURTOSIS,
C CORRELATION COEFFICIENTS, REGRESSION COEFFICIENTS, AND
C STANDARD ERRORS OF REGRESSION COEFFICIENTS WHEN THERE ARE
C MISSING DATA POINTS. THE USER IDENTIFIES THE MISSING DATA
C BY MEANS OF A NUMERIC CODE. THOSE VALUES HAVING THIS CODE
C ARE SKIPPED IN COMPUTING THE STATISTICS. IN THE CASE OF THE
C CORRELATION COEFFICIENTS, ANY PAIR OF VALUES ARE SKIPPED IF
C EITHER ONE OF THEM ARE MISSING.
C
C USAGE
C CALL MISR (NO,M,X,CODE,XBAR,STD,SKEW,CURT,R,N,A,B,S,IER)
C
C DESCRIPTION OF PARAMETERS
C NO - NUMBER OF OBSERVATIONS
C M - NUMBER OF VARIABLES
C X - INPUT DATA MATRIX OF SIZE NO X M.
C CODE - INPUT VECTOR OF LENGTH M, WHICH CONTAINS A NUMERIC
C MISSING DATA CODE FOR EACH VARIABLE. ANY OBSERVATION
C FOR A GIVEN VARIABLE HAVING A VALUE EQUAL TO THE CODE
C WILL BE DROPPED FOR THE COMPUTATIONS.
C XBAR - OUTPUT VECTOR OF LENGTH M CONTAINING MEANS
C STD - OUTPUT VECTOR OF LENGTH M CONTAINING STANDARD DEVI-
C ATIONS
C SKEW - OUTPUT VECTOR OF LENGTH M CONTAINING SKEWNESS
C CURT - OUTPUT VECTOR OF LENGTH M CONTAINING KURTOSIS
C R - OUTPUT MATRIX OF PRODUCT-MOMENT CORRELATION
C COEFFICIENTS. THIS WILL BE THE UPPER TRIANGULAR
C MATRIX ONLY, SINCE THE M X M MATRIX OF COEFFICIENTS
C IS SYMMETRIC. (STORAGE MODE 1)
C N - OUTPUT MATRIX OF NUMBER OF PAIRS OF OBSERVATIONS USED
C IN COMPUTING THE CORRELATION COEFFICIENTS. ONLY THE
C UPPER TRIANGULAR PORTION OF THE MATRIX IS GIVEN.
C (STORAGE MODE 1)
C A - OUTPUT MATRIX (M BY M) CONTAINING INTERCEPTS OF
C REGRESSION LINES (A) OF THE FORM Y=A+BX. THE FIRST
C SUBSCRIPT OF THIS MATRIX REFERS TO THE INDEPENDENT
C VARIABLE AND THE SECOND TO THE DEPENDENT VARIABLE.
C FOR EXAMPLE, A(1,3) CONTAINS THE INTERCEPT OF THE
C REGRESSION LINE FOR TWO VARIABLES WHERE VARIABLE 1
C IS INDEPENDENT AND VARIABLE 3 IS DEPENDENT. NOTE
C THAT MATRIX A IS STORED IN A VECTOR FORM.
C B - OUTPUT MATRIX (M BY M) CONTAINING REGRESSION
C COEFFICIENTS (B) CORRESPONDING TO THE VALUES OF
C INTERCEPTS CONTAINED IN THE OUTPUT MATRIX A.
C S - OUTPUT MATRIX (M BY M) CONTAINING STANDARD ERRORS
C OF REGRESSION COEFFICIENTS CORRESPONDING TO THE
C COEFFICIENTS CONTAINED IN THE OUTPUT MATRIX B.
C IER - 0, NO ERROR.
C 1, IF NUMBER OF NON-MISSING DATA ELEMENTS FOR J-TH
C VARIABLE IS TWO OR LESS. IN THIS CASE, STD(J),
C SKEW(J), AND CURT(J) ARE SET TO 10**75. ALL
C VALUES OF R, A, B, AND S RELATED TO THIS VARIABLE
C ARE ALSO SET TO 10**75.
C 2, IF VARIANCE OF J-TH VARIABLE IS LESS THAN
C 10**(-20). IN THIS CASE, STD(J), SKEW(J), AND
C CURT(J) ARE SET TO 10**75. ALL VALUES OF R, A,
C B, AND S RELATED TO THIS VARIABLE ARE ALSO SET TO
C 10**75.
C
C REMARKS
C THIS SUBROUTINE CANNOT DISTINGUISH A BLANK AND A ZERO.
C THEREFORE, IF A BLANK IS SPECIFIED AS A MISSING DATA CODE IN
C INPUT CARDS, IT WILL BE TREATED AS 0 (ZERO).
C
C SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C NONE
C
C METHOD
C LEAST SQUARES REGRESSION LINES AND PRODUCT-MOMENT CORRE-
C LATION COEFFICIENTS ARE COMPUTED.
C
C ..................................................................
C
SUBROUTINE MISR (NO,M,X,CODE,XBAR,STD,SKEW,CURT,R,N,A,B,S,IER)
C
DIMENSION X(1),CODE(1),XBAR(1),STD(1),SKEW(1),CURT(1),R(1),N(1)
DIMENSION A(1),B(1),S(1)
C
C COMPUTE MEANS
C
IER=0
L=0
DO 20 J=1,M
FN=0.0
XBAR(J)=0.0
DO 15 I=1,NO
L=L+1
IF(X(L)-CODE(J)) 12, 15, 12
12 FN=FN+1.0
XBAR(J)=XBAR(J)+X(L)
15 CONTINUE
IF(FN) 16, 16, 17
16 XBAR(J)=0.0
GO TO 20
17 XBAR(J)=XBAR(J)/FN
20 CONTINUE
C
C SET-UP WORK AREAS AND TEST WHETHER DATA IS MISSING
C
L=0
DO 55 J=1,M
LJJ=NO*(J-1)
SKEW(J)=0.0
CURT(J)=0.0
KI=M*(J-1)
KJ=J-M
DO 54 I=1,J
KI=KI+1
KJ=KJ+M
SUMX=0.0
SUMY=0.0
TI=0.0
TJ=0.0
TII=0.0
TJJ=0.0
TIJ=0.0
NIJ=0
LI=NO*(I-1)
LJ=LJJ
L=L+1
DO 38 K=1,NO
LI=LI+1
LJ=LJ+1
IF(X(LI)-CODE(I)) 30, 38, 30
30 IF(X(LJ)-CODE(J)) 35, 38, 35
C
C BOTH DATA ARE PRESENT
C
35 XX=X(LI)-XBAR(I)
YY=X(LJ)-XBAR(J)
TI=TI+XX
TII=TII+XX**2
TJ=TJ+YY
TJJ=TJJ+YY**2
TIJ=TIJ+XX*YY
NIJ=NIJ+1
SUMX=SUMX+X(LI)
SUMY=SUMY+X(LJ)
IF(I-J) 38, 37, 37
37 SKEW(J)=SKEW(J)+YY**3
CURT(J)=CURT(J)+YY**4
38 CONTINUE
C
C COMPUTE SUM OF CROSS-PRODUCTS OF DEVIATIONS
C
IF(NIJ) 40, 40, 39
39 FN=NIJ
R(L)=TIJ-TI*TJ/FN
N(L)=NIJ
TII=TII-TI*TI/FN
TJJ=TJJ-TJ*TJ/FN
C
C COMPUTE STANDARD DEVIATION, SKEWNESS, AND KURTOSIS
C
40 IF(I-J) 47, 41, 47
41 IF(NIJ-2) 42,42,43
42 IER=1
R(L)=1.0E38
A(KI)=1.0E38
B(KI)=1.0E38
S(KI)=1.0E38
GO TO 45
C
43 STD(J)=R(L)
R(L)=1.0
A(KI)=0.0
B(KI)=1.0
S(KI)=0.0
C
IF(STD(J)-(1.0E-20)) 44,44,46
44 IER=2
45 STD(J)=1.0E38
SKEW(J)=1.0E38
CURT(J)=1.0E38
GO TO 55
C
46 WORK=STD(J)/FN
SKEW(J)=(SKEW(J)/FN)/(WORK*SQRT(WORK))
CURT(J)=((CURT(J)/FN)/WORK**2)-3.0
STD(J)=SQRT(STD(J)/(FN-1.0))
GO TO 55
C
C COMPUTE REGRESSION COEFFICIENTS
C
47 IF(NIJ-2) 48,48,50
48 IER=1
49 R(L)=1.0E38
A(KI)=1.0E38
B(KI)=1.0E38
S(KI)=1.0E38
A(KJ)=1.0E38
B(KJ)=1.0E38
S(KJ)=1.0E38
GO TO 54
C
50 IF(TII-(1.0E-20)) 52,52,51
51 IF(TJJ-(1.0E-20)) 52,52,53
52 IER=2
GO TO 49
C
53 SUMX=SUMX/FN
SUMY=SUMY/FN
B(KI)=R(L)/TII
A(KI)=SUMY-B(KI)*SUMX
B(KJ)=R(L)/TJJ
A(KJ)=SUMX-B(KJ)*SUMY
C
C COMPUTE CORRELATION COEFFICIENTS
C
R(L)=R(L)/(SQRT(TII)*SQRT(TJJ))
C
C COMPUTE STANDARD ERRORS OF REGRESSION COEFFICIENTS
C
RR=R(L)**2
SUMX=(TJJ-TJJ*RR)/(FN-2)
S(KI)=SQRT(SUMX/TII)
SUMY=(TII-TII*RR)/(FN-2)
S(KJ)=SQRT(SUMY/TJJ)
C
54 CONTINUE
55 CONTINUE
C
RETURN
END
A(KJ)=