﻿ g02cf Method
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

C#
```public static void g02cf(
int n,
int[] korder,
double[] xbar,
double[] std,
double[,] ssp,
double[,] r,
out int ifail
)```
Visual Basic
```Public Shared Sub g02cf ( _
n As Integer, _
korder As Integer(), _
xbar As Double(), _
std As Double(), _
ssp As Double(,), _
r As Double(,), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02cf(
int n,
array<int>^ korder,
array<double>^ xbar,
array<double>^ std,
array<double,2>^ ssp,
array<double,2>^ r,
[OutAttribute] int% ifail
)```
F#
```static member g02cf :
n : int *
korder : int[] *
xbar : float[] *
std : float[] *
ssp : float[,] *
r : float[,] *
ifail : int byref -> unit
```

#### Parameters

n
Type: System..::..Int32
On entry: $n$, the number of variables in the input data.
Constraint: ${\mathbf{n}}\ge 2$.
korder
Type: array<System..::..Int32>[]()[][]
An array of size [n]
On entry: ${\mathbf{korder}}\left[\mathit{i}-1\right]$ must be set to the number of the original variable which is to be the $\mathit{i}$th variable in the re-arranged data, for $\mathit{i}=1,2,\dots ,n$.
Constraint: $1\le {\mathbf{korder}}\left[\mathit{i}\right]\le {\mathbf{n}}$, for $\mathit{i}=0,1,\dots ,n-1$.
xbar
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: ${\mathbf{xbar}}\left[\mathit{i}-1\right]$ must be set to the mean of variable $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
On exit: ${\mathbf{xbar}}\left[\mathit{i}-1\right]$ contains the mean of variable $k$ where $k={\mathbf{korder}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$.
std
Type: array<System..::..Double>[]()[][]
An array of size [n]
On entry: ${\mathbf{std}}\left[\mathit{i}-1\right]$ must be set to the standard deviation of variable $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
On exit: ${\mathbf{std}}\left[\mathit{i}-1\right]$ contains the standard deviation of variable $k$ where $k={\mathbf{korder}}\left[\mathit{i}-1\right]$, for $\mathit{i}=1,2,\dots ,n$.
ssp
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: ${\mathbf{ssp}}\left[\mathit{i}-1,\mathit{j}-1\right]$ must be set to the sum of cross-products of deviations from means ${S}_{\mathit{i}\mathit{j}}$ (or about zero ${\stackrel{~}{S}}_{\mathit{i}\mathit{j}}$) for variables $\mathit{i}$ and $\mathit{j}$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,n$.
On exit: ${\mathbf{ssp}}\left[i-1,j-1\right]$ contains the sum of cross-products of deviations from means ${S}_{kl}$ (or about zero ${\stackrel{~}{S}}_{kl}$) for variables $k$ and $l$, where $k={\mathbf{korder}}\left[i-1\right]$, and $l={\mathbf{korder}}\left[j-1\right]$, $i,j=1,2,\dots ,n$.
r
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, n]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: ${\mathbf{r}}\left[\mathit{i}-1,\mathit{j}-1\right]$ must be set to the Pearson product-moment correlation coefficient ${R}_{\mathit{i}\mathit{j}}$ (or the correlation-like coefficient ${\stackrel{~}{R}}_{\mathit{i}\mathit{j}}$) for variables $\mathit{i}$ and $\mathit{j}$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,n$.
On exit: ${\mathbf{r}}\left[\mathit{i}-1,\mathit{j}-1\right]$ contains the Pearson product-moment correlation coefficient ${R}_{kl}$ (or the correlation-like coefficient ${\stackrel{~}{R}}_{kl}$) for variables $k$ and $l$, where $k={\mathbf{korder}}\left[\mathit{i}-1\right]$ and $l={\mathbf{korder}}\left[\mathit{j}-1\right]$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,n$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

Input to the method consists of:
(a) A list of the order in which the $n$ variables are to be arranged on exit:
 $i1,i2,i3,…,in.$
(b) A vector of means:
 $x-1,x-2,x-3,…,x-n.$
(c) A vector of standard deviations:
 $s1,s2,s3,…,sn.$
(d) A matrix of sums of squares and cross-products of deviations from means:
 $S11S12S13...S1nS21S22.S31.......Sn1Sn2....Snn.$
(e) A matrix of correlation coefficients:
 $R11R12R13...R1nR21R22.R31.......Rn1Rn2....Rnn.$
On exit from the method, these same vectors and matrices are reordered, in the manner specified, and contain the following information:
(i) The vector of means:
 $x-i1,x-i2,x-i3,…,x-in.$
(ii) The vector of standard deviations:
 $si1,si2,si3,…sin.$
(iii) The matrix of sums of squares and cross-products of deviations from means:
 $Si1i1Si1i2Si1i3...Si1inSi2i1Si2i2.Si3i1.......Sini1Sini2....Sinin.$
(iv) The matrix of correlation coefficients:
 $Ri1i1Ri1i2Ri1i3...Ri1inRi2i1Ri2i2.Ri3i1.......Rini1Rini2....Rinin.$
Note:  for sums of squares of cross-products of deviations about zero and correlation-like coefficients ${S}_{ij}$ and ${R}_{ij}$ should be replaced by ${\stackrel{~}{S}}_{ij}$ and ${\stackrel{~}{R}}_{ij}$ in the description of the input and output above.

None.

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDSSP, LDR) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<2$.
${\mathbf{ifail}}=3$
 On entry, ${\mathbf{korder}}\left[i-1\right]<1$, or ${\mathbf{korder}}\left[i-1\right]>{\mathbf{n}}$ for some $i=1,2,\dots ,n$.
${\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.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

Not applicable.

# Parallelism and Performance

None.

The time taken by g02cf depends on $n$ and the amount of re-arrangement involved.
The method 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 method should not also be used to reorder vectors and matrices which contain any other non-statistical information; the matrices need not be symmetric.
The method 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

This example reads in the means, standard deviations, sums of squares and cross-products, and correlation coefficients for three variables. The vectors and matrices are reordered so that they contain the means, standard deviations, sums of squares and cross-products, and correlation coefficients for the first, third and second variables (in that order). Finally the reordered vectors and matrices are printed.

Example program (C#): g02cfe.cs

Example program data: g02cfe.d

Example program results: g02cfe.r