# NAG FL Interfaceg01abf (summary_​2var)

## ▸▿ Contents

Settings help

FL Name Style:

FL Specification Language:

## 1Purpose

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.

## 2Specification

Fortran Interface
 Subroutine g01abf ( n, x1, x2, iwt, wt, res,
 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)
#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.

## 3Description

The data consist of two samples of $n$ observations, denoted by ${x}_{i}$, and ${y}_{i}$, for $i=1,2,\dots ,n$, with corresponding weights ${w}_{i}$, for $\mathit{i}=1,2,\dots ,n$.
If no specific weighting is given, then each ${w}_{i}$ is set to $1.0$ in g01abf.
The quantities calculated are:
1. (a)The sum of weights,
 $W=∑i=1nwi.$
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 ${w}_{i}>0$, i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if $m\ge 2$. All other items are computed if $m\ge 1$.

None.

## 5Arguments

1: $\mathbf{n}$Integer Input
On entry: $n$, the number of pairs of observations.
Constraint: ${\mathbf{n}}\ge 1$.
2: $\mathbf{x1}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the observations from the first sample, ${x}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
3: $\mathbf{x2}\left({\mathbf{n}}\right)$Real (Kind=nag_wp) array Input
On entry: the observations from the second sample, ${y}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
4: $\mathbf{iwt}$Integer Input/Output
On entry: indicates whether user-supplied weights are provided by you:
${\mathbf{iwt}}=1$
• Indicates that user-supplied weights are given in the array wt.
${\mathbf{iwt}}\ne 0$
• 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: $\mathbf{wt}\left({\mathbf{n}}\right)$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, ${w}_{\mathit{i}}$, for $\mathit{i}=1,2,\dots ,n$.
Constraint: if ${\mathbf{iwt}}=1$, ${\mathbf{wt}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$.
On exit: if ${\mathbf{iwt}}=1$, the elements of wt are unchanged, otherwise each element of wt will be assigned the value $1.0$.
6: $\mathbf{res}\left(13\right)$Real (Kind=nag_wp) array Output
On exit: the elements of res contain the following results:
 ${\mathbf{res}}\left(1\right)$ mean of the first sample, $\overline{x}$; ${\mathbf{res}}\left(2\right)$ mean of the second sample, $\overline{y}$; ${\mathbf{res}}\left(3\right)$ standard deviation of the first sample, ${s}_{1}$; ${\mathbf{res}}\left(4\right)$ standard deviation of the second sample, ${s}_{2}$; ${\mathbf{res}}\left(5\right)$ corrected sum of squares of the first sample, ${c}_{11}$; ${\mathbf{res}}\left(6\right)$ corrected sum of products of the two samples, ${c}_{12}$; ${\mathbf{res}}\left(7\right)$ corrected sum of squares of the second sample, ${c}_{22}$; ${\mathbf{res}}\left(8\right)$ product-moment correlation coefficient, $R$; ${\mathbf{res}}\left(9\right)$ minimum of the first sample; ${\mathbf{res}}\left(10\right)$ maximum of the first sample; ${\mathbf{res}}\left(11\right)$ minimum of the second sample; ${\mathbf{res}}\left(12\right)$ maximum of the second sample; ${\mathbf{res}}\left(13\right)$ sum of weights, $\sum _{i=1}^{n}{w}_{i}$ ($={\mathbf{n}}$, if ${\mathbf{iwt}}=0$, on entry).
7: $\mathbf{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 $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{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:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 1$.
${\mathbf{ifail}}=2$
The number of valid cases, $m$, is $1$. In this case standard deviation and product-moment correlation coefficient cannot be calculated.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{wt}}\left(⟨\mathit{\text{value}}⟩\right)=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{wt}}\left(\mathit{i}\right)\ge 0.0$, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$
The number of valid cases, $m$, is $0$.
${\mathbf{ifail}}=-99$
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
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.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.

## 7Accuracy

The method used is believed to be stable.

## 8Parallelism and Performance

g01abf is not threaded in any implementation.

The time taken by g01abf increases linearly with $n$.

## 10Example

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.1Program Text

Program Text (g01abfe.f90)

### 10.2Program Data

Program Data (g01abfe.d)

### 10.3Program Results

Program Results (g01abfe.r)