G03 Chapter Contents
G03 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG03ZAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

G03ZAF produces standardized values ($z$-scores) for a data matrix.

## 2  Specification

 SUBROUTINE G03ZAF ( N, M, X, LDX, NVAR, ISX, S, E, Z, LDZ, IFAIL)
 INTEGER N, M, LDX, NVAR, ISX(M), LDZ, IFAIL REAL (KIND=nag_wp) X(LDX,M), S(M), E(M), Z(LDZ,NVAR)

## 3  Description

For a data matrix, $X$, consisting of $n$ observations on $p$ variables, with elements ${x}_{ij}$, G03ZAF computes a matrix, $Z$, with elements ${z}_{ij}$ such that:
 $zij=xij-μjσj, i=1,2,…,n; j=1,2,…,p,$
where ${\mu }_{j}$ is a location shift and ${\sigma }_{j}$ is a scaling factor. Typically, ${\mu }_{j}$ will be the mean and ${\sigma }_{j}$ will be the standard deviation of the $j$th variable and therefore the elements in column $j$ of $Z$ will have zero mean and unit variance.

None.

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of observations in the data matrix.
Constraint: ${\mathbf{N}}\ge 1$.
2:     M – INTEGERInput
On entry: the number of variables in the data array X.
Constraint: ${\mathbf{M}}\ge {\mathbf{NVAR}}$.
3:     X(LDX,M) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{X}}\left(\mathit{i},\mathit{j}\right)$ must contain the $\mathit{i}$th sample point for the $\mathit{j}$th variable, ${x}_{\mathit{i}\mathit{j}}$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
4:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G03ZAF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
5:     NVAR – INTEGERInput
On entry: $p$, the number of variables to be standardized.
Constraint: ${\mathbf{NVAR}}\ge 1$.
6:     ISX(M) – INTEGER arrayInput
On entry: ${\mathbf{ISX}}\left(j\right)$ indicates whether or not the observations on the $j$th variable are included in the matrix of standardized values.
If ${\mathbf{ISX}}\left(j\right)\ne 0$, the observations from the $j$th variable are included.
If ${\mathbf{ISX}}\left(j\right)=0$, the observations from the $j$th variable are not included.
Constraint: ${\mathbf{ISX}}\left(j\right)\ne 0$ for NVAR values of $j$.
7:     S(M) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{ISX}}\left(j\right)\ne 0$, ${\mathbf{S}}\left(j\right)$ must contain the scaling (standard deviation), ${\sigma }_{j}$, for the $j$th variable.
If ${\mathbf{ISX}}\left(j\right)=0$, ${\mathbf{S}}\left(j\right)$ is not referenced.
Constraint: if ${\mathbf{ISX}}\left(j\right)\ne 0$, ${\mathbf{S}}\left(\mathit{j}\right)>0.0$, for $\mathit{j}=1,2,\dots ,{\mathbf{M}}$.
8:     E(M) – REAL (KIND=nag_wp) arrayInput
On entry: if ${\mathbf{ISX}}\left(j\right)\ne 0$, ${\mathbf{E}}\left(j\right)$ must contain the location shift (mean), ${\mu }_{j}$, for the $j$th variable.
If ${\mathbf{ISX}}\left(j\right)=0$, ${\mathbf{E}}\left(j\right)$ is not referenced.
9:     Z(LDZ,NVAR) – REAL (KIND=nag_wp) arrayOutput
On exit: the matrix of standardized values ($z$-scores), $Z$.
10:   LDZ – INTEGERInput
On entry: the first dimension of the array Z as declared in the (sub)program from which G03ZAF is called.
Constraint: ${\mathbf{LDZ}}\ge {\mathbf{N}}$.
11:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ 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).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{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{N}}<1$, or ${\mathbf{NVAR}}<1$, or ${\mathbf{M}}<{\mathbf{NVAR}}$, or ${\mathbf{LDX}}<{\mathbf{N}}$, or ${\mathbf{LDZ}}<{\mathbf{N}}$.
${\mathbf{IFAIL}}=2$
 On entry, there are not precisely NVAR elements of ${\mathbf{ISX}}\ne 0$.
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{ISX}}\left(j\right)\ne 0$ and ${\mathbf{S}}\left(j\right)\le 0.0$ for some $j$.

## 7  Accuracy

Standard accuracy is achieved.

Means and standard deviations may be obtained using G01ATF or G02BXF.

## 9  Example

A $4$ by $3$ data matrix is input along with location and scaling values. The first and third columns are scaled and the results printed.

### 9.1  Program Text

Program Text (g03zafe.f90)

### 9.2  Program Data

Program Data (g03zafe.d)

### 9.3  Program Results

Program Results (g03zafe.r)