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)

## 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 ${c}_{jk}$ be the cross-product of deviations from the mean, for $\mathit{j}=1,2,\dots ,m$ and $\mathit{k}=j,\dots ,m$, then the product-moment correlation coefficient, ${r}_{jk}$ is given by
 $rjk=cjkcjjckk .$

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}}×{\mathbf{m}}+{\mathbf{m}}\right)/2\right)$ – 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$, $k\ge j$, is stored in ${\mathbf{r}}\left(\left(k×\left(k-1\right)/2+j\right)\right)$.

None.

### Output Parameters

1:     $\mathrm{r}\left(\left({\mathbf{m}}×{\mathbf{m}}+{\mathbf{m}}\right)/2\right)$ – double array
The Pearson product-moment correlation coefficients.
These are stored packed by column corresponding to the input cross-products.
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.

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