NAG Library Routine Document
G01ABF
1 Purpose
G01ABF 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.
2 Specification
INTEGER |
N, IWT, IFAIL |
REAL (KIND=nag_wp) |
X1(N), X2(N), WT(N), RES(13) |
|
3 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 G01ABF.
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 . |
4 References
None.
5 Parameters
- 1: N – INTEGERInput
On entry: , the number of pairs of observations.
Constraint:
.
- 2: X1(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations from the first sample,
, for .
- 3: X2(N) – REAL (KIND=nag_wp) arrayInput
On entry: the observations from the second sample,
, for .
- 4: IWT – INTEGERInput/Output
On entry: indicates whether user-supplied weights are provided by you:
- Indicates that user-supplied weights are given in the array WT.
- Indicates that user-supplied weights are not given. In this case the routine assigns the value to each element of the weight array, WT.
On exit: is used to indicate the number of valid observations,
; see
Section 3(g), above.
- 5: WT(N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if weights are being supplied then the elements of
WT must contain the weights associated with the observations,
, for
.
Constraint:
if , , for .
On exit: if
, the elements of
WT are unchanged, otherwise each element of
WT will be assigned the value
.
- 6: RES() – REAL (KIND=nag_wp) arrayOutput
On exit: 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
,
on entry). |
- 7: IFAIL – INTEGERInput/Output
-
On entry:
IFAIL must be set to
,
. If you are unfamiliar with this parameter you should refer to
Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
-
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.
7 Accuracy
The method used is believed to be stable.
The time taken by G01ABF increases linearly with .
9 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 G01ABF, all the calculated quantities are printed. In the example, there is one set of data, with (unweighted) pairs of observations.
9.1 Program Text
Program Text (g01abfe.f90)
9.2 Program Data
Program Data (g01abfe.d)
9.3 Program Results
Program Results (g01abfe.r)