NAG FL Interface
g01abf (summary_​2var)

Settings help

FL Name Style:

FL Specification Language:

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

Fortran Interface
Subroutine g01abf ( n, x1, x2, iwt, wt, res, ifail)
Integer, Intent (In) :: n
Integer, Intent (Inout) :: iwt, ifail
Real (Kind=nag_wp), Intent (In) :: x1(n), x2(n)
Real (Kind=nag_wp), Intent (Inout) :: wt(n)
Real (Kind=nag_wp), Intent (Out) :: res(13)
C Header Interface
#include <nag.h>
void  g01abf_ (const Integer *n, const double x1[], const double x2[], Integer *iwt, double wt[], double res[], Integer *ifail)
The routine may be called by the names g01abf or nagf_stat_summary_2var.

3 Description

The data consist of two samples of n observations, denoted by xi, and yi, for i=1,2,,n, with corresponding weights wi, for i=1,2,,n.
If no specific weighting is given, then each wi is set to 1.0 in g01abf.
The quantities calculated are:
  1. (a)The sum of weights,
  2. (b)The means,
    x¯=i= 1nwixiW,   y¯=i= 1nwiyiW.  
  3. (c)The corrected sums of squares and products
    c11=i=1n wi (xi-x¯) 2 c21=c12=i=1n wi (xi-x¯) (yi-y¯) c22=i=1n wi (yi-y¯) 2 .  
  4. (d)The standard deviations
    sj= cjj d ,   where   j= 1,2   and   d=W- i= 1 n wi2 W .  
  5. (e)The product-moment correlation coefficient
    R= c12 c11 c22 .  
  6. (f)The minimum and maximum elements in each of the two samples.
  7. (g)The number of pairs of observations, m, for which wi>0, i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if m2. All other items are computed if m1.

4 References


5 Arguments

1: n Integer Input
On entry: n, the number of pairs of observations.
Constraint: n1.
2: x1(n) Real (Kind=nag_wp) array Input
On entry: the observations from the first sample, xi, for i=1,2,,n.
3: x2(n) Real (Kind=nag_wp) array Input
On entry: the observations from the second sample, yi, for i=1,2,,n.
4: iwt Integer Input/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 1.0 to each element of the weight array, wt.
On exit: is used to indicate the number of valid observations, m; see Section 3(g), above.
5: wt(n) Real (Kind=nag_wp) array Input/Output
On entry: if weights are being supplied then the elements of wt must contain the weights associated with the observations, wi, for i=1,2,,n.
Constraint: if iwt=1, wt(i)0.0, for i=1,2,,n.
On exit: if iwt=1, the elements of wt are unchanged, otherwise each element of wt will be assigned the value 1.0.
6: res(13) Real (Kind=nag_wp) array Output
On exit: the elements of res contain the following results:
res(1) mean of the first sample, x¯;
res(2) mean of the second sample, y¯;
res(3) standard deviation of the first sample, s1;
res(4) standard deviation of the second sample, s2;
res(5) corrected sum of squares of the first sample, c11;
res(6) corrected sum of products of the two samples, c12;
res(7) corrected sum of squares of the second sample, c22;
res(8) product-moment correlation coefficient, R;
res(9) minimum of the first sample;
res(10) maximum of the first sample;
res(11) minimum of the second sample;
res(12) maximum of the second sample;
res(13) sum of weights, i=1nwi (=n, if iwt=0, on entry).
7: ifail Integer Input/Output
On entry: ifail must be set to 0, −1 or 1 to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of 0 causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of −1 means that an error message is printed while a value of 1 means that it is not.
If halting is not appropriate, the value −1 or 1 is recommended. If message printing is undesirable, then the value 1 is recommended. Otherwise, the value 0 is recommended. When the value -1 or 1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6 Error Indicators and Warnings

If on entry ifail=0 or −1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, n=value.
Constraint: n1.
The number of valid cases, m, is 1. In this case standard deviation and product-moment correlation coefficient cannot be calculated.
On entry, wt(value)=value.
Constraint: wt(i)0.0, for i=1,2,,n
The number of valid cases, m, is 0.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

7 Accuracy

The method used is believed to be stable.

8 Parallelism and Performance

g01abf is not threaded in any implementation.

9 Further Comments

The time taken by g01abf increases linearly with n.

10 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 29 (unweighted) pairs of observations.

10.1 Program Text

Program Text (g01abfe.f90)

10.2 Program Data

Program Data (g01abfe.d)

10.3 Program Results

Program Results (g01abfe.r)