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_linregm_service_reorder (g02cf)

## Purpose

nag_correg_linregm_service_reorder (g02cf) reorders the elements in two vectors (typically vectors of means and standard deviations), and the rows and columns in two matrices (typically either matrices of sums of squares and cross-products of deviations from means and Pearson product-moment correlation coefficients, or matrices of sums of squares and cross-products about zero and correlation-like coefficients).

## Syntax

[xbar, std, ssp, r, ifail] = g02cf(korder, xbar, std, ssp, r, 'n', n)
[xbar, std, ssp, r, ifail] = nag_correg_linregm_service_reorder(korder, xbar, std, ssp, r, 'n', n)

## Description

Input to the function consists of:
(a) A list of the order in which the n$n$ variables are to be arranged on exit:
 i1,i2,i3, … ,in. $i1,i2,i3,…,in.$
(b) A vector of means:
 ( x1,x2,x3, … ,xn) . $(x-1,x-2,x-3,…,x-n) .$
(c) A vector of standard deviations:
 (s1,s2,s3, … ,sn). $(s1,s2,s3,…,sn).$
(d) A matrix of sums of squares and cross-products of deviations from means:
 S11 S12 S13 . . . S1n S21 S22 . S31 . . . . . . . Sn1 Sn2 . . . . Snn
.
$S11 S12 S13 . . . S1n S21 S22 . S31 . . . . . . . Sn1 Sn2 . . . . Snn .$
(e) A matrix of correlation coefficients:
 R11 R12 R13 . . . R1n R21 R22 . R31 . . . . . . . Rn1 Rn2 . . . . Rnn
.
$R11 R12 R13 . . . R1n R21 R22 . R31 . . . . . . . Rn1 Rn2 . . . . Rnn .$
On exit from the function, these same vectors and matrices are reordered, in the manner specified, and contain the following information:
(i) The vector of means:
 (xi1,xi2,xi3, … ,xin) . $(x-i1,x-i2,x-i3,…,x-in) .$
(ii) The vector of standard deviations:
 (si1,si2,si3, … sin). $(si1,si2,si3,…sin).$
(iii) The matrix of sums of squares and cross-products of deviations from means:
 Si_1i_1 Si_1i_2 Si_1i_3 . . . Si_1i_n Si_2i_1 Si_2i_2 . Si_3i_1 . . . . . . . Si_ni_1 Si_ni_2 . . . . Si_ni_n
.
$Si1i1 Si1i2 Si1i3 . . . Si1in Si2i1 Si2i2 . Si3i1 . . . . . . . Sini1 Sini2 . . . . Sinin .$
(iv) The matrix of correlation coefficients:
 Ri_1i_1 Ri_1i_2 Ri_1i_3 . . . Ri_1i_n Ri_2i_1 Ri_2i_2 . Ri_3i_1 . . . . . . . Ri_ni_1 Ri_ni_2 . . . . Ri_ni_n
.
$Ri1i1 Ri1i2 Ri1i3 . . . Ri1in Ri2i1 Ri2i2 . Ri3i1 . . . . . . . Rini1 Rini2 . . . . Rinin .$
Note:  for sums of squares of cross-products of deviations about zero and correlation-like coefficients Sij${S}_{ij}$ and Rij${R}_{ij}$ should be replaced by ij${\stackrel{~}{S}}_{ij}$ and ij${\stackrel{~}{R}}_{ij}$ in the description of the input and output above.

None.

## Parameters

### Compulsory Input Parameters

