Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

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

None.

## Parameters

### Compulsory Input Parameters

1:     m – int64int32nag_int scalar
m$m$, the number of variables.
Constraint: m1${\mathbf{m}}\ge 1$.
2:     r((m × m + m) / 2$\left({\mathbf{m}}×{\mathbf{m}}+{\mathbf{m}}\right)/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$j$ and k$k$, kj$k\ge j$, is stored in r((k × (k1) / 2 + j))${\mathbf{r}}\left(\left(k×\left(k-1\right)/2+j\right)\right)$.

None.

None.

### Output Parameters

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

ifail = 1${\mathbf{ifail}}=1$
 On entry, m < 1${\mathbf{m}}<1$.
W ifail = 2${\mathbf{ifail}}=2$
A variable has a zero variance. All correlations involving the variable with zero variance will be returned as zero.

## 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

```function nag_correg_ssqmat_to_corrmat_example
m = int64(3);
r = [8.75689620235916;
3.697844992253459;
1.59053509294466;
4.070728079123907;
1.686058157917487;
1.929668337915273];
[rOut, ifail] = nag_correg_ssqmat_to_corrmat(m, r)
```
```

rOut =

1.0000
0.9908
1.0000
0.9903
0.9624
1.0000

ifail =

0

```
```function g02bw_example
m = int64(3);
r = [8.75689620235916;
3.697844992253459;
1.59053509294466;
4.070728079123907;
1.686058157917487;
1.929668337915273];
[rOut, ifail] = g02bw(m, r)
```
```

rOut =

1.0000
0.9908
1.0000
0.9903
0.9624
1.0000

ifail =

0

```