hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
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 nn observations, denoted by xixi, and yiyi, for i = 1,2,,ni=1,2,,n, with corresponding weights wiwi, for i = 1,2,,ni=1,2,,n.
If no specific weighting is given, then each wiwi is set to 1.01.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(xix)2
i = 1
n
c21 = c12 = wi(xix)(yiy)
i = 1
n
c22 = wi(yiy)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, mm, for which wi > 0wi>0, i.e., the number of valid observations. The quantities in (d) and (e) above will only be computed if m2m2. All other items are computed if m1m1.

References

None.

Parameters

Compulsory Input Parameters

1:     x1(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The observations from the first sample, xixi, for i = 1,2,,ni=1,2,,n.
2:     x2(n) – double array
n, the dimension of the array, must satisfy the constraint n1n1.
The observations from the second sample, yiyi, for i = 1,2,,ni=1,2,,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.)
nn, the number of pairs of observations.
Constraint: n1n1.
2:     wt(n) – double array
If weights are being supplied then the elements of wt must contain the weights associated with the observations, wiwi, for i = 1,2,,ni=1,2,,n.
Constraint: if iwt = 1iwt=1, wt(i)0.0wti0.0, for i = 1,2,,ni=1,2,,n.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     res(1313) – double array
The elements of res contain the following results:
res(1)res1 mean of the first sample, xx-;
res(2)res2 mean of the second sample, yy-;
res(3)res3 standard deviation of the first sample, s1s1;
res(4)res4 standard deviation of the second sample, s2s2;
res(5)res5 corrected sum of squares of the first sample, c11c11;
res(6)res6 corrected sum of products of the two samples, c12c12;
res(7)res7 corrected sum of squares of the second sample, c22c22;
res(8)res8 product-moment correlation coefficient, RR;
res(9)res9 minimum of the first sample;
res(10)res10 maximum of the first sample;
res(11)res11 minimum of the second sample;
res(12)res12 maximum of the second sample;
res(13)res13 sum of weights, i = 1nwii=1nwi ( = n=n, if wt is null on entry).
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=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 = 1ifail=1
On entry,n < 1n<1.
W ifail = 2ifail=2
The number of valid cases, mm, is 11, hence the standard deviation, 3(d), and the product-moment correlation coefficient, 3(e), cannot be calculated.
  ifail = 3ifail=3
The number of valid cases, mm, is 00, or at least one of the weights is negative.

Accuracy

The method used is believed to be stable.

Further Comments

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

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



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013