# NAG Library Routine Document

## 1Purpose

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

## 2Specification

Fortran Interface
 Subroutine g03zaf ( n, m, x, ldx, nvar, isx, s, e, z, ldz,
 Integer, Intent (In) :: n, m, ldx, nvar, isx(m), ldz Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: x(ldx,m), s(m), e(m) Real (Kind=nag_wp), Intent (Inout) :: z(ldz,nvar)
#include nagmk26.h
 void g03zaf_ (const Integer *n, const Integer *m, const double x[], const Integer *ldx, const Integer *nvar, const Integer isx[], const double s[], const double e[], double z[], const Integer *ldz, Integer *ifail)

## 3Description

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.

## 5Arguments

1:     $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of observations in the data matrix.
Constraint: ${\mathbf{n}}\ge 1$.
2:     $\mathbf{m}$ – IntegerInput
On entry: the number of variables in the data array x.
Constraint: ${\mathbf{m}}\ge {\mathbf{nvar}}$.
3:     $\mathbf{x}\left({\mathbf{ldx}},{\mathbf{m}}\right)$ – 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:     $\mathbf{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:     $\mathbf{nvar}$ – IntegerInput
On entry: $p$, the number of variables to be standardized.
Constraint: ${\mathbf{nvar}}\ge 1$.
6:     $\mathbf{isx}\left({\mathbf{m}}\right)$ – 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:     $\mathbf{s}\left({\mathbf{m}}\right)$ – 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:     $\mathbf{e}\left({\mathbf{m}}\right)$ – 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:     $\mathbf{z}\left({\mathbf{ldz}},{\mathbf{nvar}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: the matrix of standardized values ($z$-scores), $Z$.
10:   $\mathbf{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:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

## 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{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$.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

## 7Accuracy

Standard accuracy is achieved.

## 8Parallelism and Performance

g03zaf is not threaded in any implementation.

Means and standard deviations may be obtained using g01atf or g02bxf.

## 10Example

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.

### 10.1Program Text

Program Text (g03zafe.f90)

### 10.2Program Data

Program Data (g03zafe.d)

### 10.3Program Results

Program Results (g03zafe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017