hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_correg_ssqmat_update (g02bt)

Purpose

nag_correg_ssqmat_update (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

[sw, xbar, c, ifail] = g02bt(wt, x, sw, xbar, c, 'mean', mean, 'm', m, 'incx', incx)
[sw, xbar, c, ifail] = nag_correg_ssqmat_update(wt, x, sw, xbar, c, 'mean', mean, 'm', m, 'incx', incx)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: incx now optional (default 1)
Mark 24: mean optional
.

Description

nag_correg_ssqmat_update (g02bt) is an adaptation of West's WV2 algorithm; see West (1979). This function 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 mm variables XjXj, for j = 1,2,,mj=1,2,,m. For the first i1i-1 observations let the mean of the jjth variable be xj(i1)x-j(i-1), the cross-product about the mean for the jjth and kkth variables be cjk(i1)cjk(i-1) and the sum of weights be Wi1Wi-1. These are updated by the iith observation, xijxij, for j = 1,2,,mj=1,2,,m, with weight wiwi as follows:
Wi = Wi1 + wi,  xj(i) = xj(i1) + (wi)/(Wi)(xjxj(i1)),  j = 1,2,,m
Wi=Wi-1+wi,  x-j(i)=x-j(i-1)+wiWi(xj-x-j(i-1)),  j=1,2,,m
and
cjk(i) = cjk(i1) + (wi)/(Wi)(xjxj(i1))(xkxk(i1))Wi 1,   j = 1,2,,m;k = j,j + 1,2,,m.
cjk(i)=cjk(i- 1)+wiWi(xj-x-j(i- 1))(xk-x-k(i- 1))Wi- 1,   j= 1,2,,m;k=j,j+ 1,2,,m.
The algorithm is initialized by taking xj(1) = x1jx-j(1)=x1j, the first observation and cij(1) = 0.0cij(1)=0.0.
For the unweighted case wi = 1wi=1 and Wi = iWi=i for all ii.

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

Parameters

Compulsory Input Parameters

1:     wt – double scalar
The weight to use for the current observation, wiwi.
For unweighted means and cross-products set wt = 1.0wt=1.0. The use of a suitable negative value of wt, e.g., wi-wi will have the effect of deleting the observation.
2:     x(m × incxm×incx) – double array
x((j1) × incx + 1)x(j-1)×incx+1 must contain the value of the jjth variable for the current observation, j = 1,2,,mj=1,2,,m.
3:     sw – double scalar
The sum of weights for the previous observations, Wi1Wi-1.
sw = 0.0sw=0.0
The update procedure is initialized.
sw + wt = 0.0sw+wt=0.0
All elements of xbar and c are set to zero.
Constraint: sw0.0sw0.0 and sw + wt0.0sw+wt0.0.
4:     xbar(m) – double array
m, the dimension of the array, must satisfy the constraint m1m1.
If sw = 0.0sw=0.0, xbar is initialized, otherwise xbar(j)xbarj must contain the weighted mean of the jjth variable for the previous (i1)(i-1) observations, xj(i1)x-j(i-1), for j = 1,2,,mj=1,2,,m.
5:     c((m × m + m) / 2(m×m+m)/2) – double array
If sw0.0sw0.0, 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 jjth and kkth variable, kjkj, is stored in c(k × (k1) / 2 + j)ck×(k-1)/2+j.

Optional Input Parameters

1:     mean – string (length ≥ 1)
Indicates whether nag_correg_ssqmat_update (g02bt) is to calculate sums of squares and cross-products, or sums of squares and cross-products of deviations about the mean.
mean = 'M'mean='M'
The sums of squares and cross-products of deviations about the mean are calculated.
mean = 'Z'mean='Z'
The sums of squares and cross-products are calculated.
Default: 'M''M'
Constraint: mean = 'M'mean='M' or 'Z''Z'.
2:     m – int64int32nag_int scalar
Default: The dimension of the array xbar.
mm, the number of variables.
Constraint: m1m1.
3:     incx – int64int32nag_int scalar
The increment of x. Two situations are common.
If incx = 1incx=1, the data values are to be found in consecutive locations in x, i.e., in a column.
If incx = ldxincx=ldx, for some positive integer ldxldx, the data values are to be found as a row of an array with first dimension ldxldx.
Default: 11
Constraint: incx > 0incx>0.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     sw – double scalar
Contains the updated sum of weights, WiWi.
2:     xbar(m) – double array
xbar(j)xbarj contains the weighted mean of the jjth variable, xj(i)x-j(i), for j = 1,2,,mj=1,2,,m.
3:     c((m × m + m) / 2(m×m+m)/2) – double array
The update sums of squares and cross-products stored as on input.
4:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,m < 1m<1,
orincx < 1incx<1.
  ifail = 2ifail=2
On entry,sw < 0.0sw<0.0.
  ifail = 3ifail=3
On entry,(sw + wt) < 0.0(sw+wt)<0.0, the current weight causes the sum of weights to be less than 0.00.0.
  ifail = 4ifail=4
On entry,mean'M'mean'M' or 'Z''Z'.

Accuracy

For a detailed discussion of the accuracy of this method see Chan et al. (1982) and West (1979).

Further Comments

nag_correg_ssqmat_update (g02bt) may be used to update the results returned by nag_correg_ssqmat (g02bu).
nag_correg_ssqmat_to_corrmat (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 to produce a variance-covariance matrix.

Example

function nag_correg_ssqmat_update_example
wt = 0.13;
x = [9.1231;
     3.7011;
     4.523];
sw = 0;
xbar = zeros(3,1);
c = zeros(6,1);
[swOut, xbarOut, cOut, ifail] = nag_correg_ssqmat_update(wt, x, sw, xbar, c)
 

swOut =

    0.1300


xbarOut =

    9.1231
    3.7011
    4.5230


cOut =

     0
     0
     0
     0
     0
     0


ifail =

                    0


function g02bt_example
wt = 0.13;
x = [9.1231;
     3.7011;
     4.523];
sw = 0;
xbar = zeros(3,1);
c = zeros(6,1);
[swOut, xbarOut, cOut, ifail] = g02bt(wt, x, sw, xbar, c)
 

swOut =

    0.1300


xbarOut =

    9.1231
    3.7011
    4.5230


cOut =

     0
     0
     0
     0
     0
     0


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013