PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_correg_ssqmat_combine (g02bz)
Purpose
nag_correg_ssqmat_combine (g02bz) combines two sets of sample means and sums of squares and cross-products matrices. It is designed to be used in conjunction with
nag_correg_ssqmat (g02bu) to allow large datasets to be summarised.
Syntax
[
xsw,
xmean,
xc,
ifail] = g02bz(
xsw,
xmean,
xc,
ysw,
ymean,
yc, 'mean_p',
mean_p, 'm',
m)
[
xsw,
xmean,
xc,
ifail] = nag_correg_ssqmat_combine(
xsw,
xmean,
xc,
ysw,
ymean,
yc, 'mean_p',
mean_p, 'm',
m)
Description
Let
and
denote two sets of data, each with
variables and
and
observations respectively. Let
denote the (optionally weighted) vector of
means for the first dataset and
denote either the sums of squares and cross-products of deviations from
or the sums of squares and cross-products, in which case
where
is a vector of
ones and
is a diagonal matrix of (optional) weights and
is defined as the sum of the diagonal elements of
. Similarly, let
,
and
denote the same quantities for the second dataset.
Given
and
nag_correg_ssqmat_combine (g02bz) calculates
,
and
as if a dataset
, with
variables and
observations were supplied to
nag_correg_ssqmat (g02bu), with
constructed as
nag_correg_ssqmat_combine (g02bz) has been designed to combine the results from two calls to
nag_correg_ssqmat (g02bu) allowing large datasets, or cases where all the data is not available at the same time, to be summarised.
References
Bennett J, Pebay P, Roe D and Thompson D (2009) Numerically stable, single-pass, parallel statistics algorithms Proceedings of IEEE International Conference on Cluster Computing
Parameters
Compulsory Input Parameters
- 1:
– double scalar
-
, the sum of weights, from the first set of data, . If the data is unweighted then this will be the number of observations in the first dataset.
Constraint:
.
- 2:
– double array
-
, the sample means for the first set of data, .
- 3:
– double array
-
, the sums of squares and cross-products matrix for the first set of data,
, as returned by
nag_correg_ssqmat (g02bu).
nag_correg_ssqmat (g02bu), returns this matrix packed by columns, i.e., the cross-product between the
th and
th variable,
, is stored in
.
No check is made that is a valid cross-products matrix.
- 4:
– double scalar
-
, the sum of weights, from the second set of data, . If the data is unweighted then this will be the number of observations in the second dataset.
Constraint:
.
- 5:
– double array
-
, the sample means for the second set of data, .
- 6:
– double array
-
, the sums of squares and cross-products matrix for the second set of data,
, as returned by
nag_correg_ssqmat (g02bu).
nag_correg_ssqmat (g02bu), returns this matrix packed by columns, i.e., the cross-product between the
th and
th variable,
, is stored in
.
No check is made that is a valid cross-products matrix.
Optional Input Parameters
- 1:
– string (length ≥ 1)
Default:
Indicates whether the matrices supplied in
xc and
yc are sums of squares and cross-products, or sums of squares and cross-products of deviations about the mean.
- Sums of squares and cross-products of deviations about the mean have been supplied.
- Sums of squares and cross-products have been supplied.
Constraint:
or .
- 2:
– int64int32nag_int scalar
-
Default:
the dimension of the array
xmean and the dimension of the array
ymean. (An error is raised if these dimensions are not equal.)
, the number of variables.
Constraint:
.
Output Parameters
- 1:
– double scalar
-
, the sum of weights, from the combined dataset, . If both datasets are unweighted then this will be the number of observations in the combined dataset.
- 2:
– double array
-
, the sample means for the combined data, .
- 3:
– double array
-
, the sums of squares and cross-products matrix for the combined dataset,
.
This matrix is again stored packed by columns.
- 4:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, was an illegal value.
-
-
Constraint: .
-
-
Constraint: .
-
-
Constraint: .
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
None.
Example
This example illustrates the use of
nag_correg_ssqmat_combine (g02bz) by dividing a dataset into three blocks of
,
and
observations respectively. Each block of data is summarised using
nag_correg_ssqmat (g02bu) and then the three summaries combined using
nag_correg_ssqmat_combine (g02bz).
The resulting sums of squares and cross-products matrix is then scaled to obtain the covariance matrix for the whole dataset.
Open in the MATLAB editor:
g02bz_example
function g02bz_example
fprintf('g02bz example results\n\n');
x1 = [-1.10 4.06 -0.95 8.53 10.41;
1.63 -3.22 -1.15 -1.30 3.78;
-2.23 -8.19 -3.50 4.31 -1.11;
0.92 0.33 -1.60 5.80 -1.15];
x2 = [ 2.12 5.00 -11.69 -1.22 2.86;
4.82 -7.23 -4.67 0.83 3.46;
-0.51 -1.12 -1.76 1.45 0.26;
-4.32 4.89 1.34 -1.12 -2.49;
0.02 -0.74 0.94 -0.99 -2.61];
wt = [ 2; 0.89; 0.32; 4.19; 4.33];
x3 = [ 1.37 0.00 -0.53 -7.98 3.32;
4.15 -2.81 -4.09 -7.96 -2.13;
13.09 -1.43 5.16 -1.83 1.58];
for b=1:3
switch b
case 1
[xsw, xmean, xc, ifail] = g02bu( ...
x1);
case 2
[ysw, ymean, yc, ifail] = g02bu( ...
x2, 'wt', wt);
case 3
[ysw, ymean, yc, ifail] = g02bu( ...
x3);
end
if b ~= 1
[xsw, xmean, xc, ifail] = g02bz( ...
xsw, xmean, xc, ysw, ymean, yc);
end
end
fprintf('\nMeans\n');
disp(xmean');
mtitle = 'Sums of squares and cross-products';
uplo = 'Upper';
diag = 'Non-unit';
m = int64(5);
[ifail] = x04cc( ...
uplo, diag, m, xc, mtitle);
if xsw > 1
fprintf('\n');
mtitle = 'Covariance Matrix';
[ifail] = x04cc( ...
uplo, diag, m, xc/(xsw-1), mtitle);
end
g02bz example results
Means
0.4369 0.4929 -1.3387 -0.5684 0.0987
Sums of squares and cross-products
1 2 3 4 5
1 304.5052 -123.7700 -27.1830 -60.7092 83.4830
2 298.9148 -17.3196 -2.1710 5.2072
3 332.1639 -3.9445 -96.9299
4 264.7684 79.6211
5 225.5948
Covariance Matrix
1 2 3 4 5
1 17.1746 -6.9808 -1.5332 -3.4241 4.7086
2 16.8593 -0.9769 -0.1224 0.2937
3 18.7346 -0.2225 -5.4670
4 14.9334 4.4908
5 12.7239
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015