G2 orrelation and Regression Analysis NAG Library Routine Document Note before using this routine, please read the Users Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details Purpose reorders the elements in two vectors (typically vectors of means and standard deviations), and the rows and columns in two matrices (typically either matrices of sums of squares and cross-products of deviations from means and Pearson product-moment correlation coefficients, or matrices of sums of squares and cross-products about zero and correlation-like coefficients) 2 Specification SUROUTINE (N, KORDER, XAR, STD, SSP, LDSSP, R, LDR, KWORK, IFAIL) INTEGER N, KORDER(N), LDSSP, LDR, KWORK(N), IFAIL double precision XAR(N), STD(N), SSP(LDSSP,N), R(LDR,N) 3 Description Input to the routine consists of (a) A list of the order in which the n variables are to be arranged on exit i ;i 2 ;i 3 ; ;i n (b) A vector of means ðx ; x 2 ; x 3 ; ; x n Þ (c) A vector of standard deviations ðs ;s 2 ;s 3 ; ;s n Þ (d) A matrix of sums of squares and cross-products of deviations from means S S 2 S 3 S n S 2 S 22 S 3 @ A S n S n2 S nn (e) A matrix of correlation coefficients R R 2 R 3 R n R 2 R 22 R 3 @ A R n R n2 R nn On exit from the routine, these same vectors and matrices are reordered, in the manner specified, and contain the following information
NAG Library Manual (i) The vector of means x i ; x i2 ; x i3 ; ; x in (ii) The vector of standard deviations s i ;s i2 ;s i3 ; s in (iii) The matrix of sums of squares and cross-products of deviations from means S i i S i i 2 S i i 3 S i i n S i2 i S i2 i 2 S i3 i @ A S in i S in i 2 S in i n (iv) The matrix of correlation coefficients R i i R i i 2 R i i 3 R i i n R i2 i R i2 i 2 R i3 i @ A R in i R in i 2 R in i n Note for sums of squares of cross-products of deviations about zero and correlation-like coefficients S ij and R ij should be replaced by ~ S ij and ~R ij in the description of the input and output above 4 References None 5 Parameters N INTEGER Input On entry n, the number of variables in the input data onstraint N 2 2 KORDERðNÞ INTEGER array Input On entry KORDERðiÞ must be set to the number of the original variable which is to be the ith variable in the re-arranged data, for i ¼ ; 2; ;n onstraint KORDERðiÞ N, for i ¼ ; 2; ;n 3 XARðNÞ double precision array Input/Output On entry XARðiÞ must be set to the mean of variable i, for i ¼ ; 2; ;n On exit XARðiÞ contains the mean of variable k where k ¼ KORDERðiÞ, for i ¼ ; 2; ;n 4 STDðNÞ double precision array Input/Output On entry STDðiÞ must be set to the standard deviation of variable i, for i ¼ ; 2; ;n On exit STDðiÞ contains the standard deviation of variable k where k ¼ KORDERðiÞ, for i ¼ ; 2; ;n 2
G2 orrelation and Regression Analysis 5 SSPðLDSSP,NÞ double precision array Input/Output On entry SSPði; jþ must be set to the sum of cross-products of deviations from means S ij (or about zero S ~ ij ) for variables i and j, for i; j ¼ ; 2; ;n On exit SSPði; jþ contains the sum of cross-products of deviations from means S kl (or about zero ~S kl ) for variables k and l, where k ¼ KORDERðiÞ, and l ¼ KORDERðjÞ, i; j ¼ ; 2; ;n 6 LDSSP INTEGER Input On entry the first dimension of the array SSP as declared in the (sub)program from which is called onstraint LDSSP N 7 RðLDR,NÞ double precision array Input/Output On entry Rði; jþ must be set to the Pearson product-moment correlation coefficient R ij (or the correlation-like coefficient ~R ij ) for variables i and j, for i; j ¼ ; 2; ;n On exit Rði; jþ contains the Pearson product-moment correlation coefficient R kl (or the correlationlike coefficient ~R kl ) for variables k and l, where k ¼ KORDERðiÞ and l ¼ KORDERðjÞ, for i; j ¼ ; 2; ;n 8 LDR INTEGER Input On entry the first dimension of the array R as declared in the (sub)program from which is called onstraint LDR N 9 KWORKðNÞ INTEGER array Workspace IFAIL INTEGER Input/Output On entry IFAIL must be set to, or If you are unfamiliar with this parameter you should refer to Section 33 in the Essential Introduction for details On exit IFAIL ¼ unless the routine detects an error (see Section 6) For environments where it might be inappropriate to halt program execution when an error is detected, the value or is recommended If the output of error messages is undesirable, then the value is recommended Otherwise, if you are not familiar with this parameter, the recommended value is When the value or is used it is essential to test the value of IFAIL on exit 6 Error Indicators and Warnings If on entry IFAIL ¼ or, explanatory error messages are output on the current error message unit (as defined by X4AAF) Errors or warnings detected by the routine IFAIL ¼ On entry, N < 2 IFAIL ¼ 2 On entry, LDSSP < N, or LDR < N 3
NAG Library Manual IFAIL ¼ 3 On entry, KORDERðiÞ <, or KORDERðiÞ > N for some i ¼ ; 2; ;n IFAIL ¼ 4 On entry, there is not a one-to-one correspondence between the old variables and the new variables; at least one of the original variables is not included in the new set, and consequently at least one other variable has been included more than once 7 Accuracy Not applicable 8 Further omments The time taken by depends on n and the amount of re-arrangement involved The routine is intended primarily for use when a set of variables is to be reordered for use in a regression, and is described accordingly There is however no reason why the routine should not also be used to reorder vectors and matrices which contain any other non-statistical information; the matrices need not be symmetric The routine may be used either with sums of squares and cross-products of deviations from means and Pearson product-moment correlation coefficients in connection with a regression involving a constant, or with sums of squares and cross-products about zero and correlation-like coefficients in connection with a regression with no constant 9 Example This example reads in the means, standard deviations, sums of squares and cross-products, and correlation coefficients for three variables The vectors and matrices are reordered so that they contain the means, standard deviations, sums of squares and cross-products, and correlation coefficients for the first, third and second variables (in that order) Finally the reordered vectors and matrices are printed 9 Program Text * Example Program Text * Mark 4 Revised NAG opyright 989 * Parameters INTEGER N, LDSSP, LDR PARAMETER (N=3,LDSSP=N,LDR=N) INTEGER NIN, NOUT PARAMETER (NIN=5,NOUT=6) * Local Scalars INTEGER I, IFAIL, J * Local Arrays DOULE PREISION R(LDR,N), SSP(LDSSP,N), STD(N), XAR(N) INTEGER KORDER(N), KWORK(N) * External Subroutines EXTERNAL * Executable Statements Example Program Results * Skip heading in data file READ (NIN,*) READ (NIN,*) (XAR(I),I=,N), (STD(I),I=,N), + ((SSP(I,J),J=,N),I=,N), ((R(I,J),J=,N),I=,N) WRITE (NOUT,99999) Original vector XAR, (XAR(I),I=,N) WRITE (NOUT,99999) Original vector STD, (STD(I),I=,N) Original matrix SSP WRITE (NOUT,99998) ((SSP(I,J),J=,N),I=,N) 4
G2 orrelation and Regression Analysis Original matrix R WRITE (NOUT,99998) ((R(I,J),J=,N),I=,N) KORDER() = KORDER(2) = 3 KORDER(3) = 2 IFAIL = * ALL (N,KORDER,XAR,STD,SSP,LDSSP,R,LDR,KWORK,IFAIL) * IF (IFAILNE) THEN WRITE (NOUT,99997) ** returned with IFAIL =, IFAIL ELSE WRITE (NOUT,99996) New vector XAR, (XAR(I),I=,N) WRITE (NOUT,99996) New vector STD, (STD(I),I=,N) New matrix SSP WRITE (NOUT,99995) ((SSP(I,J),J=,N),I=,N) New matrix R WRITE (NOUT,99995) ((R(I,J),J=,N),I=,N) END IF * 99999 FORMAT (X,A,3F4) 99998 FORMAT (X,3F4) 99997 FORMAT (X,A,I5) 99996 FORMAT (X,A,3F4) 99995 FORMAT (X,3F4) END 92 Program Data Example Program Data 54 58 28 498 5695 924 992-576 64-576 28-292 64-292 48-574 67-574 -7486 67-7486 93 Program Results Example Program Results Original vector XAR 54 58 28 Original vector STD 498 5695 924 Original matrix SSP 992-576 64-576 28-292 64-292 48 Original matrix R -574 67-574 -7486 67-7486 New vector XAR 54 28 58 New vector STD 498 924 5695 New matrix SSP 992 64-576 64 48-292 5
NAG Library Manual -576-292 28 New matrix R 67-574 67-7486 -574-7486 6 (last)