PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_stat_summary_2var (g01ab)
Purpose
nag_stat_summary_2var (g01ab) computes the means, standard deviations, corrected sums of squares and products, maximum and minimum values, and the product-moment correlation coefficient for two variables. Unequal weighting may be given.
Syntax
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 23: |
wt is no longer an output parameter |
Description
The data consist of two samples of observations, denoted by , and , for , with corresponding weights , for .
If no specific weighting is given, then each is set to in nag_stat_summary_2var (g01ab).
The quantities calculated are:
(a) |
The sum of weights,
|
(b) |
The means,
|
(c) |
The corrected sums of squares and products
|
(d) |
The standard deviations
|
(e) |
The product-moment correlation coefficient
|
(f) |
The minimum and maximum elements in each of the two samples. |
(g) |
The number of pairs of observations, , for which , i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if . All other items are computed if . |
References
None.
Parameters
Compulsory Input Parameters
- 1:
– double array
-
The observations from the first sample,
, for .
- 2:
– double array
-
The observations from the second sample,
, for .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the dimension of the arrays
x1,
x2,
wt. (An error is raised if these dimensions are not equal.)
, the number of pairs of observations.
Constraint:
.
- 2:
– double array
-
If weights are being supplied then the elements of
wt must contain the weights associated with the observations,
, for
.
Constraint:
if , , for .
Output Parameters
- 1:
– double array
-
The elements of
res contain the following results:
| mean of the first sample, ; |
| mean of the second sample, ; |
| standard deviation of the first sample, ; |
| standard deviation of the second sample, ; |
| corrected sum of squares of the first sample, ; |
| corrected sum of products of the two samples, ; |
| corrected sum of squares of the second sample, ; |
| product-moment correlation coefficient, ; |
| minimum of the first sample; |
| maximum of the first sample; |
| minimum of the second sample; |
| maximum of the second sample; |
| sum of weights, (, if
wt is null
on entry). |
- 2:
– 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:
Cases prefixed with W are classified as warnings and
do not generate an error of type NAG:error_n. See nag_issue_warnings.
-
-
- W
-
The number of valid cases, , is , hence the standard deviation, 3(d), and the product-moment correlation coefficient, 3(e), cannot be calculated.
-
-
The number of valid cases, , is , or at least one of the weights is negative.
-
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
The method used is believed to be stable.
Further Comments
The time taken by nag_stat_summary_2var (g01ab) increases linearly with .
Example
In the program below, NPROB determines the number of datasets to be analysed. For each analysis, a set of observations and, optionally, weights, is read and printed. After calling nag_stat_summary_2var (g01ab), all the calculated quantities are printed. In the example, there is one set of data, with (unweighted) pairs of observations.
Open in the MATLAB editor:
g01ab_example
function g01ab_example
fprintf('g01ab example results\n\n');
x1 = [350 550 380 510 1270 300 2630 810 ...
140 450 2280 250 540 720 90 480 ...
180 3160 220 860 300 1460 400 620 ...
120 780 230 1070 160];
x2 = [ 47 95 211 122 530 38 278 309 ...
75 43 407 142 89 159 35 103 ...
78 969 120 333 73 147 30 100 ...
55 145 101 468 86];
n = size(x1,2);
[res, ifail] = g01ab(x1, x2);
fprintf('Number of cases %7d\n',n);
fprintf('Data as input -\n');
v1 = 'Var 1';
v2 = 'Var 2';
fprintf('%12s%12s%12s%12s%12s%12s\n', v1, v2, v1, v2, v1, v2);
fprintf('%12.1f%12.1f%12.1f%12.1f%12.1f%12.1f\n',[x1; x2])
fprintf('\n\n');
fprintf('No. of valid cases %7d\n\n',n);
fprintf('%30s%30s\n', 'Variable 1', 'Variable 2');
fprintf('Mean %11.1f%30.1f\n',res(1:2));
fprintf('Minimum %11.1f%30.1f\n',res(9:2:11));
fprintf('Maximum %11.1f%30.1f\n',res(10:2:12));
fprintf('Standard deviation %11.1f%30.1f\n',res(3:4));
fprintf('Sum of squares %11.1f%30.1f\n',res(5:2:7));
fprintf('Sum of weights %26.4f\n',res(13));
fprintf('Sum of products %26.4f\n',res(6));
fprintf('Correlation %26.4f\n',res(8));
g01ab example results
Number of cases 29
Data as input -
Var 1 Var 2 Var 1 Var 2 Var 1 Var 2
350.0 47.0 550.0 95.0 380.0 211.0
510.0 122.0 1270.0 530.0 300.0 38.0
2630.0 278.0 810.0 309.0 140.0 75.0
450.0 43.0 2280.0 407.0 250.0 142.0
540.0 89.0 720.0 159.0 90.0 35.0
480.0 103.0 180.0 78.0 3160.0 969.0
220.0 120.0 860.0 333.0 300.0 73.0
1460.0 147.0 400.0 30.0 620.0 100.0
120.0 55.0 780.0 145.0 230.0 101.0
1070.0 468.0 160.0 86.0
No. of valid cases 29
Variable 1 Variable 2
Mean 734.8 185.8
Minimum 90.0 30.0
Maximum 3160.0 969.0
Standard deviation 765.2 201.1
Sum of squares 16395924.1 1131860.8
Sum of weights 29.0000
Sum of products 3483048.9655
Correlation 0.8085
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015