PDF version (NAG web site
, 64bit version, 64bit version)
NAG Toolbox: nag_correg_ssqmat_to_corrmat (g02bw)
Purpose
nag_correg_ssqmat_to_corrmat (g02bw) calculates a matrix of Pearson productmoment correlation coefficients from sums of squares and crossproducts of deviations about the mean.
Syntax
[
r,
ifail] = nag_correg_ssqmat_to_corrmat(
m,
r)
Description
nag_correg_ssqmat_to_corrmat (g02bw) calculates a matrix of Pearson productmoment correlation coefficients from sums of squares and crossproducts 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 crossproducts are stored in an array packed by column and are overwritten by the correlation coefficients.
Let
${c}_{jk}$ be the crossproduct of deviations from the mean, for
$\mathit{j}=1,2,\dots ,m$ and
$\mathit{k}=j,\dots ,m$, then the productmoment correlation coefficient,
${r}_{jk}$ is given by
References
None.
Parameters
Compulsory Input Parameters
 1:
$\mathrm{m}$ – int64int32nag_int scalar

$m$, the number of variables.
Constraint:
${\mathbf{m}}\ge 1$.
 2:
$\mathrm{r}\left(\left({\mathbf{m}}\times {\mathbf{m}}+{\mathbf{m}}\right)/2\right)$ – double array

Contains the upper triangular part of the sums of squares and crossproducts matrix of deviations from the mean. These are stored packed by column, i.e., the crossproduct between variable $j$ and $k$, $k\ge j$, is stored in ${\mathbf{r}}\left(\left(k\times \left(k1\right)/2+j\right)\right)$.
Optional Input Parameters
None.
Output Parameters
 1:
$\mathrm{r}\left(\left({\mathbf{m}}\times {\mathbf{m}}+{\mathbf{m}}\right)/2\right)$ – double array

The Pearson productmoment correlation coefficients.
These are stored packed by column corresponding to the input crossproducts.
 2:
$\mathrm{ifail}$ – int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{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.
 ${\mathbf{ifail}}=1$

On entry,  ${\mathbf{m}}<1$. 
 W ${\mathbf{ifail}}=2$

A variable has a zero variance. All correlations involving the variable with zero variance will be returned as zero.
 ${\mathbf{ifail}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
 ${\mathbf{ifail}}=399$
Your licence key may have expired or may not have been installed correctly.
 ${\mathbf{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 variancecovariance 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 crossproducts 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.
Open in the MATLAB editor:
g02bw_example
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);
[sw, wmean, c, ifail] = g02bu(x, 'wt', wt);
[r, ifail] = g02bw(m, c);
mtitle = 'Correlation matrix:';
uplo = 'Upper';
diag = 'Nonunit';
[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
, 64bit version, 64bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015