G02BZF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

G02BZF

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

G02BZF combines two sets of sample means and sums of squares and cross-products matrices. It is designed to be used in conjunction with G02BUF to allow large datasets to be summarised.

2  Specification

SUBROUTINE G02BZF ( MEAN, M, XSW, XMEAN, XC, YSW, YMEAN, YC, IFAIL)
INTEGER  M, IFAIL
REAL (KIND=nag_wp)  XSW, XMEAN(M), XC((M*M+M)/2), YSW, YMEAN(M), YC((M*M+M)/2)
CHARACTER(1)  MEAN

3  Description

Let X and Y denote two sets of data, each with m variables and nx and ny observations respectively. Let μx denote the (optionally weighted) vector of m means for the first dataset and Cx denote either the sums of squares and cross-products of deviations from μx 
Cx= X-e μxT T Dx X-e μxT
or the sums of squares and cross-products, in which case
Cx = XT Dx X
where e is a vector of n ones and Dx is a diagonal matrix of (optional) weights, with the sum of the diagonal elements of Dx equal to Wx. Similarly, let μy, Cy and Wy denote the same quantities for the second dataset.
Given μx, μy, Cx, Cy, Wx  and Wy  G02BZF calculates μz, Cz and Wz as if a dataset Z, with m variables and nx+ny observations were supplied to G02BUF, with Z constructed as
Z = X Y .
G02BZF has been designed to combine the results from two calls to G02BUF allowing large datasets, or cases where all the data is not available at the same time, to be summarised.

4  References

Bennett J, Pebay P, Roe D and Thompson D (2009) Numerically stable, single-pass, parallel statistics algorithms Proceedings of IEEE International Conference on Cluster Computing

5  Parameters

1:     MEAN – CHARACTER(1)Input
On entry: indicates whether the matrices supplied in XC and YC are sums of squares and cross-products, or sums of squares and cross-products of deviations about the mean.
MEAN='M'
Sums of squares and cross-products of deviations about the mean have been supplied.
MEAN='Z'
Sums of squares and cross-products have been supplied.
Constraint: MEAN='M' or 'Z'.
2:     M – INTEGERInput
On entry: m, the number of variables.
Constraint: M1.
3:     XSW – REAL (KIND=nag_wp)Input/Output
On entry: Wx, the sum of weights, from the first set of data, X. If the data is unweighted then this will be the number of observations in the first dataset.
On exit: Wz, the sum of weights, from the combined dataset, Z. If both datasets are unweighted then this will be the number of observations in the combined dataset.
Constraint: XSW0.
4:     XMEAN(M) – REAL (KIND=nag_wp) arrayInput/Output
On entry: μx, the sample means for the first set of data, X.
On exit: μz, the sample means for the combined data, Z.
5:     XC(M×M+M/2) – REAL (KIND=nag_wp) arrayInput/Output
On entry: Cx, the sums of squares and cross-products matrix for the first set of data, X, as returned by G02BUF.
G02BUF, returns this matrix packed by columns, i.e., the cross-product between the jth and kth variable, kj, is stored in XCk×k-1/2+j.
No check is made that Cx is a valid cross-products matrix.
On exit: Cz, the sums of squares and cross-products matrix for the combined dataset, Z.
This matrix is again stored packed by columns.
6:     YSW – REAL (KIND=nag_wp)Input
On entry: Wy, the sum of weights, from the second set of data, Y. If the data is unweighted then this will be the number of observations in the second dataset.
Constraint: YSW0.
7:     YMEAN(M) – REAL (KIND=nag_wp) arrayInput
On entry: μy, the sample means for the second set of data, Y.
8:     YC(M×M+M/2) – REAL (KIND=nag_wp) arrayInput
On entry: Cy, the sums of squares and cross-products matrix for the second set of data, Y, as returned by G02BUF.
G02BUF, returns this matrix packed by columns, i.e., the cross-product between the jth and kth variable, kj, is stored in YCk×k-1/2+j.
No check is made that Cy is a valid cross-products matrix.
9:     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=11
On entry, MEAN=value.
Constraint: MEAN='M' or 'Z'.
IFAIL=21
On entry, M=value.
Constraint: M1.
IFAIL=31
On entry, XSW=value.
Constraint: XSW0.0.
IFAIL=61
On entry, YSW=value.
Constraint: YSW0.0.

7  Accuracy

Not applicable.

8  Further Comments

None.

9  Example

This example illustrates the use of G02BZF by dividing a dataset into three blocks of 4, 5 and 3 observations respectively. Each block of data is summarised using G02BUF and then the three summaries combined using G02BZF.
The resulting sums of squares and cross-products matrix is then scaled to obtain the covariance matrix for the whole dataset.

9.1  Program Text

Program Text (g02bzfe.f90)

9.2  Program Data

Program Data (g02bzfe.d)

9.3  Program Results

Program Results (g02bzfe.r)


G02BZF (PDF version)
G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

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