NAG Library Function Document

nag_sum_sqs_combine (g02bzc)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_sum_sqs_combine (g02bzc) combines two sets of sample means and sums of squares and cross-products matrices. It is designed to be used in conjunction with nag_sum_sqs (g02buc) to allow large datasets to be summarised.

2
Specification

#include <nag.h>
#include <nagg02.h>
void  nag_sum_sqs_combine (Nag_SumSquare mean, Integer m, double *xsw, double xmean[], double xc[], double ysw, const double ymean[], const double yc[], NagError *fail)

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 nx ones and Dx is a diagonal matrix of (optional) weights and Wx is defined as the sum of the diagonal elements of D. Similarly, let μy, Cy and Wy denote the same quantities for the second dataset.
Given μx, μy, Cx, Cy, Wx  and Wy  nag_sum_sqs_combine (g02bzc) calculates μz, Cz and Wz as if a dataset Z, with m variables and nx+ny observations were supplied to nag_sum_sqs (g02buc), with Z constructed as
Z = X Y .  
nag_sum_sqs_combine (g02bzc) has been designed to combine the results from two calls to nag_sum_sqs (g02buc) 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
Arguments

1:     mean Nag_SumSquareInput
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=Nag_AboutMean
Sums of squares and cross-products of deviations about the mean have been supplied.
mean=Nag_AboutZero
Sums of squares and cross-products have been supplied.
Constraint: mean=Nag_AboutMean or Nag_AboutZero.
2:     m IntegerInput
On entry: m, the number of variables.
Constraint: m1.
3:     xsw double *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] doubleInput/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] doubleInput/Output
On entry: Cx, the sums of squares and cross-products matrix for the first set of data, X, as returned by nag_sum_sqs (g02buc).
nag_sum_sqs (g02buc), returns this matrix packed by columns, i.e., the cross-product between the jth and kth variable, kj, is stored in xc[k×k-1/2+j-1].
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 doubleInput
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] const doubleInput
On entry: μy, the sample means for the second set of data, Y.
8:     yc[m×m+m/2] const doubleInput
On entry: Cy, the sums of squares and cross-products matrix for the second set of data, Y, as returned by nag_sum_sqs (g02buc).
nag_sum_sqs (g02buc), returns this matrix packed by columns, i.e., the cross-product between the jth and kth variable, kj, is stored in yc[k×k-1/2+j-1].
No check is made that Cy is a valid cross-products matrix.
9:     fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, m=value.
Constraint: m1.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.
NE_REAL
On entry, xsw=value.
Constraint: xsw0.0.
On entry, ysw=value.
Constraint: ysw0.0.

7
Accuracy

Not applicable.

8
Parallelism and Performance

nag_sum_sqs_combine (g02bzc) makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the x06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this function. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

9
Further Comments

None.

10
Example

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

10.1
Program Text

Program Text (g02bzce.c)

10.2
Program Data

Program Data (g02bzce.d)

10.3
Program Results

Program Results (g02bzce.r)

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