hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_ssqmat_to_corrmat (g02bw)

 Contents

    1  Purpose
    2  Syntax
    7  Accuracy
    9  Example

Purpose

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

Syntax

[r, ifail] = g02bw(m, r)
[r, ifail] = nag_correg_ssqmat_to_corrmat(m, r)

Description

nag_correg_ssqmat_to_corrmat (g02bw) 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 nag_correg_ssqmat (g02bu) or a series of calls to nag_correg_ssqmat_update (g02bt). 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 .  

References

None.

Parameters

Compulsory Input Parameters

1:     m int64int32nag_int scalar
m, the number of variables.
Constraint: m1.
2:     rm×m+m/2 – double array
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.

Optional Input Parameters

None.

Output Parameters

1:     rm×m+m/2 – double array
The Pearson product-moment correlation coefficients.
These are stored packed by column corresponding to the input cross-products.
2:     ifail int64int32nag_int scalar
ifail=0 unless the function detects an error (see Error Indicators and Warnings).

Error Indicators and Warnings

Note: nag_correg_ssqmat_to_corrmat (g02bw) may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

   ifail=1
On entry,m<1.
W  ifail=2
A variable has a zero variance. All correlations involving the variable with zero variance will be returned as zero.
   ifail=-99
An unexpected error has been triggered by this routine. Please contact NAG.
   ifail=-399
Your licence key may have expired or may not have been installed correctly.
   ifail=-999
Dynamic memory allocation failed.

Accuracy

The accuracy of nag_correg_ssqmat_to_corrmat (g02bw) is entirely dependent upon the accuracy of the elements of array r.

Further Comments

nag_correg_ssqmat_to_corrmat (g02bw) 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.

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 nag_correg_ssqmat (g02bu). The correlation matrix is then calculated from these values.
function g02bw_example


fprintf('g02bw example results\n\n');

wt = [  0.1300   1.3070   0.3700];
x  = [  9.1231   3.7011   4.5230;
        0.9310   0.0900   0.8870;
        0.0009   0.0099   0.0999];

[m, n] = size(x);
m      = int64(m);

% Calculate the sums of squares and cross-products matrix
[sw, wmean, c, ifail] = g02bu(x, 'wt', wt);

% Calculate the correlation matrix
[r, ifail] = g02bw(m, c);

mtitle = 'Correlation matrix:';
uplo   = 'Upper';
diag   = 'Non-unit';
[ifail] = x04cc( ...
                 uplo, diag, m, r, mtitle);


g02bw example results

 Correlation matrix:
          1       2       3
 1   1.0000  0.9908  0.9903
 2           1.0000  0.9624
 3                   1.0000

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015