g02bt updates the sample means and sums of squares and cross-products, or sums of squares and cross-products of deviations about the mean, for a new observation. The data may be weighted.
Syntax
C# |
---|
public static void g02bt( string mean, int m, double wt, double[] x, int incx, ref double sw, double[] xbar, double[] c, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g02bt ( _ mean As String, _ m As Integer, _ wt As Double, _ x As Double(), _ incx As Integer, _ ByRef sw As Double, _ xbar As Double(), _ c As Double(), _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g02bt( String^ mean, int m, double wt, array<double>^ x, int incx, double% sw, array<double>^ xbar, array<double>^ c, [OutAttribute] int% ifail ) |
F# |
---|
static member g02bt : mean : string * m : int * wt : float * x : float[] * incx : int * sw : float byref * xbar : float[] * c : float[] * ifail : int byref -> unit |
Parameters
- mean
- Type: System..::..StringOn entry: indicates whether g02bt is to calculate sums of squares and cross-products, or sums of squares and cross-products of deviations about the mean.
- The sums of squares and cross-products of deviations about the mean are calculated.
- The sums of squares and cross-products are calculated.
Constraint: or .
- m
- Type: System..::..Int32On entry: , the number of variables.Constraint: .
- wt
- Type: System..::..DoubleOn entry: the weight to use for the current observation, .For unweighted means and cross-products set . The use of a suitable negative value of wt, e.g., will have the effect of deleting the observation.
- x
- Type: array<System..::..Double>[]()[][]An array of size []On entry: must contain the value of the th variable for the current observation, .
- incx
- Type: System..::..Int32On entry: the increment of x.If , for some positive integer , the data values are to be found as a row of an array with first dimension .Constraint: .
- sw
- Type: System..::..Double%On entry: the sum of weights for the previous observations, .Constraint: and .On exit: contains the updated sum of weights, .
- xbar
- Type: array<System..::..Double>[]()[][]An array of size [m]On entry: if , xbar is initialized, otherwise must contain the weighted mean of the th variable for the previous observations, , for .On exit: contains the weighted mean of the th variable, , for .
- c
- Type: array<System..::..Double>[]()[][]An array of size []On entry: if , c must contain the upper triangular part of the matrix of weighted sums of squares and cross-products or weighted sums of squares and cross-products of deviations about the mean. It is stored packed form by column, i.e., the cross-product between the th and th variable, , is stored in .On exit: the update sums of squares and cross-products stored as on input.
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
g02bt is an adaptation of West's WV2 algorithm; see West (1979). This method updates the weighted means of variables and weighted sums of squares and cross-products or weighted sums of squares and cross-products of deviations about the mean for observations on variables , for . For the first observations let the mean of the th variable be , the cross-product about the mean for the th and th variables be and the sum of weights be . These are updated by the th observation, , for , with weight as follows:
and
The algorithm is initialized by taking , the first observation and .
For the unweighted case and for all .
References
Chan T F, Golub G H and Leveque R J (1982) Updating Formulae and a Pairwise Algorithm for Computing Sample Variances Compstat, Physica-Verlag
West D H D (1979) Updating mean and variance estimates: An improved method Comm. ACM 22 532–555
Error Indicators and Warnings
Errors or warnings detected by the method:
On entry, , or .
On entry, .
On entry, , the current weight causes the sum of weights to be less than .
On entry, or .
Accuracy
For a detailed discussion of the accuracy of this method see Chan et al. (1982) and West (1979).
Parallelism and Performance
None.
Further Comments
g02bw may be used to calculate the correlation matrix from the matrix of sums of squares and cross-products of deviations about the mean
and the matrix may be scaled
using (F06EDF not in this release) f06fd
to produce a variance-covariance matrix.
Example
A program to calculate the means, the required sums of squares and cross-products matrix, and the variance matrix for a set of observations of variables.
Example program (C#): g02bte.cs