|
NAG[g02buc] NAG[nag_sum_sqs] - Computes a weighted sum of squares matrix
|
|
Calling Sequence
g02buc(mean, n, x, sw, wmean, c, 'm'=m, 'wt'=wt, 'fail'=fail)
nag_sum_sqs(. . .)
Parameters
|
mean - String;
|
|
|
On entry: indicates whether nag_sum_sqs (g02buc) 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: "Nag_AboutMean" or "Nag_AboutZero". .
|
|
|
n - integer;
|
|
|
On entry: , the number of observations in the data set.
|
|
Constraint: . .
|
|
|
x - Matrix(1..dim1, 1..m, datatype=float[8], order=order);
|
|
|
Note: this array may be supplied in Fortran_order or C_order , as specified by order. All array parameters must use a consistent order.
|
|
|
sw - assignable;
|
|
|
Note: On exit the variable sw will have a value of type float.
|
|
On exit: the sum of weights.
|
|
If , sw contains the number of observations, .
|
|
|
wmean - Vector(1..m, datatype=float[8]);
|
|
|
On exit: the sample means. contains the mean for the th variable.
|
|
|
c - Vector(1.., datatype=float[8]);
|
|
|
Note: the dimension, dim, of the array c must be at least .
|
|
On exit: the cross-products.
|
|
If , c contains the upper triangular part of the matrix of (weighted) sums of squares and cross-products of deviations about the mean.
|
|
If , c contains the upper triangular part of the matrix of (weighted) sums of squares and cross-products.
|
|
|
'm'=m - integer; (optional)
|
|
|
On entry: , the number of variables.
|
|
Constraint: . .
|
|
|
'wt'=wt - Vector(1..dim, datatype=float[8]); (optional)
|
|
|
Note: the dimension, dim, of the array wt must be at least .
|
|
On entry: the optional weights of each observation. If weights are not provided then wt must be set to the null pointer, i.e., (double *)0, otherwise must contain the weight for the th observation.
|
|
|
'fail'=fail - table; (optional)
|
|
|
The NAG error argument, see the documentation for NagError.
|
|
|
|
Description
|
|
|
Purpose
|
|
nag_sum_sqs (g02buc) calculates the sample means and sums of squares and cross-products, or sums of squares and cross-products of deviations from the mean, in a single pass for a set of data. The data may be weighted.
|
|
Error Indicators and Warnings
|
|
"NE_ALLOC_FAIL"
Dynamic memory allocation failed.
"NE_BAD_PARAM"
On entry, argument had an illegal value.
"NE_INT"
On entry, . Constraint: .
On entry, . Constraint: .
"NE_INTERNAL_ERROR"
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please consult NAG for assistance.
"NE_REAL_ARRAY_ELEM_CONS"
On entry, .
|
|
Accuracy
|
|
For a detailed discussion of the accuracy of this algorithm see Chan et al. (1982) or West (1979).
|
|
Further Comments
|
|
g02bwc (nag_cov_to_corr) may be used to calculate the correlation coefficients from the cross-products of deviations about the mean. The cross-products of deviations about the mean may be scaled to give a variance-covariance matrix.
The means and cross-products produced by nag_sum_sqs (g02buc) may be updated by adding or removing observations using g02btc (nag_sum_sqs_update).
|
|
|
Examples
|
|
>
|
mean := "Nag_AboutMean":
n := 3:
m := 3:
x := Matrix([[9.123100000000001, 3.7011, 4.523], [0.931, 0.09, 0.887], [0.0009, 0.009900000000000001, 0.0999]], datatype=float[8]):
wt := Vector([0.13, 1.307, 0.37], datatype=float[8]):
wmean := Vector(3, datatype=float[8]):
c := Vector(6, datatype=float[8]):
NAG:-g02buc(mean, n, x, sw, wmean, c, 'm' = m, 'wt' = wt):
|
|
|
See Also
|
|
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
g02 Chapter Introduction.
NAG Toolbox Overview.
NAG Web Site.
|
|