1 SUBROUTINE REGRESS_ONE(NX
,XBAR
,YBAR
,XCOV
,YCOV
,XYCOV
,NXEIGS
,CCOF
,CCOF0
,RESERR
,RESCOV
,XVEC
)
6 ! ROUTINE CALCF2 SUBROUTINE ***** |EYRE.TOVFFG@
8 ! PURPOSE EIGENVECTOR REGRESSION ROUTINE
10 ! VERSION 3.00,190491,J.R.EYRE
12 ! DESCRIPTION ROUTINE TO CALCULATE EIGENVECTOR REGRESSION COEFFICIENT
13 ! Y AGAINST VECTOR X FROM COVARIANCE MATRICES XYCOV AND
14 ! XCOV, WHICH CONTAINS THE COVARIANCE MATRICES OF Y AND X
16 ! ARGUMENTS XBAR R*8 MEAN VECTOR OF PREDICTORS, LENGTH NX
17 ! YBAR R*8 MEAN VALUE OF PREDICTANT
18 ! XCOV R*8 COVARIANCE MATRIX (NX*NX) OF PREDICTORS
19 ! XYCOV R*8 CROSS-COVARIANCE MATRIX (NX) OF PREDICTORS/PREDICTANT
20 ! NX I*4 NUMBER OF PREDICTORS
21 ! NXEIGS I*4 NUMBER OF EIGENVECTORS OF PREDICTOR USED IN
22 ! THE REGRESSION EQUATION
23 ! CCOF R*8 OUTPUT MATRIX (NX) OF REGRESSION COEFF
24 ! SUCH THAT: Y = CCOF0 + CCOF.X
25 ! CCOF0 R*8 OFFSET IN ABOVE EQUATION
26 ! RESERR R*8 RESIDUAL ERROR IN PREDICANT
27 ! RESCOV R*8 RESIDUAL VARIANCE IN PREDICTANT
28 ! XVEC R*8 OUTPUT MATRIX (NX*NX) OF PREDICTOR EIGENVECTORS
30 ! SUBPROGRAMS F02ABF, F01ABF (nag)
32 ! FILES UNIT(6) DIAGNOSTIC OUTPUT
34 ! 14 JAN 88. MADISON VERSION CHANGED BACK FOR HOMER.
35 ! 13 MAY 97. REWRITTEN IN F90 (B.Harris)
37 INTEGER, PARAMETER :: JWORK
=4900
38 INTEGER, PARAMETER :: JMPRED
=70
41 INTEGER, INTENT(IN
) :: NX
, NXEIGS
44 REAL(KIND
=LONG
), INTENT(IN
) :: XBAR(NX
), YBAR
, XCOV(NX
,NX
), XYCOV(NX
), YCOV
46 REAL(KIND
=LONG
), INTENT(OUT
) :: CCOF(NX
), CCOF0
47 REAL(KIND
=LONG
), INTENT(OUT
) :: RESERR
, RESCOV
48 REAL(KIND
=LONG
), INTENT(OUT
) :: XVEC(NX
,NX
)
50 REAL(KIND
=LONG
) :: XDEV(NX
), XXBAR(NX
)
51 REAL(KIND
=LONG
) :: YVEC
, XVAL(NX
), YVAL
, DET
, D(NX
)
52 REAL(KIND
=LONG
) :: XW1(NX
,NX
), XW2(NX
,NX
), YW1
, XYW1(NX
), YXW1(NX
), XINV(NX
,NX
), XYW2(NX
)
53 REAL(KIND
=LONG
) :: W1(JWORK
)
56 INTEGER :: IPIV(JMPRED
)
57 INTEGER :: NWORK
= JWORK
59 INTEGER :: J
, JJ
, I
, II
62 REAL(KIND
=LONG
) :: offdiag(NX
)
70 ! CHECK INPUT PARAMETERS
71 IF ((NX
< 1) .OR
. (NX
> JMPRED
)) STOP 701
72 IF ((NXEIG
< 1) .OR
. (NXEIG
> NX
)) STOP 702
75 ! PREDICTOR = XCOV, SIZE = NX*NX
77 ! CROSS-COVARIANCE = XYCOV, SIZE = NX
80 XDEV(I
) = SQRT(XCOV(I
,I
))
83 PRINT *, 'PREDICTOR STD DEV AND MEAN NEW F02FAF'
87 ! *** CALCULATE EIGENVECTOR REGRESSION COEFFICIENTS
89 ! CALCULATE EIGENVECTORS AND EIGENVALUES OF XCOV:
92 ! PRINT *, 'PREDICTOR COVARIANCE MATRIX XCOV'
94 ! PRINT 99, XCOV(1:NX,J)
98 ! XW1(I,J) = XCOV(I,J)/SQRT(XCOV(I,I)*XCOV(J,J))
101 ! PRINT *, 'PREDICTOR CORRELATION MATRIX'
103 ! PRINT 99, XW1(1:NX,J)
106 ! CALL F02ABF(XCOV,NX,NX,XVAL,XVEC,NX,W1,IFAIL)
108 ! CALL F02FAF('V','L',NX,XVEC,NX,XVAL,W1,JWORK,IFAIL)
109 ! tranform matrix to tridiagonal form
110 call tred2(XVEC
,NX
,NX
,XVAL
,offdiag
)
112 call tqli(XVAL
,offdiag
,NX
,NX
,XVEC
)
115 PRINT *, 'PROBLEM WITH PREDICTOR EIGENVALUE CALCULATION'
120 89 FORMAT (/1X
,'XVAL = EIGENVALUES OF PREDICTOR in one and two zero')
122 99 FORMAT (1X
,10F12
.4
)
124 PRINT *, 'EIGENVECTORS OF PREDICTOR BY COLUMN'
125 XVEC(1:NX
,1:(NXEIG
-NXEIGS
))=0
127 PRINT 99, XVEC(I
,1:NX
)
131 XXBAR
= MATMUL(XBAR
,XVEC
)
132 PRINT *, 'MEAN VALUE OF PREDICTORS IN XVEC SPACE'
133 PRINT 99, XXBAR(1:NX
)
135 XYW1
= MATMUL(XYCOV
,XVEC
)
137 ! CALCULATE REGRESSION MATRIX OF EIGENVECTOR COEFFICIENTS:
139 D(NXE
:NXEIG
) = XYW1(NXE
:NXEIG
)/XVAL(NXE
:NXEIG
)
141 ! CALCULATE REGRESSION MATRIX OF Y AGAINST X : CCOF :
144 CCOF
= MATMUL(XVEC(:,NXE
:NXEIG
),D(NXE
:NXEIG
))
146 ! *** CALCULATE OFFSET VECTOR, CCOF0 :
147 ! Y - YBAR = CCOF . (X-XBAR)
148 ! THERFORE Y = CCOF.X + CCOF0, WHERE CCOF0 = YBAR -CCOF.XBAR
150 CCOF0
= YBAR
- SUM(CCOF(NXE
:NX
)*XBAR(NXE
:NX
))
153 ! 86 FORMAT (/1X,'PREDICTIVE MATRIX, CCOF')
158 ! PRINT *, 'CCOF IN XVEC SPACE'
163 XYW1(NXE
:NXEIG
) = MATMUL(XYCOV
,XVEC(:,NXE
:NXEIG
))
164 XYW1(NXE
:NXEIG
) = XYW1(1:NXEIG
) * XYW1(NXE
:NXEIG
)
165 XYW1(NXE
:NXEIG
) = XYW1(1:NXEIG
)/XVAL(NXE
:NXEIG
)
167 PRINT *, 'EXPLANATION OF VARIANCE'
172 PRINT 99, XYW1(I
)/YCOV
174 PRINT 99, (YCOV
- SUM(XYW1(1:NXEIG
)))/YCOV
176 PRINT 99, YCOV
- SUM(XYW1(1:NXEIG
))
179 ! 85 FORMAT (/1X,'OFFSET VECTOR, CCOF0')
182 ! *** CALCULATE RESIDUAL COVARIANCE MATRIX
183 ! = YCOV + CCOF.XCOV.CCOF(TR) - 2.XYCOF.CCOF(TR)
186 XYW1
= MATMUL(CCOF
,XCOV
)
187 XYW1
= XYW1
- 2*XYCOV
188 RESCOV
= YCOV
+ DOT_PRODUCT(XYW1
,YXW1
)
190 ! RESCOV NOW CONTAINS RESIDUAL COVARIANCE(CORRELATION) MATRIX
194 51 FORMAT (/1X
,'RES ERR COV FOR ELEMENT',I5
,' = ',E12
.4
/1X
,'SET TO ZERO')
200 ! 84 FORMAT (/1X,'RESIDUAL ERROR VECTOR, RESERR')
205 END SUBROUTINE REGRESS_ONE