G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG01ABF

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

G01ABF computes the means, standard deviations, corrected sums of squares and products, maximum and minimum values, and the product-moment correlation coefficient for two variables. Unequal weighting may be given.

## 2  Specification

 SUBROUTINE G01ABF ( N, X1, X2, IWT, WT, RES, IFAIL)
 INTEGER N, IWT, IFAIL REAL (KIND=nag_wp) X1(N), X2(N), WT(N), RES(13)

## 3  Description

The data consist of two samples of $n$ observations, denoted by ${x}_{i}$, and ${y}_{i}$, for $i=1,2,\dots ,n$, with corresponding weights ${w}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
If no specific weighting is given, then each ${w}_{i}$ is set to $1.0$ in G01ABF.
The quantities calculated are:
(a) The sum of weights,
 $W=∑i=1nwi.$
(b) The means,
 $x-=∑i= 1nwixiW, y-=∑i= 1nwiyiW.$
(c) The corrected sums of squares and products
 $c11=∑i=1n wi xi-x- 2 c21=c12=∑i=1n wi xi-x- yi-y- c22=∑i=1n wi yi-y- 2 .$
(d) The standard deviations
 $sj= cjj d , where j= 1,2 and d=W- ∑ i= 1 n wi2 W .$
(e) The product-moment correlation coefficient
 $R= c12 c11 c22 .$
(f) The minimum and maximum elements in each of the two samples.
(g) The number of pairs of observations, $m$, for which ${w}_{i}>0$, i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if $m\ge 2$. All other items are computed if $m\ge 1$.

None.

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of pairs of observations.
Constraint: ${\mathbf{N}}\ge 1$.
2:     X1(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations from the first sample, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3:     X2(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations from the second sample, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4:     IWT – INTEGERInput/Output
On entry: indicates whether user-supplied weights are provided by you:
${\mathbf{IWT}}=1$
• Indicates that user-supplied weights are given in the array WT.
${\mathbf{IWT}}\ne 0$
• Indicates that user-supplied weights are not given. In this case the routine assigns the value $1.0$ to each element of the weight array, WT.
On exit: is used to indicate the number of valid observations, $m$; see Section 3(g), above.
5:     WT(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if weights are being supplied then the elements of WT must contain the weights associated with the observations, ${w}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
Constraint: if ${\mathbf{IWT}}=1$, ${\mathbf{WT}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{N}}$.
On exit: if ${\mathbf{IWT}}=1$, the elements of WT are unchanged, otherwise each element of WT will be assigned the value $1.0$.
6:     RES($13$) – REAL (KIND=nag_wp) arrayOutput
On exit: the elements of RES contain the following results:
 ${\mathbf{RES}}\left(1\right)$ mean of the first sample, $\stackrel{-}{x}$; ${\mathbf{RES}}\left(2\right)$ mean of the second sample, $\stackrel{-}{y}$; ${\mathbf{RES}}\left(3\right)$ standard deviation of the first sample, ${s}_{1}$; ${\mathbf{RES}}\left(4\right)$ standard deviation of the second sample, ${s}_{2}$; ${\mathbf{RES}}\left(5\right)$ corrected sum of squares of the first sample, ${c}_{11}$; ${\mathbf{RES}}\left(6\right)$ corrected sum of products of the two samples, ${c}_{12}$; ${\mathbf{RES}}\left(7\right)$ corrected sum of squares of the second sample, ${c}_{22}$; ${\mathbf{RES}}\left(8\right)$ product-moment correlation coefficient, $R$; ${\mathbf{RES}}\left(9\right)$ minimum of the first sample; ${\mathbf{RES}}\left(10\right)$ maximum of the first sample; ${\mathbf{RES}}\left(11\right)$ minimum of the second sample; ${\mathbf{RES}}\left(12\right)$ maximum of the second sample; ${\mathbf{RES}}\left(13\right)$ sum of weights, $\sum _{i=1}^{n}{w}_{i}$ ($={\mathbf{N}}$, if ${\mathbf{IWT}}=0$, on entry).
7:     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$.
${\mathbf{IFAIL}}=2$
The number of valid cases, $m$, is $1$, hence the standard deviation, 3(d), and the product-moment correlation coefficient, 3(e), cannot be calculated.
${\mathbf{IFAIL}}=3$
The number of valid cases, $m$, is $0$, or at least one of the weights is negative.

## 7  Accuracy

The method used is believed to be stable.

The time taken by G01ABF increases linearly with $n$.

## 9  Example

In the program below, NPROB determines the number of datasets to be analysed. For each analysis, a set of observations and, optionally, weights, is read and printed. After calling G01ABF, all the calculated quantities are printed. In the example, there is one set of data, with $29$ (unweighted) pairs of observations.

### 9.1  Program Text

Program Text (g01abfe.f90)

### 9.2  Program Data

Program Data (g01abfe.d)

### 9.3  Program Results

Program Results (g01abfe.r)