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_select (g02ce)

## Purpose

nag_correg_linregm_service_select (g02ce) takes selected elements from two vectors (typically vectors of means and standard deviations) to form two smaller vectors, and selected rows and columns from 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) to form two smaller matrices, allowing reordering of elements in the process.

## Syntax

[xbar2, std2, ssp2, r2, ifail] = g02ce(xbar, std, ssp, r, korder, 'n', n, 'm', m)
[xbar2, std2, ssp2, r2, ifail] = nag_correg_linregm_service_select(xbar, std, ssp, r, korder, 'n', n, 'm', m)

## Description

Input to the function consists of:
(a) A vector of means:
 $x-1,x-2,x-3,…,x-n,$
where $n$ is the number of input variables.
(b) A vector of standard deviations:
 $s1,s2,s3,…,sn.$
(c) A matrix of sums of squares and cross-products of deviations from means:
 $S11 S12 S13 . . . S1n S21 S22 S2n S31 . . . . . . . Sn1 Sn2 . . . . Snn .$
(d) A matrix of correlation coefficients:
 $R11 R12 R13 . . . R1n R21 R22 R2n R31 . . . . . . . Rn1 Rn2 . . . . Rnn .$
(e) The number of variables, $m$, in the required subset, and their row/column numbers in the input data, ${i}_{1},{i}_{2},{i}_{3},\dots ,{i}_{m}$,
New vectors and matrices are output containing the following information:
(i) A vector of means:
 $x-i1,x-i2,x-i3,…,x-im.$
(ii) A vector of standard deviations:
 $si1,si2,si3,…,sim.$
(iii) A matrix of sums of squares and cross-products of deviations from means:
 $Si1i1 Si1i2 Si1i3 . . . Si1im Si2i1 Si2i2 . Si3i1 . . . . . . . Simi1 Simi2 . . . . Simim .$
