NAG FL Interface
g03zaf (z_​scores)

1 Purpose

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

2 Specification

Fortran Interface
Subroutine g03zaf ( n, m, x, ldx, nvar, isx, s, e, z, ldz, ifail)
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)
C Header Interface
#include <nag.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)
The routine may be called by the names g03zaf or nagf_mv_z_scores.

3 Description

For a data matrix, X, consisting of n observations on p variables, with elements xij, g03zaf computes a matrix, Z, with elements zij such that:
zij=xij-μjσj,  i=1,2,,n;  j=1,2,,p,  
where μj is a location shift and σj is a scaling factor. Typically, μj will be the mean and σj will be the standard deviation of the jth variable and therefore the elements in column j of Z will have zero mean and unit variance.

4 References

None.

5 Arguments

1: n Integer Input
On entry: n, the number of observations in the data matrix.
Constraint: n1.
2: m Integer Input
On entry: the number of variables in the data array x.
Constraint: mnvar.
3: xldxm Real (Kind=nag_wp) array Input
On entry: xij must contain the ith sample point for the jth variable, xij, for i=1,2,,n and j=1,2,,m.
4: ldx Integer Input
On entry: the first dimension of the array x as declared in the (sub)program from which g03zaf is called.
Constraint: ldxn.
5: nvar Integer Input
On entry: p, the number of variables to be standardized.
Constraint: nvar1.
6: isxm Integer array Input
On entry: isxj indicates whether or not the observations on the jth variable are included in the matrix of standardized values.
If isxj0, the observations from the jth variable are included.
If isxj=0, the observations from the jth variable are not included.
Constraint: isxj0 for nvar values of j.
7: sm Real (Kind=nag_wp) array Input
On entry: if isxj0, sj must contain the scaling (standard deviation), σj, for the jth variable.
If isxj=0, sj is not referenced.
Constraint: if isxj0, sj>0.0, for j=1,2,,m.
8: em Real (Kind=nag_wp) array Input
On entry: if isxj0, ej must contain the location shift (mean), μj, for the jth variable.
If isxj=0, ej is not referenced.
9: zldznvar Real (Kind=nag_wp) array Output
On exit: the matrix of standardized values (z-scores), Z.
10: ldz Integer Input
On entry: the first dimension of the array z as declared in the (sub)program from which g03zaf is called.
Constraint: ldzn.
11: ifail Integer Input/Output
On entry: ifail must be set to 0, -1 or 1. If you are unfamiliar with this argument you should refer to Section 4 in the Introduction to the NAG Library FL Interface for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1 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 -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry 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:
ifail=1
On entry, ldx=value and n=value.
Constraint: ldxn.
On entry, ldz=value and n=value.
Constraint: ldzn.
On entry, m=value and nvar=value.
Constraint: mnvar.
On entry, n=value.
Constraint: n1.
On entry, nvar=value.
Constraint: nvar1.
ifail=2
On entry, nvar=value and value values of isx>0.
Constraint: exactly nvar elements of isx>0.
ifail=3
On entry, j=value and si0.0.
Constraint: sj>0.0.
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.
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.
ifail=-999
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

Standard accuracy is achieved.

8 Parallelism and Performance

g03zaf is not threaded in any implementation.

9 Further Comments

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

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

10.1 Program Text

Program Text (g03zafe.f90)

10.2 Program Data

Program Data (g03zafe.d)

10.3 Program Results

Program Results (g03zafe.r)