G02BTF updates the sample means and sums of squares and crossproducts, or sums of squares and crossproducts of deviations about the mean, for a new observation. The data may be weighted.
G02BTF is an adaptation of West's WV2 algorithm; see
West (1979). This routine updates the weighted means of variables and weighted sums of squares and crossproducts or weighted sums of squares and crossproducts of deviations about the mean for observations on
$m$ variables
${X}_{j}$, for
$j=1,2,\dots ,m$. For the first
$i1$ observations let the mean of the
$j$th variable be
${\stackrel{}{x}}_{j}\left(i1\right)$, the crossproduct about the mean for the
$j$th and
$k$th variables be
${c}_{jk}\left(i1\right)$ and the sum of weights be
${W}_{i1}$. These are updated by the
$i$th observation,
${x}_{ij}$, for
$\mathit{j}=1,2,\dots ,m$, with weight
${w}_{i}$ as follows:
and
The algorithm is initialized by taking
${\stackrel{}{x}}_{j}\left(1\right)={x}_{1j}$, the first observation and
${c}_{ij}\left(1\right)=0.0$.
 1: $\mathrm{MEAN}$ – CHARACTER(1)Input

On entry: indicates whether G02BTF is to calculate sums of squares and crossproducts, or sums of squares and crossproducts of deviations about the mean.
 ${\mathbf{MEAN}}=\text{'M'}$
 The sums of squares and crossproducts of deviations about the mean are calculated.
 ${\mathbf{MEAN}}=\text{'Z'}$
 The sums of squares and crossproducts are calculated.
Constraint:
${\mathbf{MEAN}}=\text{'M'}$ or $\text{'Z'}$.
 2: $\mathrm{M}$ – INTEGERInput

On entry: $m$, the number of variables.
Constraint:
${\mathbf{M}}\ge 1$.
 3: $\mathrm{WT}$ – REAL (KIND=nag_wp)Input

On entry: the weight to use for the current observation,
${w}_{i}$.
For unweighted means and crossproducts set
${\mathbf{WT}}=1.0$. The use of a suitable negative value of
WT, e.g.,
${w}_{i}$ will have the effect of deleting the observation.
 4: $\mathrm{X}\left({\mathbf{M}}\times {\mathbf{INCX}}\right)$ – REAL (KIND=nag_wp) arrayInput

On entry: ${\mathbf{X}}\left(\left(j1\right)\times {\mathbf{INCX}}+1\right)$ must contain the value of the $j$th variable for the current observation, $j=1,2,\dots ,m$.
 5: $\mathrm{INCX}$ – INTEGERInput

On entry: the increment of
X. Two situations are common.
If
${\mathbf{INCX}}=1$, the data values are to be found in consecutive locations in
X, i.e., in a column.
If ${\mathbf{INCX}}=\mathit{ldx}$, for some positive integer $\mathit{ldx}$, the data values are to be found as a row of an array with first dimension $\mathit{ldx}$.
Constraint:
${\mathbf{INCX}}>0$.
 6: $\mathrm{SW}$ – REAL (KIND=nag_wp)Input/Output

On entry: the sum of weights for the previous observations,
${W}_{i1}$.
 ${\mathbf{SW}}=0.0$
 The update procedure is initialized.
 ${\mathbf{SW}}+{\mathbf{WT}}=0.0$
 All elements of XBAR and C are set to zero.
Constraint:
${\mathbf{SW}}\ge 0.0$ and ${\mathbf{SW}}+{\mathbf{WT}}\ge 0.0$.
On exit: contains the updated sum of weights, ${W}_{i}$.
 7: $\mathrm{XBAR}\left({\mathbf{M}}\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: if
${\mathbf{SW}}=0.0$,
XBAR is initialized, otherwise
${\mathbf{XBAR}}\left(\mathit{j}\right)$ must contain the weighted mean of the
$\mathit{j}$th variable for the previous
$\left(\mathit{i}1\right)$ observations,
${\stackrel{}{x}}_{\mathit{j}}\left(\mathit{i}1\right)$, for
$\mathit{j}=1,2,\dots ,m$.
On exit: ${\mathbf{XBAR}}\left(\mathit{j}\right)$ contains the weighted mean of the $\mathit{j}$th variable, ${\stackrel{}{x}}_{\mathit{j}}\left(\mathit{i}\right)$, for $\mathit{j}=1,2,\dots ,m$.
 8: $\mathrm{C}\left(\left({\mathbf{M}}\times {\mathbf{M}}+{\mathbf{M}}\right)/2\right)$ – REAL (KIND=nag_wp) arrayInput/Output

On entry: if
${\mathbf{SW}}\ne 0.0$,
C must contain the upper triangular part of the matrix of weighted sums of squares and crossproducts or weighted sums of squares and crossproducts of deviations about the mean. It is stored packed form by column, i.e., the crossproduct between the
$j$th and
$k$th variable,
$k\ge j$, is stored in
${\mathbf{C}}\left(k\times \left(k1\right)/2+j\right)$.
On exit: the update sums of squares and crossproducts stored as on input.
 9: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).
If on entry
${\mathbf{IFAIL}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
For a detailed discussion of the accuracy of this method see
Chan et al. (1982) and
West (1979).
G02BTF is not threaded in any implementation.
G02BTF may be used to update the results returned by
G02BUF.
G02BWF may be used to calculate the correlation matrix from the matrix of sums of squares and crossproducts of deviations about the mean
and the matrix may be scaled
using
F06EDF (DSCAL) or
F06FDF
to produce a variancecovariance matrix.
A program to calculate the means, the required sums of squares and crossproducts matrix, and the variance matrix for a set of $3$ observations of $3$ variables.