G01ABF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G01ABF

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.

 Contents

    1  Purpose
    7  Accuracy

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 xi, and yi, for i=1,2,,n, with corresponding weights wi, for i=1,2,,n.
If no specific weighting is given, then each wi 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 wi>0, i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if m2. All other items are computed if m1.

4  References

None.

5  Parameters

1:     N – INTEGERInput
On entry: n, the number of pairs of observations.
Constraint: N1.
2:     X1N – REAL (KIND=nag_wp) arrayInput
On entry: the observations from the first sample, xi, for i=1,2,,n.
3:     X2N – REAL (KIND=nag_wp) arrayInput
On entry: the observations from the second sample, yi, for i=1,2,,n.
4:     IWT – INTEGERInput/Output
On entry: indicates whether user-supplied weights are provided by you:
IWT=1 
  • Indicates that user-supplied weights are given in the array WT.
IWT0 
  • 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:     WTN – 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, wi, for i=1,2,,n.
Constraint: if IWT=1, WTi0.0, for i=1,2,,N.
On exit: if IWT=1, the elements of WT are unchanged, otherwise each element of WT will be assigned the value 1.0.
6:     RES13 – REAL (KIND=nag_wp) arrayOutput
On exit: the elements of RES contain the following results:
RES1 mean of the first sample, x-;
RES2 mean of the second sample, y-;
RES3 standard deviation of the first sample, s1;
RES4 standard deviation of the second sample, s2;
RES5 corrected sum of squares of the first sample, c11;
RES6 corrected sum of products of the two samples, c12;
RES7 corrected sum of squares of the second sample, c22;
RES8 product-moment correlation coefficient, R;
RES9 minimum of the first sample;
RES10 maximum of the first sample;
RES11 minimum of the second sample;
RES12 maximum of the second sample;
RES13 sum of weights, i=1nwi (=N, if IWT=0, on entry).
7:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ 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​ 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 -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,N<1.
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.
IFAIL=3
The number of valid cases, m, is 0, or at least one of the weights is negative.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

7  Accuracy

The method used is believed to be stable.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by G01ABF increases linearly with n.

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

10.1  Program Text

Program Text (g01abfe.f90)

10.2  Program Data

Program Data (g01abfe.d)

10.3  Program Results

Program Results (g01abfe.r)


G01ABF (PDF version)
G01 Chapter Contents
G01 Chapter Introduction
NAG Library Manual

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