G02BWF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G02BWF

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.

+ Contents

    1  Purpose
    7  Accuracy

1  Purpose

G02BWF calculates a matrix of Pearson product-moment correlation coefficients from sums of squares and cross-products of deviations about the mean.

2  Specification

SUBROUTINE G02BWF ( M, R, IFAIL)
INTEGER  M, IFAIL
REAL (KIND=nag_wp)  R((M*M+M)/2)

3  Description

G02BWF calculates a matrix of Pearson product-moment correlation coefficients from sums of squares and cross-products about the mean for observations on m variables which can be computed by a single call to G02BUF or a series of calls to G02BTF. The sums of squares and cross-products are stored in an array packed by column and are overwritten by the correlation coefficients.
Let cjk be the cross-product of deviations from the mean, for j=1,2,,m and k=j,,m, then the product-moment correlation coefficient, rjk is given by
rjk=cjkcjjckk .

4  References

None.

5  Parameters

1:     M – INTEGERInput
On entry: m, the number of variables.
Constraint: M1.
2:     R(M×M+M/2) – REAL (KIND=nag_wp) arrayInput/Output
On entry: contains the upper triangular part of the sums of squares and cross-products matrix of deviations from the mean. These are stored packed by column, i.e., the cross-product between variable j and k, kj, is stored in Rk×k-1/2+j.
On exit: Pearson product-moment correlation coefficients.
These are stored packed by column corresponding to the input cross-products.
3:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry IFAIL=0 or -1, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Note: G02BWF may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
IFAIL=1
On entry,M<1.
IFAIL=2
A variable has a zero variance. All correlations involving the variable with zero variance will be returned as zero.

7  Accuracy

The accuracy of G02BWF is entirely dependent upon the accuracy of the elements of array R.

8  Further Comments

G02BWF may also be used to calculate the correlations between parameter estimates from the variance-covariance matrix of the parameter estimates as is given by several routines in this chapter.

9  Example

A program to calculate the correlation matrix from raw data. The sum of squares and cross-products about the mean are calculated from the raw data by a call to G02BUF. The correlation matrix is then calculated from these values.

9.1  Program Text

Program Text (g02bwfe.f90)

9.2  Program Data

Program Data (g02bwfe.d)

9.3  Program Results

Program Results (g02bwfe.r)


G02BWF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2012