naginterfaces.library.correg.ssqmat_​update

naginterfaces.library.correg.ssqmat_update(wt, x, sw, xbar, c, mean='M')[source]

ssqmat_update 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.

For full information please refer to the NAG Library document for g02bt

https://support.nag.com/numeric/nl/nagdoc_30.3/flhtml/g02/g02btf.html

Parameters
wtfloat

The weight to use for the current observation, .

For unweighted means and cross-products set .

The use of a suitable negative value of , e.g., will have the effect of deleting the observation.

xfloat, array-like, shape

must contain the value of the th variable for the current observation, .

swfloat

The sum of weights for the previous observations, .

The update procedure is initialized.

All elements of and are set to zero.

xbarfloat, array-like, shape

If , is initialized, otherwise must contain the weighted mean of the th variable for the previous observations, , for .

cfloat, array-like, shape

If , 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 .

meanstr, length 1, optional

Indicates whether ssqmat_update 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.

Returns
swfloat

Contains the updated sum of weights, .

xbarfloat, ndarray, shape

contains the weighted mean of the th variable, , for .

cfloat, ndarray, shape

The update sums of squares and cross-products stored as on input.

Raises
NagValueError
(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: .

(errno )

On entry, .

Constraint: or .

Notes

ssqmat_update 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 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