1:     korder(n) – int64int32nag_int array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
korder(i)${\mathbf{korder}}\left(\mathit{i}\right)$ must be set to the number of the original variable which is to be the i$\mathit{i}$th variable in the re-arranged data, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
Constraint: 1korder(i)n$1\le {\mathbf{korder}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     xbar(n) – double array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
xbar(i)${\mathbf{xbar}}\left(\mathit{i}\right)$ must be set to the mean of variable i$\mathit{i}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
3:     std(n) – double array
n, the dimension of the array, must satisfy the constraint n2${\mathbf{n}}\ge 2$.
std(i)${\mathbf{std}}\left(\mathit{i}\right)$ must be set to the standard deviation of variable i$\mathit{i}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
4:     ssp(ldssp,n) – double array
ldssp, the first dimension of the array, must satisfy the constraint ldsspn$\mathit{ldssp}\ge {\mathbf{n}}$.
ssp(i,j)${\mathbf{ssp}}\left(\mathit{i},\mathit{j}\right)$ must be set to the sum of cross-products of deviations from means Sij${S}_{\mathit{i}\mathit{j}}$ (or about zero ij${\stackrel{~}{S}}_{\mathit{i}\mathit{j}}$) for variables i$\mathit{i}$ and j$\mathit{j}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
5:     r(ldr,n) – double array
ldr, the first dimension of the array, must satisfy the constraint ldrn$\mathit{ldr}\ge {\mathbf{n}}$.
r(i,j)${\mathbf{r}}\left(\mathit{i},\mathit{j}\right)$ must be set to the Pearson product-moment correlation coefficient Rij${R}_{\mathit{i}\mathit{j}}$ (or the correlation-like coefficient ij${\stackrel{~}{R}}_{\mathit{i}\mathit{j}}$) for variables i$\mathit{i}$ and j$\mathit{j}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays korder, xbar, std and the first dimension of the arrays ssp, r and the second dimension of the arrays ssp, r. (An error is raised if these dimensions are not equal.)
n$n$, the number of variables in the input data.
Constraint: n2${\mathbf{n}}\ge 2$.

ldssp ldr kwork

### Output Parameters

1:     xbar(n) – double array
xbar(i)${\mathbf{xbar}}\left(\mathit{i}\right)$ contains the mean of variable k$k$ where k = korder(i)$k={\mathbf{korder}}\left(\mathit{i}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     std(n) – double array
std(i)${\mathbf{std}}\left(\mathit{i}\right)$ contains the standard deviation of variable k$k$ where k = korder(i)$k={\mathbf{korder}}\left(\mathit{i}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
3:     ssp(ldssp,n) – double array
ldsspn$\mathit{ldssp}\ge {\mathbf{n}}$.
ssp(i,j)${\mathbf{ssp}}\left(i,j\right)$ contains the sum of cross-products of deviations from means Skl${S}_{kl}$ (or about zero kl${\stackrel{~}{S}}_{kl}$) for variables k$k$ and l$l$, where k = korder(i)$k={\mathbf{korder}}\left(i\right)$, and l = korder(j)$l={\mathbf{korder}}\left(j\right)$, i,j = 1,2,,n$i,j=1,2,\dots ,n$.
4:     r(ldr,n) – double array
ldrn$\mathit{ldr}\ge {\mathbf{n}}$.
r(i,j)${\mathbf{r}}\left(\mathit{i},\mathit{j}\right)$ contains the Pearson product-moment correlation coefficient Rkl${R}_{kl}$ (or the correlation-like coefficient kl${\stackrel{~}{R}}_{kl}$) for variables k$k$ and l$l$, where k = korder(i)$k={\mathbf{korder}}\left(\mathit{i}\right)$ and l = korder(j)$l={\mathbf{korder}}\left(\mathit{j}\right)$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ and j = 1,2,,n$\mathit{j}=1,2,\dots ,n$.
5:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:
ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 2${\mathbf{n}}<2$.
ifail = 2${\mathbf{ifail}}=2$
 On entry, ldssp < n$\mathit{ldssp}<{\mathbf{n}}$, or ldr < n$\mathit{ldr}<{\mathbf{n}}$.
ifail = 3${\mathbf{ifail}}=3$
 On entry, korder(i) < 1${\mathbf{korder}}\left(i\right)<1$, or korder(i) > n${\mathbf{korder}}\left(i\right)>{\mathbf{n}}$ for some i = 1,2, … ,n$i=1,2,\dots ,n$.
ifail = 4${\mathbf{ifail}}=4$
On entry, there is not a one-to-one correspondence between the old variables and the new variables; at least one of the original variables is not included in the new set, and consequently at least one other variable has been included more than once.

## Accuracy

Not applicable.

The time taken by nag_correg_linregm_service_reorder (g02cf) depends on n$n$ and the amount of re-arrangement involved.
The function is intended primarily for use when a set of variables is to be reordered for use in a regression, and is described accordingly. There is however no reason why the function should not also be used to reorder vectors and matrices which contain any other non-statistical information; the matrices need not be symmetric.
The function may be used either with sums of squares and cross-products of deviations from means and Pearson product-moment correlation coefficients in connection with a regression involving a constant, or with sums of squares and cross-products about zero and correlation-like coefficients in connection with a regression with no constant.

## Example

```function nag_correg_linregm_service_reorder_example
korder = [int64(1);3;2];
xbar = [5.4;
5.8;
2.8];
std = [4.98;
5.0695;
1.924];
ssp = [99.2, -57.6, 6.4;
-57.6, 102.8, -29.2;
6.4, -29.2, 14.8];
r = [1, -0.5704, 0.167;
-0.5704, 1, -0.7486;
0.167, -0.7486, 1];
[xbarOut, stdOut, sspOut, rOut, ifail] = ...
nag_correg_linregm_service_reorder(korder, xbar, std, ssp, r)
```
```

xbarOut =

5.4000
2.8000
5.8000

stdOut =

4.9800
1.9240
5.0695

sspOut =

99.2000    6.4000  -57.6000
6.4000   14.8000  -29.2000
-57.6000  -29.2000  102.8000

rOut =

1.0000    0.1670   -0.5704
0.1670    1.0000   -0.7486
-0.5704   -0.7486    1.0000

ifail =

0

```
```function g02cf_example
korder = [int64(1);3;2];
xbar = [5.4;
5.8;
2.8];
std = [4.98;
5.0695;
1.924];
ssp = [99.2, -57.6, 6.4;
-57.6, 102.8, -29.2;
6.4, -29.2, 14.8];
r = [1, -0.5704, 0.167;
-0.5704, 1, -0.7486;
0.167, -0.7486, 1];
[xbarOut, stdOut, sspOut, rOut, ifail] = g02cf(korder, xbar, std, ssp, r)
```
```

xbarOut =

5.4000
2.8000
5.8000

stdOut =

4.9800
1.9240
5.0695

sspOut =

99.2000    6.4000  -57.6000
6.4000   14.8000  -29.2000
-57.6000  -29.2000  102.8000

rOut =

1.0000    0.1670   -0.5704
0.1670    1.0000   -0.7486
-0.5704   -0.7486    1.0000

ifail =

0

```