# NAG FL Interfaceg02cef (linregm_​service_​select)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

g02cef 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.

## 2Specification

Fortran Interface
 Subroutine g02cef ( n, xbar, std, ssp, r, ldr, m, std2, ssp2, r2, ldr2,
 Integer, Intent (In) :: n, ldssp, ldr, m, korder(m), ldssp2, ldr2 Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: xbar(n), std(n), ssp(ldssp,n), r(ldr,n) Real (Kind=nag_wp), Intent (Inout) :: ssp2(ldssp2,m), r2(ldr2,m) Real (Kind=nag_wp), Intent (Out) :: xbar2(m), std2(m)
C Header Interface
#include <nag.h>
 void g02cef_ (const Integer *n, const double xbar[], const double std[], const double ssp[], const Integer *ldssp, const double r[], const Integer *ldr, const Integer *m, const Integer korder[], double xbar2[], double std2[], double ssp2[], const Integer *ldssp2, double r2[], const Integer *ldr2, Integer *ifail)
The routine may be called by the names g02cef or nagf_correg_linregm_service_select.

## 3Description

Input to the routine consists of:
1. (a)A vector of means:
 $(x¯1,x¯2,x¯3,…,x¯n),$
where $n$ is the number of input variables.
2. (b)A vector of standard deviations:
 $(s1,s2,s3,…,sn).$
3. (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 ) .$
4. (d)A matrix of correlation coefficients:
 $( R11 R12 R13 . . . R1n R21 R22 R2n R31 . . . . . . . Rn1 Rn2 . . . . Rnn ) .$
5. (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:
1. (i)A vector of means:
 $(x¯i1,x¯i2,x¯i3,…,x¯im).$
2. (ii)A vector of standard deviations:
 $(si1,si2,si3,…,sim).$
3. (iii)A matrix of sums of squares and cross-products of deviations from means:
 $( Si1i1 Si1i2 Si1i3 . . . Si1im Si2i1 Si2i2 . Si3i1 . . . . . . . Simi1 Simi2 . . . . Simim ) .$
4. (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.

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of variables in the input data.
Constraint: ${\mathbf{n}}\ge 2$.
2: $\mathbf{xbar}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\mathbf{xbar}}\left(\mathit{i}\right)$ must be set to ${\overline{x}}_{\mathit{i}}$, the mean of variable $\mathit{i}$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{std}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\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$.
4: $\mathbf{ssp}\left({\mathbf{ldssp}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\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$.
5: $\mathbf{ldssp}$Integer Input
On entry: the first dimension of the array ssp as declared in the (sub)program from which g02cef is called.
Constraint: ${\mathbf{ldssp}}\ge {\mathbf{n}}$.
6: $\mathbf{r}\left({\mathbf{ldr}},{\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\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$.
7: $\mathbf{ldr}$Integer Input
On entry: the first dimension of the array r as declared in the (sub)program from which g02cef is called.
Constraint: ${\mathbf{ldr}}\ge {\mathbf{n}}$.
8: $\mathbf{m}$Integer Input
On entry: the number of variables $m$, required in the reduced vectors and matrices.
Constraint: $1\le {\mathbf{m}}\le {\mathbf{n}}$.
9: $\mathbf{korder}\left({\mathbf{m}}\right)$Integer array Input
On entry: ${\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$.
10: $\mathbf{xbar2}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: 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.)
11: $\mathbf{std2}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: 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.)
12: $\mathbf{ssp2}\left({\mathbf{ldssp2}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\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}$).
13: $\mathbf{ldssp2}$Integer Input
On entry: the first dimension of the array ssp2 as declared in the (sub)program from which g02cef is called.
Constraint: ${\mathbf{ldssp2}}\ge {\mathbf{m}}$.
14: $\mathbf{r2}\left({\mathbf{ldr2}},{\mathbf{m}}\right)$Real (Kind=nag_wp) array Output
On exit: ${\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}$).
15: $\mathbf{ldr2}$Integer Input
On entry: the first dimension of the array r2 as declared in the (sub)program from which g02cef is called.
Constraint: ${\mathbf{ldr2}}\ge {\mathbf{m}}$.
16: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 2$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constratint: ${\mathbf{n}}\ge {\mathbf{m}}$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{ldr2}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldr2}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{ldr}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldr}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{ldssp2}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldssp2}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{ldssp}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ldssp}}\ge {\mathbf{n}}$.
${\mathbf{ifail}}=4$
On entry, ${\mathbf{korder}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: $1\le {\mathbf{korder}}\left(i\right)\le {\mathbf{n}}$, for $i=1,2,\dots ,m$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

g02cef is not threaded in any implementation.

## 9Further Comments

The time taken by g02cef depends on $n$ and $m$.
The routine 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 routine 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 routine 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.

## 10Example

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.

### 10.1Program Text

Program Text (g02cefe.f90)

### 10.2Program Data

Program Data (g02cefe.d)

### 10.3Program Results

Program Results (g02cefe.r)