# NAG FL Interfaceg02bzf (ssqmat_​combine)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g02bzf ( mean, m, xsw, xc, ysw, yc,
 Integer, Intent (In) :: m Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: ysw, ymean(m), yc(*) Real (Kind=nag_wp), Intent (Inout) :: xsw, xmean(m), xc(*) Character (1), Intent (In) :: mean
C Header Interface
#include <nag.h>
 void g02bzf_ (const char *mean, const Integer *m, double *xsw, double xmean[], double xc[], const double *ysw, const double ymean[], const double yc[], Integer *ifail, const Charlen length_mean)
The routine may be called by the names g02bzf or nagf_correg_ssqmat_combine.

## 3Description

Let $X$ and $Y$ denote two sets of data, each with $m$ variables and ${n}_{x}$ and ${n}_{y}$ observations respectively. Let ${\mu }_{x}$ denote the (optionally weighted) vector of $m$ means for the first dataset and ${C}_{x}$ denote either the sums of squares and cross-products of deviations from ${\mu }_{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}_{x}$ ones and ${D}_{x}$ is a diagonal matrix of (optional) weights and ${W}_{x}$ is defined as the sum of the diagonal elements of $D$. Similarly, let ${\mu }_{y}$, ${C}_{y}$ and ${W}_{y}$ denote the same quantities for the second dataset.
Given ${\mu }_{x},{\mu }_{y},{C}_{x},{C}_{y},{W}_{x}$ and ${W}_{y}$ g02bzf calculates ${\mu }_{z}$, ${C}_{z}$ and ${W}_{z}$ as if a dataset $Z$, with $m$ variables and ${n}_{x}+{n}_{y}$ 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.

## 4References

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

## 5Arguments

1: $\mathbf{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.
${\mathbf{mean}}=\text{'M'}$
Sums of squares and cross-products of deviations about the mean have been supplied.
${\mathbf{mean}}=\text{'Z'}$
Sums of squares and cross-products have been supplied.
Constraint: ${\mathbf{mean}}=\text{'M'}$ or $\text{'Z'}$.
2: $\mathbf{m}$Integer Input
On entry: $m$, the number of variables.
Constraint: ${\mathbf{m}}\ge 1$.
3: $\mathbf{xsw}$Real (Kind=nag_wp) Input/Output
On entry: ${W}_{x}$, 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: ${W}_{z}$, 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: ${\mathbf{xsw}}\ge 0$.
4: $\mathbf{xmean}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Input/Output
On entry: ${\mu }_{x}$, the sample means for the first set of data, $X$.
On exit: ${\mu }_{z}$, the sample means for the combined data, $Z$.
5: $\mathbf{xc}\left(*\right)$Real (Kind=nag_wp) array Input/Output
Note: the dimension of the array xc must be at least $\left({\mathbf{m}}×{\mathbf{m}}+{\mathbf{m}}\right)/2$.
On entry: ${C}_{x}$, 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 $j$th and $k$th variable, $k\ge j$, is stored in ${\mathbf{xc}}\left(k×\left(k-1\right)/2+j\right)$.
No check is made that ${C}_{x}$ is a valid cross-products matrix.
On exit: ${C}_{z}$, the sums of squares and cross-products matrix for the combined dataset, $Z$.
This matrix is again stored packed by columns.
6: $\mathbf{ysw}$Real (Kind=nag_wp) Input
On entry: ${W}_{y}$, 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: ${\mathbf{ysw}}\ge 0$.
7: $\mathbf{ymean}\left({\mathbf{m}}\right)$Real (Kind=nag_wp) array Input
On entry: ${\mu }_{y}$, the sample means for the second set of data, $Y$.
8: $\mathbf{yc}\left(*\right)$Real (Kind=nag_wp) array Input
Note: the dimension of the array yc must be at least $\left({\mathbf{m}}×{\mathbf{m}}+{\mathbf{m}}\right)/2$.
On entry: ${C}_{y}$, 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 $j$th and $k$th variable, $k\ge j$, is stored in ${\mathbf{yc}}\left(k×\left(k-1\right)/2+j\right)$.
No check is made that ${C}_{y}$ is a valid cross-products matrix.
9: $\mathbf{ifail}$Integer Input/Output
On entry: ifail must be set to $0$, $-1$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $-1$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $-1$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $0$ is recommended. When the value $-\mathbf{1}$ 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=11$
On entry, ${\mathbf{mean}}=⟨\mathit{\text{value}}⟩$ was an illegal value.
${\mathbf{ifail}}=21$
On entry, ${\mathbf{m}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{m}}\ge 1$.
${\mathbf{ifail}}=31$
On entry, ${\mathbf{xsw}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{xsw}}\ge 0.0$.
${\mathbf{ifail}}=61$
On entry, ${\mathbf{ysw}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{ysw}}\ge 0.0$.
${\mathbf{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.
${\mathbf{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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

Not applicable.

## 8Parallelism and Performance

Background information to multithreading can be found in the Multithreading documentation.
g02bzf 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 routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

None.

## 10Example

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.

### 10.1Program Text

Program Text (g02bzfe.f90)

### 10.2Program Data

Program Data (g02bzfe.d)

### 10.3Program Results

Program Results (g02bzfe.r)