Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# 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

[res, ifail] = g01ab(x1, x2, 'n', n, 'wt', wt)
[res, ifail] = nag_stat_summary_2var(x1, x2, 'n', n, 'wt', wt)
Note: the interface to this routine has changed since earlier releases of the toolbox:
Mark 23: wt no longer an output parameter
.

## Description

The data consist of two samples of n$n$ observations, denoted by xi${x}_{i}$, and yi${y}_{i}$, for i = 1,2,,n$i=1,2,\dots ,n$, with corresponding weights wi${w}_{i}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
If no specific weighting is given, then each wi${w}_{i}$ is set to 1.0$1.0$ in nag_stat_summary_2var (g01ab).
The quantities calculated are:
(a) The sum of weights,
 n W = ∑ wi. i = 1
$W=∑i=1nwi.$
(b) The means,
 x = ( ∑ i = 1nwixi)/W,   y = ( ∑ i = 1nwiyi)/W. $x-=∑i= 1nwixiW, y-=∑i= 1nwiyiW.$
(c) The corrected sums of squares and products
 n c11 = ∑ wi(xi − x)2 i = 1
 n c21 = c12 = ∑ wi(xi − x)(yi − y) i = 1
 n c22 = ∑ wi(yi − y)2. i = 1
$c11=∑i=1n wi ( xi-x- ) 2 c21=c12=∑i=1n wi (xi-x-) (yi-y-) c22=∑i=1n wi ( yi-y- ) 2 .$
(d) The standard deviations
 sj = sqrt( (cjj)/d ) ,   where   j = 1,2   and   d = W − ( ∑ i = 1n wi2 )/W . $sj= cjj d , where j= 1,2 and d=W- ∑ i= 1 n wi2 W .$
(e) The product-moment correlation coefficient
 R = (c12)/( sqrt( c11 c22 ) ) . $R= c12 c11 c22 .$
(f) The minimum and maximum elements in each of the two samples.
(g) The number of pairs of observations, m$m$, for which wi > 0${w}_{i}>0$, i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if m2$m\ge 2$. All other items are computed if m1$m\ge 1$.

None.

## Parameters

### Compulsory Input Parameters

1:     x1(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The observations from the first sample, xi${x}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
2:     x2(n) – double array
n, the dimension of the array, must satisfy the constraint n1${\mathbf{n}}\ge 1$.
The observations from the second sample, yi${y}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.

### Optional Input Parameters

1:     n – int64int32nag_int scalar
Default: The dimension of the arrays x1, x2, wt. (An error is raised if these dimensions are not equal.)
n$n$, the number of pairs of observations.
Constraint: n1${\mathbf{n}}\ge 1$.
2:     wt(n) – double array
If weights are being supplied then the elements of wt must contain the weights associated with the observations, wi${w}_{\mathit{i}}$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$.
Constraint: if iwt = 1$\mathbf{iwt}=1$, wt(i)0.0${\mathbf{wt}}\left(\mathit{i}\right)\ge 0.0$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,{\mathbf{n}}$.

None.

### Output Parameters

1:     res(13$13$) – double array
The elements of res contain the following results:
 res(1)${\mathbf{res}}\left(1\right)$ mean of the first sample, x$\stackrel{-}{x}$; res(2)${\mathbf{res}}\left(2\right)$ mean of the second sample, y$\stackrel{-}{y}$; res(3)${\mathbf{res}}\left(3\right)$ standard deviation of the first sample, s1${s}_{1}$; res(4)${\mathbf{res}}\left(4\right)$ standard deviation of the second sample, s2${s}_{2}$; res(5)${\mathbf{res}}\left(5\right)$ corrected sum of squares of the first sample, c11${c}_{11}$; res(6)${\mathbf{res}}\left(6\right)$ corrected sum of products of the two samples, c12${c}_{12}$; res(7)${\mathbf{res}}\left(7\right)$ corrected sum of squares of the second sample, c22${c}_{22}$; res(8)${\mathbf{res}}\left(8\right)$ product-moment correlation coefficient, R$R$; res(9)${\mathbf{res}}\left(9\right)$ minimum of the first sample; res(10)${\mathbf{res}}\left(10\right)$ maximum of the first sample; res(11)${\mathbf{res}}\left(11\right)$ minimum of the second sample; res(12)${\mathbf{res}}\left(12\right)$ maximum of the second sample; res(13)${\mathbf{res}}\left(13\right)$ sum of weights, ∑ i = 1nwi$\sum _{i=1}^{n}{w}_{i}$ ( = n$={\mathbf{n}}$, if wt is null on entry).
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ 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.

ifail = 1${\mathbf{ifail}}=1$
 On entry, n < 1${\mathbf{n}}<1$.
W ifail = 2${\mathbf{ifail}}=2$
The number of valid cases, m$m$, is 1$1$, hence the standard deviation, 3(d), and the product-moment correlation coefficient, 3(e), cannot be calculated.
ifail = 3${\mathbf{ifail}}=3$
The number of valid cases, m$m$, is 0$0$, or at least one of the weights is negative.

## Accuracy

The method used is believed to be stable.

The time taken by nag_stat_summary_2var (g01ab) increases linearly with n$n$.

## Example

```function nag_stat_summary_2var_example
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];
[res, ifail] = nag_stat_summary_2var(x1, x2)
```
```

res =

1.0e+07 *

0.0001
0.0000
0.0001
0.0000
1.6396
0.3483
0.1132
0.0000
0.0000
0.0003
0.0000
0.0001
0.0000

ifail =

0

```
```function g01ab_example
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];
[res, ifail] = g01ab(x1, x2)
```
```

res =

1.0e+07 *

0.0001
0.0000
0.0001
0.0000
1.6396
0.3483
0.1132
0.0000
0.0000
0.0003
0.0000
0.0001
0.0000

ifail =

0

```