NAG CL Interface
g02bwc (ssqmat_​to_​corrmat)

Settings help

CL Name Style:


1 Purpose

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

2 Specification

#include <nag.h>
void  g02bwc (Integer m, double r[], NagError *fail)
The function may be called by the names: g02bwc, nag_correg_ssqmat_to_corrmat or nag_cov_to_corr.

3 Description

g02bwc 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 g02buc or a series of calls to g02btc. 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 Arguments

1: m Integer Input
On entry: m, the number of variables.
Constraint: m1.
2: r[(m×m+m)/2] double Input/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 r[(k×(k-1)/2+j)-1].
On exit: the Pearson product-moment correlation coefficients.
These are stored packed by column corresponding to the input cross-products.
3: fail NagError * Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).

6 Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, m=value.
Constraint: m1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
NE_ZERO_VARIANCE
A variable has a zero variance. All correlations involving the variable with zero variance will be returned as zero.

7 Accuracy

The accuracy of g02bwc is entirely dependent upon the accuracy of the elements of array r.

8 Parallelism and Performance

g02bwc is not threaded in any implementation.

9 Further Comments

g02bwc 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 functions in this chapter.

10 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 g02buc. The correlation matrix is then calculated from these values.

10.1 Program Text

Program Text (g02bwce.c)

10.2 Program Data

Program Data (g02bwce.d)

10.3 Program Results

Program Results (g02bwce.r)