(iv) A matrix of correlation coefficients:
 $Ri1i1 Ri1i2 Ri1i3 . . . Ri1im Ri2i1 Ri2i2 . Ri3i1 . . . . . . . Rimi1 Rimi2 . . . . Rimim .$
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.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{xbar}\left({\mathbf{n}}\right)$ – double array
${\mathbf{xbar}}\left(\mathit{i}\right)$ must be set to ${\stackrel{-}{x}}_{\mathit{i}}$, the mean of variable $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
2:     $\mathrm{std}\left({\mathbf{n}}\right)$ – double array
${\mathbf{std}}\left(\mathit{i}\right)$ must be set to ${s}_{\mathit{i}}$, the standard deviation of variable $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
3:     $\mathrm{ssp}\left(\mathit{ldssp},{\mathbf{n}}\right)$ – double array
ldssp, the first dimension of the array, must satisfy the constraint $\mathit{ldssp}\ge {\mathbf{n}}$.
${\mathbf{ssp}}\left(\mathit{i},\mathit{j}\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$.
4:     $\mathrm{r}\left(\mathit{ldr},{\mathbf{n}}\right)$ – double array
ldr, the first dimension of the array, must satisfy the constraint $\mathit{ldr}\ge {\mathbf{n}}$.
${\mathbf{r}}\left(\mathit{i},\mathit{j}\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$.
5:     $\mathrm{korder}\left({\mathbf{m}}\right)$int64int32nag_int array
${\mathbf{korder}}\left(\mathit{i}\right)$ must be set to the number of the original variable which is to be the $\mathit{i}$th variable in the output vectors and matrices, for $\mathit{i}=1,2,\dots ,m$.
Constraint: $1\le {\mathbf{korder}}\left(\mathit{i}\right)\le {\mathbf{n}}$, for $\mathit{i}=1,2,\dots ,m$.

### Optional Input Parameters

1:     $\mathrm{n}$int64int32nag_int scalar
Default: the dimension of the arrays 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$, the number of variables in the input data.
Constraint: ${\mathbf{n}}\ge 2$.
2:     $\mathrm{m}$int64int32nag_int scalar
Default: the dimension of the array korder.
The number of variables $m$, required in the reduced vectors and matrices.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.

### Output Parameters

1:     $\mathrm{xbar2}\left({\mathbf{m}}\right)$ – double array
The mean of variable $i$, ${\mathbf{xbar}}\left(i\right)$, where $i={\mathbf{korder}}\left(\mathit{k}\right)$, for $\mathit{k}=1,2,\dots ,m$. (The array xbar2 must differ from xbar and std.)
2:     $\mathrm{std2}\left({\mathbf{m}}\right)$ – double array
The standard deviation of variable $i$, ${\mathbf{std}}\left(i\right)$, where $i={\mathbf{korder}}\left(\mathit{k}\right)$, for $\mathit{k}=1,2,\dots ,m$. (The array std2 must differ from both xbar and std.)
3:     $\mathrm{ssp2}\left(\mathit{ldssp2},{\mathbf{m}}\right)$ – double array
${\mathbf{ssp2}}\left(\mathit{k},\mathit{l}\right)$ contains the value of ${\mathbf{ssp}}\left(i,j\right)$, where $i={\mathbf{korder}}\left(\mathit{k}\right)$ and $j={\mathbf{korder}}\left(\mathit{l}\right)$, for $\mathit{k}=1,2,\dots ,m$ and $\mathit{l}=1,2,\dots ,m$. (The array ssp2 must differ from both ssp and r.)
That is to say: on exit, ${\mathbf{ssp2}}\left(k,l\right)$ contains the sum of cross-products of deviations from means ${S}_{ij}$ (or about zero, ${\stackrel{~}{S}}_{ij}$).
4:     $\mathrm{r2}\left(\mathit{ldr2},{\mathbf{m}}\right)$ – double array
${\mathbf{r2}}\left(\mathit{k},\mathit{l}\right)$ contains the value of ${\mathbf{r}}\left(i,j\right)$, where $i={\mathbf{korder}}\left(\mathit{k}\right)$ and $j={\mathbf{korder}}\left(\mathit{l}\right)$, for $\mathit{k}=1,2,\dots ,m$ and $\mathit{l}=1,2,\dots ,m$. (The array r2 must differ from both ssp and r.)
That is to say: on exit, ${\mathbf{r2}}\left(k,l\right)$ contains the Pearson product-moment coefficient ${R}_{ij}$ (or the correlation-like coefficient, ${\stackrel{~}{R}}_{ij}$).
5:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{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:
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<2$, or ${\mathbf{m}}<1$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{n}}<{\mathbf{m}}$.
${\mathbf{ifail}}=3$
 On entry, $\mathit{ldssp}<{\mathbf{n}}$, or $\mathit{ldr}<{\mathbf{n}}$, or $\mathit{ldssp}<{\mathbf{m}}$, or $\mathit{ldr2}<{\mathbf{m}}$.
${\mathbf{ifail}}=4$
 On entry, ${\mathbf{korder}}\left(i\right)<1$, or ${\mathbf{korder}}\left(i\right)>{\mathbf{n}}$ for some $i=1,2,\dots ,m$.
${\mathbf{ifail}}=-99$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

The time taken by nag_correg_linregm_service_select (g02ce) depends on $n$ and $m$.
The function is intended primarily for use when a subset of variables from a larger set of variables is to be used in a regression, and is described accordingly. There is however no reason why the function should not also be used to select specific rows and columns from vectors and arrays 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

This example reads in the means, standard deviations, sums of squares and cross-products, and correlation coefficients for four variables. New vectors and matrices are created containing the means, standard deviations, sums of squares and cross-products, and correlation coefficients for the fourth, first and second variables (in that order). Finally these new vectors and matrices are printed.
```function g02ce_example

fprintf('g02ce example results\n\n');

% Data
xbar = [  5.8;        2.8;       1.8;        5.4   ];
std  = [  5.0695;     1.924;     2.5884;     4.98  ];
ssp  = [102.8,      -29.2,     -14.2,      -57.6;
-29.2,       14.8,      -6.2,        6.4;
-14.2,       -6.2,      28.6,       42.4;
-57.6,        6.4,      42.4,       99.2   ];
r    = [  1,         -0.7486,   -0.2619,    -0.5704;
-0.7486,     1,        -0.3014,     0.167;
-0.2619,    -0.3014,    1,          0.796;
-0.5704,     0.167,     0.796,      1     ];

% Reordering
korder = [int64(4); 1; 2];

% Display data
fprintf('Original vector xbar :   ');
fprintf(' %10.4f', xbar);
fprintf('\n\nOriginal vector std  :   ');
fprintf(' %10.4f', std);
fprintf('\n\n');
disp('Original matrix SSP  :');
disp(ssp);
disp('Original matrix R    :');
disp(r);

% Calculate summaries on reduced number of variables
[xbar2, std2, ssp2, r2, ifail] = ...
g02ce( ...
xbar, std, ssp, r, korder);

% Display results
fprintf('New vector xbar2 :   ');
fprintf(' %10.4f', xbar2);
fprintf('\n\nNew vector std2  :   ');
fprintf(' %10.4f', std2);
fprintf('\n\n');
disp('New matrix ssp2  :');
disp(ssp2);
disp('New matrix r2    :');
disp(r2);

```
```g02ce example results

Original vector xbar :        5.8000     2.8000     1.8000     5.4000

Original vector std  :        5.0695     1.9240     2.5884     4.9800

Original matrix SSP  :
102.8000  -29.2000  -14.2000  -57.6000
-29.2000   14.8000   -6.2000    6.4000
-14.2000   -6.2000   28.6000   42.4000
-57.6000    6.4000   42.4000   99.2000

Original matrix R    :
1.0000   -0.7486   -0.2619   -0.5704
-0.7486    1.0000   -0.3014    0.1670
-0.2619   -0.3014    1.0000    0.7960
-0.5704    0.1670    0.7960    1.0000

New vector xbar2 :        5.4000     5.8000     2.8000

New vector std2  :        4.9800     5.0695     1.9240

New matrix ssp2  :
99.2000  -57.6000    6.4000
-57.6000  102.8000  -29.2000
6.4000  -29.2000   14.8000

New matrix r2    :
1.0000   -0.5704    0.1670
-0.5704    1.0000   -0.7486
0.1670   -0.7486    1.0000

```